appcrawler进阶公开课

xpath相对路径用法

  • 绝对定位 /xxx/ddd/dddd
  • 相对定位 //android.widget.Button
  • 查找
    • 所有元素://*
    • 包含条件://*[contains(@resource-id, ‘login’)]
    • 满足属性值://*[@text=‘登录’]
    • 多条件联合:
      • //*[contains(@resource-id, ‘login’) and contains(@text, ‘登录’)]]
      • //*[contains(@text, ‘登录’) or contains(@label, ‘登录’)]]
    • 当多控件同时出现://[contains(@text, ‘看点’)]/ancestor:://*[contains(name(), ‘EditText’)]
    • 根据可点击属性和文本内容长度筛选://*[@clickable=“true”]//android.widget.TextView[string-length(@text)>0 and string-length(@text)<20]

配置文件定制

生成配置模板

java -jar appcrawler-2.4.1-jar-with-dependencies.jar --demo

配置capability

adb logcat | grep -i displayed
10-28 20:35:47.172   673   692 I ActivityManager: Displayed com.xueqiu.android/.view.WelcomeActivityAlias: +23s248ms
10-28 20:36:13.671   673   692 I ActivityManager: Displayed com.xueqiu.android/.main.view.MainActivity: +26s156ms
capability: 
  appPackage: com.xueqiu.android
  appActivity: .view.WelcomeActivityAlias
  
  noReset: "true"
  fullReset: "false"
  appium: "http://127.0.0.1:4723/wd/hub"

配置启动自动化测试用例

maxDepth: 1
firstList: []
selectedList: 
- xpath: //*[contains(@resource-id, 'indicator')]//*[contains(@resource-id, 'indicator_container')]//android.widget.TextView
- xpath: //*[contains(@resource-id, 'indicator')]//*[contains(@resource-id, 'title_text')]
lastList:
- xpath: //*[contains(@resource-id, 'indicator')]//*[contains(@resource-id, 'indicator_container')]//android.widget.TextView
- xpath: //*[contains(@resource-id, 'indicator')]//*[contains(@resource-id, 'title_text')]
blackList:
- xpath: 自选股
- xpath: 市场

测试一下

appium -g /tmp/appium --session-override
java -jar appcrawler-2.4.1-jar-with-dependencies.jar -c demo.xueqiu.yaml

配置遍历范围与顺序

maxDepth: 1
firstList: []
selectedList: 
- xpath: //*[contains(@resource-id, 'indicator')]//*[contains(@resource-id, 'indicator_container')]//android.widget.TextView
- xpath: //*[contains(@resource-id, 'indicator')]//*[contains(@resource-id, 'title_text')]
lastList:
- xpath: //*[contains(@resource-id, 'indicator')]//*[contains(@resource-id, 'indicator_container')]//android.widget.TextView
- xpath: //*[contains(@resource-id, 'indicator')]//*[contains(@resource-id, 'title_text')]
关闭