Appium appium 找不到 toast 提示信息

wfp · 2016年09月25日 · 最后由 孟威 回复于 2017年07月11日 · 1864 次阅读

写了个 python 实现的 appium 脚本,抓取 toast 信息的,但是总是提示错误,各位大侠帮忙看看

脚本如下:


class BACK_UP_APP_TestCase(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        desired_caps = {}
        desired_caps['automationName'] = 'Selendroid'
        desired_caps['device'] = 'android'
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '4.4.2'
        desired_caps['deviceName'] = '192.168.128.117'+':5555'
        desired_caps['app'] = 'e:\\SC\\ConferenceControl.apk'
        desired_caps['appPackage'] = 'com.grandstream.confctrol'
        desired_caps['appActivity'] = '.activity.ConnectActivity'
       self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
        self.extend = Appium_Extend(self.driver)
        self.driver.implicitly_wait(20)    #设置全局最大等待时间

def test_c0001(self): 
  self.driver.find_element_by_link_text("Internet").click()
  self.driver.find_element_by_link_text("OK").click()
  a = find_toast(u"Password can not be empty", 20, 0.5, self.driver)

调用的查找 toast 函数

def find_toast(message, timeout, poll_frequency, driver):
    element = WebDriverWait(driver, timeout, poll_frequency).until(expected_conditions.presence_of_element_located((By.PARTIAL_LINK_TEXT, message)))

错误信息:

Error
Traceback (most recent call last):
  File "D:\python_test\SIP\TestSuit_Backup.py", line 278, in test_c0005_cancel_backup
    a = find_toast(u"Password can not be empty", 20, 0.5, self.driver)
  File "D:\python_test\SIP\TestSuit_Backup.py", line 24, in find_toast
    element = WebDriverWait(driver, timeout, poll_frequency).until(expected_conditions.presence_of_element_located((By.PARTIAL_LINK_TEXT, message)))
  File "C:\Python27\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
TimeoutException: Message: 
共收到 6 条回复 时间 点赞

desired_caps['automationName'] = 'Selendroid'这个和你的 desired_caps['platformVersion'] = '4.4.2'不搭配,4.1 以上用的是 Uiautomator.
4.1 以上获取 toast 用 xposed,论坛有帖子的,亲测成功

wfp #2 · 2016年09月25日 Author

#1 楼 @zuiniao123 也就是说,Selendroid 只试用于 4.1 或 4.1 以下的?我查了很多资料说 uiautomator 是 get 不了 toast,所以一直在用 appium 的 Selendroid

wfp #3 · 2016年09月25日 Author

#1 楼 @zuiniao123 方便告知 xposed 的使用方法吗,或者学习的参考网站

https://testerhome.com/topics/3750 帖子里说的是打印 log,不过我是显示到 xposed 模块上,当 app 测试中出现 toast 的时候跳到该模块上识别读取

wfp #5 · 2016年09月25日 Author

#4 楼 @zuiniao123 嗯,谢谢

huiyu Appium 1.6.3 python 3,怎么获取 toast 消息? 中提及了此贴 04月21日 11:55

解决了么?同样掉进该坑

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册