adb命令

adb devices:当前设备

adb shell:直接进入模拟器内部

adb install -r <下载地址>:安装软件

 

 

找到app入口:adb logcat | grep -i displayed

com.xueqiu.android/.view.WelcomeActivityAlias

 

 

根据入口启动app:adb shell am start -W -n <app入口> -S

 


 

录制case

1、Appium中输入 app基本信息,点击 start Session

 

 

2、录制

 

 

3、进行点击、输入等操作,在对应的Recorder中可以生成代码

 

4、点击 键头所指的按钮,可以生成完整的可以运行的代码

 

 

 

5、复制代码并运行

如果报错,可能需要加个隐式等待时间  :

driver.implicitly_wait(10)

 

 

 


 

启动appium并记录日志:appium -g /tmp/appium.log

 

 


元素定位:

通过id、xpath定位,如果id定位元素多,那么需要用xpath进行定位,xpath最好用 相对定位,别用 绝对定位,一般都用xpath定位

如果控件有 content-desc属性的话,可以用Accessibility_id定位,见下方代码

 

 

为什么不通过Name、Class Name定位?安卓没有Name,Class Name只有几类,定位不准确

 

使用 uiautomatorviewer,可以进行安卓控件定位(appium desktop也可以)

和appium desktop相比,更快、不需要初始化的各种操作(具体操作见 “录制case”第一步)

点击第二个按钮可以获取 当前界面,第三个按钮 可以获取到 “去掉无用代码”的界面,更快一些

 

获取元素属性:get_attribute(),可用作断言

注意单词拼写,这是规则

public enum Attribute {
    CHECKABLE(new String[]{"checkable"}),
    CHECKED(new String[]{"checked"}),
    CLASS(new String[]{"class", "className"}),
    CLICKABLE(new String[]{"clickable"}),
    CONTENT_DESC(new String[]{"content-desc", "contentDescription"}),
    ENABLED(new String[]{"enabled"}),
    FOCUSABLE(new String[]{"focusable"}),
    FOCUSED(new String[]{"focused"}),
    LONG_CLICKABLE(new String[]{"long-clickable", "longClickable"}),
    PACKAGE(new String[]{"package"}),
    PASSWORD(new String[]{"password"}),
    RESOURCE_ID(new String[]{"resource-id", "resourceId"}),
    SCROLLABLE(new String[]{"scrollable"}),
    SELECTION_START(new String[]{"selection-start"}),
    SELECTION_END(new String[]{"selection-end"}),
    SELECTED(new String[]{"selected"}),
    TEXT(new String[]{"text", "name"}),
    // The main difference of this attribute from the preceding one is that
    // it does not replace null values with empty strings
    ORIGINAL_TEXT(new String[]{"original-text"}, false, false),
    BOUNDS(new String[]{"bounds"}),
    INDEX(new String[]{"index"}, false, true),
    DISPLAYED(new String[]{"displayed"}),
    CONTENT_SIZE(new String[]{"contentSize"}, true, false);
}

  

toast弹窗测试

只能用uiautomator2,必须使用xpath查找 ,推荐第一种

 //*[@class='android.widget.Toast']

//*[contains(@text, 'xxxx')]

appium底层 抓到toast会创建一个模拟节点,这个节点的类名=包名

 

MobileBy继承了By的区别:

 MobileBy继承了By,额外封装一层,多了 客户端定位方法

 

 android上的webview测试

安卓不同系统的webview定位符可能不同

 android想要测试app 中的webview页面,有两种方法:

1、需要用安卓6.0系统的模拟机(网易mumu不支持,建议使用android studio)进行测试,其他系统不支持

2、使用真机测试的话,需要按章debug包,debug包 一般都打开了调试webview的开关

 


 

capability语法 

 待补充

 

 


 

 

数据驱动

pyyaml地址:http://pyyaml.org.wiki/

用PO后,其实不用数据驱动就可以,但是之后如果做平台的话,还是要做数据驱动的

 

 

 

 

 

 

 

 

 

 

 

 


 

散谈

1、class有 EditText的输入框才可以输入

 

 

2、app source:类似 触屏的 DOM,都是这个界面的 控件结构

 

 posted on 2020-09-07 19:21  Lverson_tester  阅读(250)  评论(0编辑  收藏  举报