appium+python 获取toast弹窗信息

appium+python 获取toast弹窗信息_第1张图片
以微信登录界面的toast弹窗为例:

我的appium版本是1.17.1,服务器运行时日志有这样的打印信息

appium+python 获取toast弹窗信息_第2张图片
所以我的desired_caps如下(如果是之前的版本,需要安装uiautomator2,并且在初始化时指定automationName为uiautomator2):

desired_caps_a = {'platformName': "Android",
                      'platFormVersion': "10",
                      'deviceName': "dd",
                      'udid': "648d4f29",
                      'automationName': "UiAutomator2",
                      'noReset': False,
                      'unicodeKeyboard': True,
                      'resetKeyboard': True,
                      'appPackage': "com.tencent.mm",
                      'appActivity': "com.tencent.mm.ui.LauncherUI",
                      'autoGrantPermissions': True,
                      'chromedriverExecutable': r"C:\Users\v_yddchen\Desktop\chromedriver_win32 77.0\chromedriver.exe",
                      'chromeOptions': {'androidProcess': "com.tencent.mm:toolsmp"}  # webview的进程名字,不然会报错
    }

填写登录信息,获取toast(有时来不及获取登录界面的toast信息,会拿到登录成功后,加载数据的toast):

device_a = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps_a)
    my_logging = output_log(logging.DEBUG)
# toast弹窗处理
    device_a.find_element_by_android_uiautomator('new UiSelector().text("登录")').click()
    time.sleep(1)
    device_a.find_element_by_android_uiautomator('new UiSelector().textContains("用微信号")').click()
    time.sleep(1)
    username_input = device_a.find_element_by_android_uiautomator('new UiSelector().textContains("请填写微信号")')
    username_input.clear()
    username_input.send_keys('xxx')
    pwd_input = device_a.find_element_by_android_uiautomator('new UiSelector().textContains("请填写密码")')
    pwd_input.clear()
    pwd_input.send_keys('xxx')
    device_a.find_element_by_android_uiautomator('new UiSelector().text("登录")').click()
    toast_el = WebDriverWait(device_a, 5, 0.00001).\
        until(lambda x: x.find_element_by_xpath("//*[contains(@text,'正在')]"))
    # toast_el = WebDriverWait(device_a, 5, 0.000001).\
    #     until(lambda x: x.find_element_by_xpath('//*[@class="android.widget.Toast"]'))
    print(toast_el.text)
    device_a.quit()

当密码填写信息错误时,不管改定时器的间隔为多小,都找不到toast,比较奇怪。如果点击【登录】–登录完成,跳转,这个过程很短,也有可能获取不到toast。

看完点赞 ~养成好习惯,以上内容希望对你有帮助,如果对软件测试、接口测试、自动化测试、面试经验交流感兴趣可以加入我们。642830685,免费领取最新软件测试大厂面试资料和Python自动化、接口、框架搭建学习资料!技术大牛解惑答疑,同行一起交流。

你可能感兴趣的:(软件测试,自动化测试,appium,软件测试,自动化测试,python,appium)