Robotframework acquiring mobile terminal toast issues

background:

In doing automated testing of mobile terminal, often you encounter a problem is to get the toast question, if you need to solve this problem needs to be reprocessed, could not follow the normal logic, use robotframework own keywords get, need to reconsider the new processing acquisition mode

A configuration environment

If the environment configuration OK skip to step 6 mounted uiautomator2

1. Download the latest version Appium

Address: https://github.com/appium/appium-desktop/releases

 

2. Download Python, and install

3. Download Pycharm

4. Download Android SDK

5. Installation uiautomator2

- NPM installation image, address: https: //npm.taobao.org/

- execute the command: npm install -g cnpm --registry = https: //registry.npm.taobao.org

- Install uiautomator2 profile execute the command: cnpm install appium-uiautomator2-driver

After setting up the environment is good, be acquired toast

1 into the appium installation root directory, D: \ Python27 \ Lib \ Site-Packages Standard Package \ robotframework_appiumlibrary-1.5-py2.7 .egg \ AppiumLibrary \ keywords, find _element.py modify file
 2  , add this statement
 3  DEF toast_open_application ( Self, automationName, PlatformName, platformVersion, deviceName, uiid, appPackage, appActivity, unicodeKeyboard, resetKeyboard, NoReset):
 . 4  
. 5          desired_caps = {}
 . 6          desired_caps [ ' automationName ' ] = automationName
 . 7          desired_caps [ " PlatformName " ] = PlatformName
 . 8          desired_caps [ "platformVersion"] = platformVersion
 9         desired_caps["deviceName"] = deviceName
10         desired_caps["uiid"] = uiid
11         desired_caps["appPackage"] = appPackage
12         desired_caps["appActivity"] = appActivity
13 
14         desired_caps["unicodeKeyboard"] = unicodeKeyboard
15         desired_caps["resetKeyboard"] = resetKeyboard
16         desired_caps["noReset"] = noReset
17 
18         driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
19         return driver
20 
21     def new_clear(self,driver,path):
22         WebDriverWait(driver,20).until(EC.visibility_of_element_located((MobileBy.ID,'com.X.XX.debug:id/account')))
23         driver.find_element_by_id(path).clear()
24 
25     def  new_input(self,driver,path,data):
26         driver.find_element_by_id(path).send_keys(data)
27 
28     def new_click(self,driver,path,message):
29         driver.find_element_by_id(path).click()
30         # toast_loc = '//*[contains(@text,"请输入正确规则的密码")]'
31         toast_loc =".//*[contains(@text,'%s')]" %message
32         # print((MobileBy.XPATH,toast_loc))
33         try:
34             WebDriverWait(driver,5,0.01) .until (EC.presence_of_all_elements_located ((MobileBy.XPATH, toast_loc)))
 35              Print (driver.find_element_by_xpath (toast_loc) .text)
 36          the except :
 37 [              Print ( ' no information acquired toast ' )

 

robotframework keyword acquisition of the package will be

1 登录_密码错误(toast)
2     Comment    Login Toast    请输入正确规则的密码
3     ${driver}    Toast Open Application    UiAutomator2    Android    6.0    Lenovo TB3-X70N    FACU8TP7UCAAMNUO
4     ...    com.X.cXd.debug    com.XX.XXactivity.SplashActivity    True    True    True
5     New Clear    ${driver}    com.XX.XX.debug:id/account
6     New Input    ${driver}    com.XX.cXXd.debug:id/account    123456
7     New Clear    ${driver}    com.XX.XX.debug:id/pwd
8     New Input    ${driver}    com.XX.XX.debug:id/pwd    123456ab
9     New Click    ${driver}    com.XX.XX.debug:id/login    请输入正确规则的密码

 







结果:

 

 

Guess you like

Origin www.cnblogs.com/xiaoyaowuming/p/11315258.html