zoukankan      html  css  js  c++  java
  • appium自动化测试中获取toast消息的解决方法【转】

    http://blog.csdn.net/hqzxsc2006/article/details/50036911

    待实践。。

    解决方法:appium下切换selendroid模式去获取Android的toast提示。

    desired_caps配置:

    [python] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. desired_caps_android={  
    2.               'platformVersion':'4.4',  
    3.               'deviceName':'',  
    4.               'udid':'34d7d220',  
    5.               'platformName':'android',  
    6.               'automationName':'Selendroid',  
    7.               'app':PATH,  
    8.               'appPackage':'com.xxx',  
    9.               'appActivity':'.com.xxx',  
    10.               'unicodeKeyboard':True,  
    11.               'resetKeyboard':True  
    12.               }  

    当切换到selendroid模式运行脚本时,服务端报错

    经过搜索查询发现由于Selendroid要求被测app的manifest必须有internet权限,所以在运行前appium会去check一下这个app有没有internet权限,但问题来了,如果我不设置app参数的话,这里获得的就是空的,所以用aapt自然就去dump了一个空的安装包。通过指定app路径参数,每次运行都重新安装包就可。

    如果还报错,应用启动不了,大概提示权限问题等,应该要更新Android SDK,比如手机系统是4.3,需要更新对应版本的platforms和build_tools,下载下来拷贝android-18到platforms目录下。build_tools也是一样。

    在selendroid模式下,有些api和appium不同,appium下的tap、swipe、get_window_size()等方法不能用,需要使用其他替代,如'adb shell input swipe x1 y1 x2 y2'、‘adb shell input tap x y’等。

    封装toast方法实例:

    [python] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. from appium import webdriver  
    2. from selenium.webdriver.common.by import By  
    3. from selenium.webdriver.support.ui import WebDriverWait  
    4. from selenium.webdriver.support import expected_conditions as EC  
    [python] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. def find_toast(self,message):  
    2.         '''''判断toast信息'''  
    3.         try:  
    4.             element = WebDriverWait(self.driver,10).until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT,message)))  
    5.             return True  
    6.         except:  
    7.             return False  

    参考官方文档:https://github.com/appium/appium/blob/master/docs/cn/writing-running-appium/running-tests.cn.md

  • 相关阅读:
    题解-CmdOI2019 口头禅
    题解-NOI2003 智破连环阵
    题解-CF1282E The Cake Is a Lie
    CF1288F Red-Blue Graph
    题解-洛谷P4229 某位歌姬的故事
    莫比乌斯反演
    [HNOI2008]越狱(bzoj1008)(组合数学+正难则反)
    [FJOI2007]轮状病毒(bzoj1002)(递推+高精度)
    矩阵快速幂
    高斯消元
  • 原文地址:https://www.cnblogs.com/wangcp-2014/p/5735720.html
Copyright © 2011-2022 走看看