appium toast pop-up box and the application switching processing

First, application switching

  The method is simple application switching, direct call driver.start_activity () method, passing app_package and app_activity parameters, the following sample code:

from appium Import the webdriver 

desired_caps = {} 

# configuration internet information 
desired_caps [ ' PlatformName ' ] = ' the Android ' 
desired_caps [ ' platformVersion ' ] = ' 8.0 ' 
desired_caps [ ' deviceName ' ] = ' the Android Emulator ' 
desired_caps [ ' NoReset ' ] = True 

# get the package name and class name to start the application 
desired_caps [ ' appPackage '] = 'com.tencent.mm'
desired_caps['appActivity'] = 'com.tencent.mm.ui.LauncherUI'

# 与appium server建立连接
driver = webdriver.Remote(command_executor='http://127.0.0.1:4723/wd/hub',
                          desired_capabilities=desired_caps)

driver.start_activity(app_package='com.autonavi.minimap',
                      app_activity='com.autonavi.map.activity.SplashActivity')

  The results demonstrate code execution:

Two, toast pop-up box processing

1.toast Profile

  toast android is a mechanism used to display the information, and Dialog box is not the same as not focus toast, toast and time display is limited, over a very short period of time will automatically disappear, and can not be clicked.

  In appium, if you want to toast the positioning information, by appium own inspector or SDK tools found inside uiautomatorviewer is positioned less, there is no corresponding property information, but the version in appium v1.6.3 and after obtaining the support of toast .

  

2.toast get

Note toast to obtain information:

  • UIAutomator2 only supports android version 5.0 and above
  • appium server version 1.6.3 and above
  • Jdk1.8 64-position and to be installed above, and to configure the path and JAVA_HOME environment variables
  • Specify start parameters: desired_caps [ 'automationName'] = 'UiAutomator2'
= desired_caps {}
 # Set UiAutomator2 toast support information obtaining 
desired_caps [ ' automationName ' ] = ' UiAutomator2 '

xpath expression:

xpath = '// * [contains (@text, "text")]'

wait:

Use presence_of_element_located, but can not be used visibility_of_element_located, where it is visible toast processing does not support, will not be executed directly thrown Command Error

# 获取对应的toast信息
xpath_locator = (MobileBy.XPATH, '//*[contains(@text, "{}")]'.format('手机号码或密码不能为空'))

try:
    WebDriverWait(driver, 10, 0.01).until(EC.presence_of_element_located(xpath_locator))  # 因为toast信息消失的很快,所以频率需要指定,这里设定为0.01
    print("已获取到toast信息:{}".format(driver.find_element(*xpath_locator).text))
except:
    print("未获取到toast信息!!!")

Guess you like

Origin www.cnblogs.com/xiaogongjin/p/11782675.html