appcrawler 什么时候会停止遍历?

想问下,appcrawler 是什么时候停止遍历呢?App 所有页面基本已经遍历完了,但是会返回桌面继续遍历其他App ,并且一直不停止,这个需要怎么处理呢?

一般不会这样,它有个内置逻辑,跳出后会尝试backtoapp。你用的什么版本?

现象确实是这样的,而且测试过多次,页面基本覆盖了,但是遍历完后一直不会停止,会继续去遍历桌面其他的App。版本信息如下:

  • appium版本信息:1.21.0

  • appcrawler:2.4.0

  • 命令:java -jar appcrawler-2.4.0-jar-with-dependencies.jar -c demo.yml appcrawler.yml

  • appcrawler.yml文件配置如下:

---
pluginList: []
saveScreen: true
reportTitle: ""
resultDir: "20211027095159"
waitLoading: 500
waitLaunch: 6000
showCancel: true
maxTime: 10800
maxDepth: 10
capability:
  noReset: "true"
  autoLaunch: "true"
  fullReset: "false"
  platformName: "Android"
  platformVersion: ""
  appium: "http://127.0.0.1:4723/wd/hub"
  deviceName: "oppo"
  appPackage: "com.jlpay.merch"
  appActivity: ".ui.start.SplashActivity"
  app: ""
testcase:
  name: "TesterHome AppCrawler"
  steps:
  - xpath: "同意"
    action: click
  - xpath: "//*[@resource-id='com.jlpay.merch:id/et_login_account']"
    action: "84931015812A00N"
    time: "1"
  - xpath: "//*[@resource-id='com.jlpay.merch:id/et_login_password']"
    action: "123456Aa"
    time: "1"
  - xpath: "//*[@resource-id='com.jlpay.merch:id/btn_login']"
    action: click
    time: "1"
  - xpath: "//*[@resource-id='com.jlpay.merch:id/btn_confirm']"
    action: click
    time: "1"

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: []
backButton:
- xpath: //*[contains(@resource-id, "im_back")]
- xpath: //*[contains(@text,'返回')]
triggerActions:
- given: []
  when: null
  then: []
  xpath: "好"
  action: click
  actions: []
  times: 10
- given: []
  when: null
  then: []
  xpath: "允许"
  action: click
  actions: []
  times: 10
xpathAttributes:
- "name"
- "label"
- "value"
- "resource-id"
- "content-desc"
- "instance"
- "text"
sortByAttribute:
- "depth"
- "list"
- "selected"
findBy: "xpath"
defineUrl: []
baseUrl: []
appWhiteList: []
urlBlackList: []
urlWhiteList: []
blackList:
- xpath: //*[contains(@resource-id,'btn_loginout')and contains(@text,'退出登录')]
- xpath: "分享至微信"
- xpath: "拍照.*"
- xpath: "相机"
- xpath: "解绑"
beforeRestart: []
beforeElement:
- given: []
  when: null
  then: []
  xpath: "/*"
  action: "Thread.sleep(500)"
  actions: []
  times: 0
afterElement: []
afterPage: []
afterPageMax: 2
tagLimitMax: 4
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: []

还有个问题想问下,如果想同一个配置文件遍历Android和iOS的话,是通过androidCapability和iosCapability来控制吗?但是添加androidCapability的时候会报错,去掉androidCapability就成功了

你把appcrawler.log 发上来

appcrawler.log (3.5 MB)

  • 上面是appcrawler.log日志,下面是截图,从红色那里开始跳出App,然后再也没回来过,一直在遍历其他App,从哔哩哔哩开始,我这边不得不结束遍历。

我这边也遇到了退出App遍历其他App的情况,想问一下问题解决了没有。 appwhitelist 是不是可以避免,这个怎么配置,有没有个模板

目前还没解决,app白名单我试过,直接用包名,表示只遍历这个包名的应用,不过没效果。。。你也可以试试

2021-10-29 09:50:34 INFO [Crawler.627.refreshPage] refresh page
2021-10-29 09:50:34 INFO [AppiumClient.102.getPageSourceWithRetry] start to get page source from appium
2021-10-29 09:50:34 INFO [AppiumClient.117.$anonfun$getPageSourceWithRetry$1] xml format
2021-10-29 09:50:34 INFO [Crawler.645.parsePageContext] appName =
2021-10-29 09:50:34 INFO [Crawler.649.parsePageContext] url=Launcher
2021-10-29 09:50:34 INFO [Crawler.673.parsePageContext] currentContentHash=0e8b2ae24b23a10ec4e28f59e61a4e3b la
stContentHash=8d7ae399f2a3cb17e093f4d94e4022a3
2021-10-29 09:50:34 INFO [Crawler.675.parsePageContext] ui change
2021-10-29 09:50:34 INFO [Crawler.931.saveDom] save to 20211027095159/506_MainActivity.tag=Back.id=Back.dom
2021-10-29 09:50:35 INFO [Crawler.953.saveScreen] start screenshot
2021-10-29 09:50:35 INFO [Crawler.956.$anonfun$saveScreen$2] ui change screenshot again
2021-10-29 09:50:38 INFO [Crawler.977.saveScreen] screenshot success
2021-10-29 09:50:38 INFO [Crawler.709.afterElementAction] backRetry=2
2021-10-29 09:50:38 INFO [Crawler.712.afterElementAction] afterElementAction eval
2021-10-29 09:50:38 INFO [ReportPlugin.36.afterElementAction] clickedElementsList size = 507
2021-10-29 09:50:38 INFO [Crawler.772.crawl]

crawl next

看起来是当前的app名字没获得正确,这一步是获取你的page source中的package字段,所以你得看看你的dom文件里有没有package这个字段。

另外 appcrawler 2.7.0已经发布了,可以试试新版本

  • 是的,dom文件中package和我应用的不是同一个,用的是我手机oppo的启动包名“com.oppo.launcher”(详情如下:),正确应该是“com.jlpay.merch”,请问下这该怎么解决呢?dom文件我这边控制不了
<?xml version="1.0" encoding="UTF-8"?>
<hierarchy class="hierarchy" height="2288" index="0" rotation="0" width="1080">
  <android.widget.FrameLayout bounds="[0,0][1080,2288]"
    checkable="false" checked="false" class="android.widget.FrameLayout"
    clickable="false" displayed="true" enabled="true" focusable="false"
    focused="false" index="0" long-clickable="false"
    package="com.oppo.launcher" password="false" scrollable="false"
    selected="false" text="">
    <android.widget.LinearLayout bounds="[0,0][1080,2288]"
      checkable="false" checked="false"
      class="android.widget.LinearLayout" clickable="false"
      displayed="true" enabled="true" focusable="false" focused="false"
      index="0" long-clickable="false" package="com.oppo.launcher"
      password="false" scrollable="false" selected="false" text="">
      <android.widget.FrameLayout bounds="[0,0][1080,2288]"
        checkable="false" checked="false"
        class="android.widget.FrameLayout" clickable="false"
        displayed="true" enabled="true" focusable="false"
        focused="false" index="0" long-clickable="false"
        package="com.oppo.launcher" password="false"
        resource-id="android:id/content" scrollable="false"
        selected="false" text="">
        <android.widget.FrameLayout bounds="[0,0][1080,2288]"
          checkable="false" checked="false"
          class="android.widget.FrameLayout" clickable="false"
          displayed="true" enabled="true" focusable="false"
          focused="false" index="0" long-clickable="false"
          package="com.oppo.launcher" password="false"
          resource-id="com.oppo.launcher:id/launcher" scrollable="false"
          selected="false" text="">
          <android.widget.FrameLayout bounds="[0,0][1080,2288]"
            checkable="false" checked="false"
            class="android.widget.FrameLayout" clickable="false"
            displayed="true" enabled="true" focusable="false"
            focused="false" index="0" long-clickable="false"
            package="com.oppo.launcher" password="false"
            resource-id="com.oppo.launcher:id/drag_layer"
            scrollable="false" selected="false" text="">
            <android.widget.ScrollView bounds="[0,0][1080,2288]"
              checkable="false" checked="false"
              class="android.widget.ScrollView" clickable="false"
              displayed="true" enabled="true" focusable="false"
              focused="false" index="0" long-clickable="false"
              package="com.oppo.launcher" password="false"
              resource-id="com.oppo.launcher:id/workspace"
              scrollable="true" selected="false" text="">
              <android.view.ViewGroup bounds="[48,142][1032,1983]"
                checkable="false" checked="false"
                class="android.view.ViewGroup" clickable="false"
                displayed="true" enabled="true" focusable="false"
                focused="false" index="6" long-clickable="false"
                package="com.oppo.launcher" password="false"
                scrollable="false" selected="false" text="">
                <android.view.ViewGroup bounds="[48,142][1032,1983]"
                  checkable="false" checked="false"
                  class="android.view.ViewGroup" clickable="false"
                  displayed="true" enabled="true" focusable="false"
                  focused="false" index="0" long-clickable="false"
                  package="com.oppo.launcher" password="false"
                  scrollable="false" selected="false" text="">
                  <android.widget.TextView bounds="[786,448][1032,754]"
                    checkable="false" checked="false"
                    class="android.widget.TextView" clickable="true"
                    content-desc="哔哩哔哩" displayed="true" enabled="true"
                    focusable="true" focused="false" index="0"
                    long-clickable="true" package="com.oppo.launcher"
                    password="false" scrollable="false" selected="false" text="哔哩哔哩"/>
                  <android.widget.TextView bounds="[294,754][540,1060]"
                    checkable="false" checked="false"
                    class="android.widget.TextView" clickable="true"
                    content-desc="Leaks" displayed="true" enabled="true"
                    focusable="true" focused="false" index="1"
                    long-clickable="true" package="com.oppo.launcher"
                    password="false" scrollable="false" selected="false" text="Leaks"/>
                  <android.widget.TextView bounds="[540,754][786,1060]"
                    checkable="false" checked="false"
                    class="android.widget.TextView" clickable="true"
                    content-desc="电签测试程序" displayed="true"
                    enabled="true" focusable="true" focused="false"
                    index="2" long-clickable="true"
                    package="com.oppo.launcher" password="false"
                    scrollable="false" selected="false" text="电签测试程序"/>
                  <android.widget.TextView bounds="[786,754][1032,1060]"
                    checkable="false" checked="false"
                    class="android.widget.TextView" clickable="true"
                    content-desc="嘉联支付" displayed="true" enabled="true"
                    focusable="true" focused="false" index="3"
                    long-clickable="true" package="com.oppo.launcher"
                    password="false" scrollable="false" selected="false" text="嘉联支付"/>
                  <android.widget.TextView bounds="[48,1060][294,1366]"
                    checkable="false" checked="false"
                    class="android.widget.TextView" clickable="true"
                    content-desc="Leaks" displayed="true" enabled="true"
                    focusable="true" focused="false" index="4"
                    long-clickable="true" package="com.oppo.launcher"
                    password="false" scrollable="false" selected="false" text="Leaks"/>
                </android.view.ViewGroup>
              </android.view.ViewGroup>
            </android.widget.ScrollView>
            <android.widget.FrameLayout bounds="[0,1408][1080,2288]"
              checkable="false" checked="false"
              class="android.widget.FrameLayout" clickable="false"
              displayed="true" enabled="true" focusable="false"
              focused="false" index="1" long-clickable="false"
              package="com.oppo.launcher" password="false"
              resource-id="com.oppo.launcher:id/toggle_bar_root_top"
              scrollable="false" selected="false" text=""/>
            <android.view.View bounds="[252,1983][828,2082]"
              checkable="false" checked="false"
              class="android.view.View" clickable="false"
              displayed="true" enabled="true" focusable="true"
              focused="false" index="3" long-clickable="false"
              package="com.oppo.launcher" password="false"
              resource-id="com.oppo.launcher:id/page_indicator"
              scrollable="false" selected="false" text=""/>
            <android.view.ViewGroup bounds="[0,2082][1080,2288]"
              checkable="false" checked="false"
              class="android.view.ViewGroup" clickable="false"
              displayed="true" enabled="true" focusable="false"
              focused="false" index="4" long-clickable="false"
              package="com.oppo.launcher" password="false"
              resource-id="com.oppo.launcher:id/hotseat"
              scrollable="false" selected="false" text="">
              <android.view.ViewGroup bounds="[48,2082][1032,2288]"
                checkable="false" checked="false"
                class="android.view.ViewGroup" clickable="false"
                displayed="true" enabled="true" focusable="false"
                focused="false" index="0" long-clickable="false"
                package="com.oppo.launcher" password="false"
                scrollable="false" selected="false" text="">
                <android.widget.TextView bounds="[48,2082][294,2288]"
                  checkable="false" checked="false"
                  class="android.widget.TextView" clickable="true"
                  content-desc="拨号" displayed="true" enabled="true"
                  focusable="true" focused="false" index="0"
                  long-clickable="true" package="com.oppo.launcher"
                  password="false" scrollable="false" selected="false" text=""/>
                <android.widget.TextView bounds="[294,2082][540,2288]"
                  checkable="false" checked="false"
                  class="android.widget.TextView" clickable="true"
                  content-desc="信息,有 3 个通知" displayed="true"
                  enabled="true" focusable="true" focused="false"
                  index="1" long-clickable="true"
                  package="com.oppo.launcher" password="false"
                  scrollable="false" selected="false" text=""/>
                <android.widget.TextView bounds="[540,2082][786,2288]"
                  checkable="false" checked="false"
                  class="android.widget.TextView" clickable="true"
                  content-desc="浏览器" displayed="true" enabled="true"
                  focusable="true" focused="false" index="2"
                  long-clickable="true" package="com.oppo.launcher"
                  password="false" scrollable="false" selected="false" text=""/>
                <android.widget.TextView bounds="[786,2082][1032,2288]"
                  checkable="false" checked="false"
                  class="android.widget.TextView" clickable="true"
                  content-desc="相机" displayed="true" enabled="true"
                  focusable="true" focused="false" index="3"
                  long-clickable="true" package="com.oppo.launcher"
                  password="false" scrollable="false" selected="false" text=""/>
              </android.view.ViewGroup>
            </android.view.ViewGroup>
            <android.widget.RelativeLayout bounds="[0,2295][1080,2400]"
              checkable="false" checked="false"
              class="android.widget.RelativeLayout" clickable="false"
              displayed="true" enabled="true" focusable="false"
              focused="false" index="5" long-clickable="false"
              package="com.oppo.launcher" password="false"
              resource-id="com.oppo.launcher:id/apps_view"
              scrollable="false" selected="false" text=""/>
          </android.widget.FrameLayout>
        </android.widget.FrameLayout>
      </android.widget.FrameLayout>
    </android.widget.LinearLayout>
  </android.widget.FrameLayout>
</hierarchy>

2.7.0版本我试了下,App 遍历着就停住了,报下面的这个异常:另外,如果崩溃的话就退回到桌面,也是继续遍历其他App

Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: The element 'By.xpath: //*[@resource-id='com.jlpay.merch:id/tv_service_contract' and @text='服务协议']' does not exist in DOM anymore
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'kongdexideMac-mini.local', ip: 'fe80:0:0:0:1476:6fb1:79bd:45f2%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_131'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: , appActivity: .ui.start.SplashActivity, appPackage: com.jlpay.merch, appium: http://127.0.0.1:4723/wd/hub, autoLaunch: true, databaseEnabled: false, desired: {app: , appActivity: .ui.start.SplashActivity, appPackage: com.jlpay.merch, appium: http://127.0.0.1:4723/wd/hub, autoLaunch: true, deviceName: oppo, fullReset: false, newCommandTimeout: 120, noReset: true, platformName: android, platformVersion: }, deviceApiLevel: 30, deviceManufacturer: OPPO, deviceModel: PDKM00, deviceName: NZKRMFZ9RSLRAQGY, deviceScreenDensity: 480, deviceScreenSize: 1080x2400, deviceUDID: NZKRMFZ9RSLRAQGY, fullReset: false, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, newCommandTimeout: 120, noReset: true, pixelRatio: 3, platform: LINUX, platformName: Android, platformVersion: 11, statBarHeight: 112, takesScreenshot: true, viewportRect: {height: 2176, left: 0, top: 112, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: e9640e53-1720-4977-911b-01aa9b940bca
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
	at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
	at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
	at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
	at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
	at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
	at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)
	at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
	at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
	at org.openqa.selenium.remote.RemoteWebElement.getLocation(RemoteWebElement.java:337)
	at com.ceshiren.appcrawler.driver.SeleniumDriver.getRect(SeleniumDriver.scala:235)
	at com.ceshiren.appcrawler.core.Crawler.saveElementScreenshot(Crawler.scala:1150)
	at com.ceshiren.appcrawler.core.Crawler.doElementAction(Crawler.scala:1031)
	at com.ceshiren.appcrawler.core.Crawler.crawl(Crawler.scala:999)
	at com.ceshiren.appcrawler.core.Crawler.$anonfun$crawlWithRetry$1(Crawler.scala:187)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at scala.util.Try$.apply(Try.scala:210)
	at com.ceshiren.appcrawler.core.Crawler.crawlWithRetry(Crawler.scala:187)
	at com.ceshiren.appcrawler.core.Crawler.start(Crawler.scala:169)
	at com.ceshiren.appcrawler.AppCrawler$.startCrawl(AppCrawler.scala:333)
	at com.ceshiren.appcrawler.AppCrawler$.parseParams(AppCrawler.scala:300)
	at com.ceshiren.appcrawler.AppCrawler$.main(AppCrawler.scala:84)
	at com.ceshiren.appcrawler.AppCrawler.main(AppCrawler.scala)

咨询下,2.7.0版本在哪里可以获取到,我想试一下

思寒大佬,如果appName = 空 这种情况的话,配置文件中appName需要指定和appPackage: "***"一致吗?这两个是不是同一个参数。

咨询下白名单你是怎么添加的?能发一下这部分的配置参数吗??
appWhiteList:# 不同App黑名单列表路径包名不同
我不知道这个参数是怎么配置的

appcrawler 的github官网,思寒大佬已经更新了 :+1:,下载链接:
https://github.com/seveniruby/AppCrawler/releases/download/2.7.0-beta/appcrawler-2.7.0-jar-with-dependencies.jar

配置文件没有appName这个参数吧,两个重要参数:appPackage和appActivity

appWhiteList我是用包名配置的,表示整个app,urlWhiteList用activity相关页面,表示能遍历的activity,不知道配得对不对

我发现你的appName一直都是空的。我明天看看是什么原因,如果appName获取不到,就没法判断黑白名单

我这边appName也是空的,同样想咨询下 Appwhite 应该怎么配置? urlWhiteList我是配置的xpath,也不知道对不对,要是有两个参数配置的示例就很好了。

关闭