关于软件测试:测试开发-AppCrawler-自动遍历测试实践二定制化配置

4次阅读

共计 5629 个字符,预计需要花费 15 分钟才能阅读完成。

定制化配置

主动遍历测试技术以及工具该如何抉择和疾速入门?通过比照和需要,最终抉择测试架构师思寒大佬的 AppCrawler 作为主动遍历测试的工具。以下就分享 AppCrawler 主动遍历测试的一些最佳实践经验。

模板文件生成

运行命令 java -jar appcrawler-2.4.0-jar-with-dependencies.jar –demo, 会在当前目录下生成一个 demo.yml 文件, 这个文件就是咱们进行定制化的配置文件模板:

执行命令生成 demo.yaml 模板配置文件

$ java -jar appcrawler-2.4.0-jar-with-dependencies.jar –demo

2019-12-01 21:33:35 INFO [AppCrawler$.86.main]

AppCrawler 2.4.0 [霍格沃兹测试开发学社特地纪念版]
Appium 1.8.1 Java8 tested
app 爬虫, 用于主动遍历测试. 反对 Android 和 iOS, 反对真机和模拟器

我的项目地址: https://github.com/seveniruby…

2019-12-01 21:33:35 INFO [AppCrawler$.223.parseParams] use default appium address 4723
2019-12-01 21:33:35 INFO [AppCrawler$.230.parseParams] appium address = Some(http://127.0.0.1:4723/wd/hub)
2019-12-01 21:33:35 INFO [AppCrawler$.242.parseParams] result directory = 20191201213335
2019-12-01 21:33:36 INFO [AppCrawler$.286.parseParams] you can read /Users/qinzhen/Documents/TestDev/AppCrawler/demo.yml for demo

查看配置文件已生成

$ ls
appcrawler-2.4.0-jar-with-dependencies.jar
demo.yml

​​​

关上配置文件 demo.yaml 如下:


pluginList: []
saveScreen: true
reportTitle: “”
resultDir: “20191201213335”
waitLoading: 500
waitLaunch: 6000
showCancel: true
maxTime: 10800
maxDepth: 10
capability:
noReset: “true”
fullReset: “false”
appium: “http://127.0.0.1:4723/wd/hub”
testcase:
name: “Ceshiren AppCrawler”
steps:

  • given: []
    when: null
    then: []
    xpath: “/*”
    action: “Thread.sleep(5000)”
    actions: []
    times: 0

selectedList:

  • given: []
    when: null
    then: []
    xpath: “//*[contains(name(), ‘Button’)]”
    action: null
    actions: []
    times: 0
  • given: []
    when: null
    then: []
    xpath: “//*[contains(name(), ‘Text’) and @clickable=’true’ and string-length(@text)<10]”
    action: null
    actions: []
    times: 0
  • given: []
    when: null
    then: []
    xpath: “//[@clickable=’true’]/[contains(name(), ‘Text’) and string-length(@text)<10]”
    action: null
    actions: []
    times: 0
  • given: []
    when: null
    then: []
    xpath: “//*[contains(name(), ‘Image’) and @clickable=’true’]”
    action: null
    actions: []
    times: 0
  • given: []
    when: null
    then: []
    xpath: “//[@clickable=’true’]/[contains(name(), ‘Image’)]”
    action: null
    actions: []
    times: 0
  • given: []
    when: null
    then: []
    xpath: “//*[contains(name(), ‘Image’) and @name!=”]”
    action: null
    actions: []
    times: 0
  • given: []
    when: null
    then: []
    xpath: “//*[contains(name(), ‘Text’) and @name!=” and string-length(@label)<10]”
    action: null
    actions: []
    times: 0
    firstList: []
    lastList:
  • given: []
    when: null
    then: []
    xpath: “//[@selected=’true’]/..//
    action: null
    actions: []
    times: 0
  • given: []
    when: null
    then: []
    xpath: “//[@selected=’true’]/../..//
    action: null
    actions: []
    times: 0
    backButton:
  • given: []
    when: null
    then: []
    xpath: “Navigate up”
    action: null
    actions: []
    times: 0
    triggerActions:
  • given: []
    when: null
    then: []
    xpath: “share_comment_guide_btn”
    action: null
    actions: []
    times: 0
    xpathAttributes:
  • “name”
  • “label”
  • “value”
  • “resource-id”
  • “content-desc”
  • “instance”
  • “text”
    sortByAttribute:
  • “depth”
  • “list”
  • “selected”
    findBy: “default”
    defineUrl: []
    baseUrl: []
    appWhiteList: []
    urlBlackList: []
    urlWhiteList: []
    blackList:
  • given: []
    when: null
    then: []
    xpath: “.[0-9]{2}.
    action: null
    actions: []
    times: 0
    beforeRestart: []
    beforeElement:
  • given: []
    when: null
    then: []
    xpath: “/*”
    action: “Thread.sleep(500)”
    actions: []
    times: 0
    afterElement: []
    afterPage: []
    afterPageMax: 2
    tagLimitMax: 2
    tagLimit:
  • given: []
    when: null
    then: []
    xpath: “ 确定 ”
    action: null
    actions: []
    times: 1000
  • given: []
    when: null
    then: []
    xpath: “ 勾销 ”
    action: null
    actions: []
    times: 1000
  • given: []
    when: null
    then: []
    xpath: “share_comment_guide_btn_name”
    action: null
    actions: []
    times: 1000
    assertGlobal: []

执行参数

同样,还是以雪球 App 为例,以实际操作运行来解释配置文件中各个参数的含意和用法

capability 设置: 与 appium 完全一致, 但要留神这里默认有 noReset: “true” 和 appium: “http://127.0.0.1:4723/wd/hub” 属性, 配置实现如下

capability:
noReset: “false”
fullReset: “false”
appium: “http://127.0.0.1:4723/wd/hub”
appPackage: com.xueqiu.androi
appActivity: .view.WelcomeActivityAlias
automationName: uiautomator2
autoGrantPermissions: true
这里再介绍两个很乏味也很有用的参数:

dontStopAppOnReset: true ; 这个参数容许咱们在某个页面继续执行遍历,比方咱们心愿 App 先进入到某个页面后再进行遍历,或者当一个 session 完结后持续下一个 session 的时候咱们心愿不要杀死 App 从新执行,而是持续上一次完结的页面开始执行

ignoreUnimportantViews: 这个参数设置为 true 的时候能够疏忽不重要的 view,减速 pageSource 的加载,放慢测试速度

testcase: 用于启动 APP 后的根底测试用例

执行参数

残缺状态

容许咱们以 given、when、then 的模式指定操作,如果学习过 Java 的接口自动化框架 rest-assured 话能够很容易了解这三个参数表白的含意:

given : 所有的先决条件,给定一个条件,只有条件成立的时候才实现前面的操作(理论用的较少)

when : 先决条件成立后的行为,对什么事件做什么事件

then : 断言汇合,事件完结后对后果断言

具体写法如下:

estcase:
name: “Ceshiren AppCrawler”
steps:

  • when:

    xpath: //*
    action: driver.swipe(0.5, 0.8, 0.5, 0.2)
  • when:

    xpath: //*
    action: driver.swipe(0.5, 0.2, 0.5, 0.8)

    then:

    • //*[contains(@text, ‘ 美股 ’)]

执行参数

简写状态

另外理论应用中咱们会常常应用简写状态

间接应用 xpath 对应 when 外面的 xpath

间接应用 action 对应 when 外面的 action 具体写法如下:

xpath: 自选
action: click
then:

  • //*[contains(@text, ‘ 美股 ’)]

注:定位模式除了能够应用 xpath 之外还能够应用正则和蕴含关系,只不过常常应用的是 xpath,也更为谨严;

正则:应用 ^ 结尾的就认定为正则,^ 确定 $,^.* 输出明码

蕴含:能够应用元素其中蕴含的内容进行定位; 明码,输出,请

这里以雪球首页搜寻框输出 alibaba 的简略场景举例,在搜寻前还须要解决掉降级弹框,批改实现如下:

testcase:
name: “XueQiuTestDemo AppCrawler”
steps:

  • {xpath: “//*[contains(@resource-id,’image_cancel’)]”, action: click }
  • xpath: home_search
    action: click
  • xpath: search_input_text
    action: alibaba

如上的 testcase 写法还要多说几句:

也能够应用 {} 将须要执行的事件包裹起来,元素定位符和操作 action 工夫用逗号隔开

{} 内若应用 xpath 表达式的话须要加双引号

xpath 中间接写 id 或 text 文本信息,就会默认应用蕴含去查找

须要点击的事件要明确指明 click,某则会报错;尽管思寒说过默认的 action 就是 click,然而通过实测发现在 2.4.0 版本上必须指明 action:click ; 很可能是思寒本地应用的外部版本通过了优化更新还未来得及开源到 GitHub 上。

运行成果:

selectedList: 遍历范畴设定
这里如果想设置让其点击所有可点击的 TextView 和 ImageView 控件, 批改实现如下:

selectedList:

  • xpath: //android.widget.ImageView[@clickable=’true’]
  • xpath: //*[@clickable=’true’ and contains(@class,”Text”)]
    firstList: 优先被点击

lastList: 最初执行 设置其最初才执行 ” 确定 ” 按钮, 批改实现如下:

lastList:

  • {xpath: text_yes, action: click}
    backButton: 当所有元素都被点击后默认后退控件定位

blackList:黑名单

triggerAction: 特定条件登程执行动作的设置; 设置遇到重置明码输入框时输出 123456abc 两次, 批改实现如下:

triggerActions:

  • {xpath: android.widget.EditText, action: 123456abc, times: 2}
    tagLimitMax: 全局设置, 同类型的最多点击的次数; 这里设置为 2 次

tagLimitMax: 2
tagLimit: 自定义控件类型的点击次数, 这里设置对于 ListView 类型的只点击一次; 批改实现如下:

  • {xpath: “//[contains(@class, ‘List’)]//“, times: 1 }
    maxDepth: 遍历的最大深度

assertGlobal:设置一个全局断言,例如可设置断言在以后 App,如果包名不合乎,就可能产生了解体,便会报错

注:执行参数比配置文件优先级高

到这里,appcrawler 的根本语法和参数含意大抵介绍了一遍,前面就是如何结合实际进行应用了。下一篇将进行具体的介绍。
————————————————
版权申明:本文为 CSDN 博主「霍格沃兹测试开发学社」的原创文章,遵循 CC 4.0 BY-SA 版权协定,转载请附上原文出处链接及本申明。
原文链接:https://blog.csdn.net/Hogwart…

正文完
 0