专栏文章 改造思寒的 AppCrawler,使其支持 Appium 最新版本

cmlanche · 2019年05月08日 · 最后由 zwt0204 回复于 2020年07月18日 · 7563 次阅读

思绪

最近完成了自定义 Appium 的需求,让 Appium 内置了自动识别权限框并点击的能力,参考我的知乎专栏:自定义 Appium 之路

但遇到另外一个问题,就是 testerhome 思寒开发的 AppiumCrawler 并不支持 Appium 最新版,也就是当前的 1.12 版本,只支持到 1.8 版本,让人很是捉急。

本来是想基于 1.8 重新自定义一个 appium,但是发现这个 appium 实在太老了,下载下来编译都有各种问题,况且后续还要自定义 appium-android-driver,appium-uiautomator2-driver 和 appium-uiaumator2-server,工作量至少得 3 天,太费时间。

索性,我来替思寒把 AppCrawler 来升级一下,让它支持最新 appium。

刚开始觉得挺难的,毕竟我对 scala 只略知一二,编译打包方面还要学,但事后发现,这个工程做的确实不错,升级改造过程比预计的要简单很多,这里要给思寒大佬一个赞👍!

改造

先看看出了什么问题?

我开启最新的 appium:

appium

执行 appcrawler 测试:

java -jar appcrawler-2.1.3.jar -a ApiDemos-debug.apk 

执行过程中在 appium 和 appcrawler 两端都报错:

[HTTP] <-- GET /wd/hub/session/efdf97d8-cf46-4ffb-b2d4-7d8feb931cee/window/rect 200 7 ms - 50
[HTTP] 
[HTTP] --> POST /wd/hub/session/efdf97d8-cf46-4ffb-b2d4-7d8feb931cee/execute/sync
[HTTP] {"script":"var source = document.documentElement.outerHTML; \nif (!source) { source = new XMLSerializer().serializeToString(document); }\nreturn source;","args":[]}
[debug] [W3C (efdf97d8)] Calling AppiumDriver.execute() with args: ["var source = document.documentElement.outerHTML; \nif (!source) { source = new XMLSerializer().serializeToString(document); }\nreturn source;",[],"efdf97d8-cf46-4ffb-b2d4-7d8feb931cee"]
[debug] [W3C (efdf97d8)] Encountered internal error running command: NotImplementedError: Method is not implemented
[debug] [W3C (efdf97d8)]     at AndroidDriver.extensions.execute (/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/lib/commands/execute.js:12:9)
[debug] [W3C (efdf97d8)]     at curCommandCancellable._bluebird.default.resolve.then (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:291:18)
[debug] [W3C (efdf97d8)]     at tryCatcher (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/util.js:26:23)
[debug] [W3C (efdf97d8)]     at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/promise.js:510:31)
[debug] [W3C (efdf97d8)]     at Promise._settlePromiseAt (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/promise.js:584:18)
[debug] [W3C (efdf97d8)]     at Promise._settlePromiseAtPostResolution (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/promise.js:248:10)
[debug] [W3C (efdf97d8)]     at Async._drainQueue (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/async.js:128:12)
[debug] [W3C (efdf97d8)]     at Async._drainQueues (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/async.js:133:10)
[debug] [W3C (efdf97d8)]     at Immediate.Async.drainQueues (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/async.js:15:14)
[debug] [W3C (efdf97d8)]     at runCallback (timers.js:705:18)
[debug] [W3C (efdf97d8)]     at tryOnImmediate (timers.js:676:5)
[debug] [W3C (efdf97d8)]     at processImmediate (timers.js:658:5)
[HTTP] <-- POST /wd/hub/session/efdf97d8-cf46-4ffb-b2d4-7d8feb931cee/execute/sync 405 11 ms - 1600
[HTTP] 
[HTTP] --> POST /wd/hub/session/efdf97d8-cf46-4ffb-b2d4-7d8feb931cee/execute/sync
[HTTP] {"script":"var source = document.documentElement.outerHTML; \nif (!source) { source = new XMLSerializer().serializeToString(document); }\nreturn source;","args":[]}
[debug] [W3C (efdf97d8)] Calling AppiumDriver.execute() with args: ["var source = document.documentElement.outerHTML; \nif (!source) { source = new XMLSerializer().serializeToString(document); }\nreturn source;",[],"efdf97d8-cf46-4ffb-b2d4-7d8feb931cee"]
[debug] [W3C (efdf97d8)] Encountered internal error running command: NotImplementedError: Method is not implemented
[debug] [W3C (efdf97d8)]     at AndroidDriver.extensions.execute (/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/lib/commands/execute.js:12:9)
[debug] [W3C (efdf97d8)]     at curCommandCancellable._bluebird.default.resolve.then (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:291:18)
[debug] [W3C (efdf97d8)]     at tryCatcher (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/util.js:26:23)
[debug] [W3C (efdf97d8)]     at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/promise.js:510:31)
[debug] [W3C (efdf97d8)]     at Promise._settlePromiseAt (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/promise.js:584:18)
[debug] [W3C (efdf97d8)]     at Promise._settlePromiseAtPostResolution (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/promise.js:248:10)
[debug] [W3C (efdf97d8)]     at Async._drainQueue (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/async.js:128:12)
[debug] [W3C (efdf97d8)]     at Async._drainQueues (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/async.js:133:10)
[debug] [W3C (efdf97d8)]     at Immediate.Async.drainQueues (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/async.js:15:14)
[debug] [W3C (efdf97d8)]     at runCallback (timers.js:705:18)
[debug] [W3C (efdf97d8)]     at tryOnImmediate (timers.js:676:5)
[debug] [W3C (efdf97d8)]     at processImmediate (timers.js:658:5)
[HTTP] <-- POST /wd/hub/session/efdf97d8-cf46-4ffb-b2d4-7d8feb931cee/execute/sync 405 4 ms - 1600
[HTTP] 
[HTTP] --> POST /wd/hub/session/efdf97d8-cf46-4ffb-b2d4-7d8feb931cee/execute/sync
[HTTP] {"script":"var source = document.documentElement.outerHTML; \nif (!source) { source = new XMLSerializer().serializeToString(document); }\nreturn source;","args":[]}
[debug] [W3C (efdf97d8)] Calling AppiumDriver.execute() with args: ["var source = document.documentElement.outerHTML; \nif (!source) { source = new XMLSerializer().serializeToString(document); }\nreturn source;",[],"efdf97d8-cf46-4ffb-b2d4-7d8feb931cee"]
[debug] [W3C (efdf97d8)] Encountered internal error running command: NotImplementedError: Method is not implemented
[debug] [W3C (efdf97d8)]     at AndroidDriver.extensions.execute (/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/lib/commands/execute.js:12:9)
[debug] [W3C (efdf97d8)]     at curCommandCancellable._bluebird.default.resolve.then (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:291:18)
[debug] [W3C (efdf97d8)]     at tryCatcher (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/util.js:26:23)
[debug] [W3C (efdf97d8)]     at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/promise.js:510:31)
[debug] [W3C (efdf97d8)]     at Promise._settlePromiseAt (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/promise.js:584:18)
[debug] [W3C (efdf97d8)]     at Promise._settlePromiseAtPostResolution (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/promise.js:248:10)
[debug] [W3C (efdf97d8)]     at Async._drainQueue (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/async.js:128:12)
[debug] [W3C (efdf97d8)]     at Async._drainQueues (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/async.js:133:10)
[debug] [W3C (efdf97d8)]     at Immediate.Async.drainQueues (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/node_modules/bluebird/js/main/async.js:15:14)
[debug] [W3C (efdf97d8)]     at runCallback (timers.js:705:18)
[debug] [W3C (efdf97d8)]     at tryOnImmediate (timers.js:676:5)
[debug] [W3C (efdf97d8)]     at processImmediate (timers.js:658:5)
[HTTP] <-- POST /wd/hub/session/efdf97d8-cf46-4ffb-b2d4-7d8feb931cee/execute/sync 405 9 ms - 1600
[HTTP]
2019-05-08 11:34:01 WARN [AppiumClient.$anonfun$getPageSource$1.340] get page source error
2019-05-08 11:34:01 WARN [Crawler.refreshPage.562] page source get fail, go back
2019-05-08 11:34:01 INFO [Crawler.setElementAction.660] set action to back
2019-05-08 11:34:01 INFO [Crawler.runStartupScript.236] first refresh
2019-05-08 11:34:01 INFO [Crawler.doElementAction.976] current element = _startupActions-Start-0
2019-05-08 11:34:01 INFO [Crawler.doElementAction.977] current index = 0
2019-05-08 11:34:01 INFO [Crawler.doElementAction.978] current action = 
2019-05-08 11:34:01 INFO [Crawler.doElementAction.979] current url = 
2019-05-08 11:34:01 INFO [Crawler.doElementAction.980] current xpath = startupActions-Start-0
2019-05-08 11:34:01 INFO [Crawler.doElementAction.981] current tag path = _startupActions-Start-0
2019-05-08 11:34:01 INFO [Crawler.doElementAction.982] current file name = _
2019-05-08 11:34:01 INFO [Crawler.doElementAction.983] current uri =    startupActions-Start-0          startupActions
Exception in thread "main" java.util.NoSuchElementException: last of empty ListBuffer
    at scala.collection.mutable.ListBuffer.last(ListBuffer.scala:401)
    at com.testerhome.appcrawler.DataRecord.last(DataRecord.scala:40)
    at com.testerhome.appcrawler.Crawler.doElementAction(Crawler.scala:985)
    at com.testerhome.appcrawler.Crawler.runStartupScript(Crawler.scala:238)
    at com.testerhome.appcrawler.Crawler.start(Crawler.scala:152)
    at com.testerhome.appcrawler.AppCrawler$.startCrawl(AppCrawler.scala:344)
    at com.testerhome.appcrawler.AppCrawler$.parseParams(AppCrawler.scala:312)
    at com.testerhome.appcrawler.AppCrawler$.main(AppCrawler.scala:92)
    at com.testerhome.appcrawler.AppCrawler.main(AppCrawler.scala)

分析原因

我们看到 Appcrawler 中报了个get page source error,我们追查 appcrawler 的代码发现是在这里报错的:

override def getPageSource(): String = {
    currentPageSource=null
    currentPageDom=null
    log.info("start to get page source from appium")
    //获取页面结构, 最多重试3次
    1 to 3 foreach (i => {
      asyncTask(20)(driver.getPageSource) match {
        case Some(v) => {
          log.trace("get page source success")
          //todo: wda返回的不是标准的xml
          val xmlStr=v match {
            case json if json.trim.charAt(0)=='{' => {
              log.info("json format maybe from wda")
              DataObject.fromJson[Map[String, String]](v).getOrElse("value", "")
            }
            case xml if xml.trim.charAt(0)=='<' =>{
              log.info("xml format ")
              xml
            }
          }
          Try(XPathUtil.toDocument(xmlStr)) match {
            case Success(v) => {
              currentPageDom = v
            }
            case Failure(e) => {
              log.warn("convert to xml fail")
              log.warn(xmlStr)
              currentPageDom=null
            }
          }

          currentPageSource = XPathUtil.toPrettyXML(xmlStr)
          return currentPageSource
        }
        case None => {
          log.warn("get page source error")
        }
      }
    })
    currentPageSource
  }

我们看 appium 的源码,发现在 appcrawler 给我们的 appium 传递了一段 js 代码来获取控件树

{"script":"var source = document.documentElement.outerHTML; \nif (!source) { source = new XMLSerializer().serializeToString(document); }\nreturn source;","args":[]}

然而,我们的 appium 代码对 get page source 这个功能接口做了限制,源码在appium-android-driver中的 lib/execute.js 中:

extensions.execute = async function execute (script, args) {
  if (script.match(/^mobile:/)) {
    script = script.replace(/^mobile:/, '').trim();
    return await this.executeMobile(script, _.isArray(args) ? args[0] : args);
  }

  throw new errors.NotImplementedError();
};

我们可以看到,这里抛出异常了,说明可能是接口变动了,那么我这里有个大胆猜想,appcrawler 所使用的 java-client 过老。

解决问题

ok,立马开始行动,替换上最新的 java-client,也就是 7.0,同时我们使用最新的 appcrawler2.4.0

<dependency>
  <groupId>com.github.appium</groupId>
  <artifactId>java-client</artifactId>
  <version>v7.0.0</version>
</dependency>

同时添加对应的仓库:

<repository>
  <id>jitpack.io</id>
  <url>https://jitpack.io</url>
</repository>

打包

mvn assembly:assembly

打包完成,会再 target 目录下生成一个完整依赖的 jar 包:appcrawler-2.4.0-jar-with-dependencies.jar

重新执行,你会发现美妙的事情发生,最新 appium 完美支持!

提出质疑

上面的完美支持,是不是因为我更新了最新版本 2.4.0,而不是使用的最开始的 2.1.3 版本呢?

有可能!!!

撤销修改,直接打包 2.4.0,执行测试看是否正常。

结果就是:最开始的 get page source 问题没了,但出现另外一个问题:

2019-05-08 11:55:46 INFO [AppiumClient.30.initLog] already exist
Exception in thread "main" scala.MatchError: [app, appium, deviceName, dontStopAppOnReset, fullReset, noReset] (of class java.util.Collections$UnmodifiableSet)
        at com.testerhome.appcrawler.driver.AppiumClient.appium(AppiumClient.scala:94)
        at com.testerhome.appcrawler.driver.AppiumClient.<init>(AppiumClient.scala:40)
        at com.testerhome.appcrawler.Crawler.setupAppium(Crawler.scala:277)
        at com.testerhome.appcrawler.Crawler.restart(Crawler.scala:221)
        at com.testerhome.appcrawler.Crawler.crawl(Crawler.scala:201)
        at com.testerhome.appcrawler.Crawler.start(Crawler.scala:170)
        at com.testerhome.appcrawler.AppCrawler$.startCrawl(AppCrawler.scala:323)
        at com.testerhome.appcrawler.AppCrawler$.parseParams(AppCrawler.scala:291)
        at com.testerhome.appcrawler.AppCrawler$.main(AppCrawler.scala:91)
        at com.testerhome.appcrawler.AppCrawler.main(AppCrawler.scala)
chengmingdeMacBook-Pro:AppCrawler cmlanche$ 
[debug] [W3C (dd159942)] Encountered internal error running command: NoSuchDriverError: A session is either terminated or not started
[debug] [W3C (dd159942)]     at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:298:15)
[debug] [W3C (dd159942)]     at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:489:15)
[debug] [W3C (dd159942)]     at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [W3C (dd159942)]     at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/route.js:137:13)
[debug] [W3C (dd159942)]     at Route.dispatch (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/route.js:112:3)
[debug] [W3C (dd159942)]     at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [W3C (dd159942)]     at /usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:281:22
[debug] [W3C (dd159942)]     at param (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:354:14)
[debug] [W3C (dd159942)]     at param (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:365:14)
[debug] [W3C (dd159942)]     at Function.process_params (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:410:3)
[debug] [W3C (dd159942)]     at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
[debug] [W3C (dd159942)]     at logger (/usr/local/lib/node_modules/appium/node_modules/morgan/index.js:144:5)
[debug] [W3C (dd159942)]     at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [W3C (dd159942)]     at trim_prefix (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:317:13)
[debug] [W3C (dd159942)]     at /usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:284:7
[debug] [W3C (dd159942)]     at Function.process_params (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:335:12)
[debug] [W3C (dd159942)]     at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
[debug] [W3C (dd159942)]     at jsonParser (/usr/local/lib/node_modules/appium/node_modules/body-parser/lib/types/json.js:110:7)
[debug] [W3C (dd159942)]     at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [W3C (dd159942)]     at trim_prefix (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:317:13)
[debug] [W3C (dd159942)]     at /usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:284:7
[debug] [W3C (dd159942)]     at Function.process_params (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:335:12)
[debug] [W3C (dd159942)]     at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
[debug] [W3C (dd159942)]     at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:91:12)
[debug] [W3C (dd159942)]     at trim_prefix (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:317:13)
[debug] [W3C (dd159942)]     at /usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:284:7
[debug] [W3C (dd159942)]     at Function.process_params (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:335:12)
[debug] [W3C (dd159942)]     at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
[HTTP] <-- GET /wd/hub/session/dd159942-ed6d-411c-8dcc-b43d7fc26284/source 404 5 ms - 3173

还是错的!

那就用我的最新 java-client 7.0 吧,重新执行一次完整的测试,发现没有任何问题!

可以看:https://github.com/cmlanche/AppCrawler/tree/2.3.1 我的修改

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 37 条回复 时间 点赞

棒棒的

恒温 回复

大佬求推荐精华😀 😀

提交 PR 不就结了😏

槽神 回复

得排期到 2025 年

可以的

我用例最新的 jar 包,还是会报错
019-05-20 19:50:15 INFO [Crawler.627.refreshPage] refresh page
2019-05-20 19:50:15 INFO [AppiumClient.102.getPageSourceWithRetry] start to get page source from appium
2019-05-20 19:50:35 ERROR [AppiumClient.234.asyncTask] 20 seconds timeout
2019-05-20 19:50:35 ERROR [AppiumClient.137.$anonfun$getPageSourceWithRetry$1] get page source error
2019-05-20 19:50:55 ERROR [AppiumClient.234.asyncTask] 20 seconds timeout
2019-05-20 19:51:32 ERROR [AppiumClient.137.$anonfun$getPageSourceWithRetry$1] get page source error

玛雅 回复

appium 版本是多少?
确定按照我的方法重新打包了吗?

刚好遇到,好人呐!

mac appium 桌面版本 1.12.1 用了这个方法后,表示还提示错误,是不支持这个版本吗
2019-07-25 17:12:03 INFO [AppiumClient.102.getPageSourceWithRetry] start to get page source from appium
2019-07-25 17:12:23 ERROR [AppiumClient.234.asyncTask] 20 seconds timeout
2019-07-25 17:12:23 ERROR [AppiumClient.137.$anonfun$getPageSourceWithRetry$1] get page source error
2019-07-25 17:12:43 ERROR [AppiumClient.234.asyncTask] 20 seconds timeout
2019-07-25 17:12:43 ERROR [AppiumClient.137.$anonfun$getPageSourceWithRetry$1] get page source error
2019-07-25 17:13:03 ERROR [AppiumClient.234.asyncTask] 20 seconds timeout
2019-07-25 17:13:03 ERROR [AppiumClient.137.$anonfun$getPageSourceWithRetry$1] get page source error

yiran酱 回复

java-client 换了吗

cmlanche 回复

换了的,从你提供的 github 打包的,java-client 是 7.0.0

yiran酱 回复

看你这错误是获取 source 超时了,版本没问题

cmlanche 回复

这个界面有 WebView,楼主通过 Appcrawler 有什么方法可以识别到 webview 的控件吗,IOS 平台上混合 app 的 webview 用什么方法识别

Android 上用这个方法解决了问题,可以支持👍 感谢

请问这个依赖包

<dependency>
            <groupId>com.oracle</groupId>
            <artifactId>tools.jar</artifactId>
            <version>1.8</version>
            <systemPath>${java.home}/../lib/tools.jar</systemPath>
            <scope>system</scope>
        </dependency>

是本地的吗,在网上没有找到这个依赖包

沐木 回复

这个可以删了吧,因为是 jdk 啊,默认就依赖了

cmlanche 回复

嗯,这个依赖删除了,在项目目录下编译 使用 mvn assembly:assembly
报错如下
没有找到这个路径,请问是为什么呢

沐木 回复


javax.xml
jaxrpc-api
1.1

缺少依赖包吧

沐木 回复
<!-- https://mvnrepository.com/artifact/javax.xml/jaxrpc-api -->
<dependency>
    <groupId>javax.xml</groupId>
    <artifactId>jaxrpc-api</artifactId>
    <version>1.1</version>
</dependency>
cmlanche 回复

灰常感谢

点个赞。 今天使用默认的版本也遇到这个问题——

2019-11-08 11:47:18 INFO [Crawler.274.setupAppium] Map(appium -> http://127.0.0.1:4723/wd/hub, noReset -> true, dontStopAppOnReset -> true, app -> , fullReset -> false)
2019-11-08 11:47:18 INFO [AppiumClient.30.initLog] already exist
Exception in thread "main" scala.MatchError: [app, appium, deviceName, dontStopAppOnReset, fullReset, noReset] (of class java.util.Collections$UnmodifiableSet)
        at com.testerhome.appcrawler.driver.AppiumClient.appium(AppiumClient.scala:94)
        at com.testerhome.appcrawler.driver.AppiumClient.<init>(AppiumClient.scala:40)
        at com.testerhome.appcrawler.Crawler.setupAppium(Crawler.scala:277)
        at com.testerhome.appcrawler.Crawler.restart(Crawler.scala:221)
        at com.testerhome.appcrawler.Crawler.crawl(Crawler.scala:201)
        at com.testerhome.appcrawler.Crawler.start(Crawler.scala:170)
        at com.testerhome.appcrawler.AppCrawler$.startCrawl(AppCrawler.scala:322)
        at com.testerhome.appcrawler.AppCrawler$.parseParams(AppCrawler.scala:290)
        at com.testerhome.appcrawler.AppCrawler$.main(AppCrawler.scala:91)
        at com.testerhome.appcrawler.AppCrawler.main(AppCrawler.scala)

请问你有更新之后的 jar 包吗,本人是 java 小白,这块不清楚怎么更新呢。谢谢。

向大佬求助,帮忙看下这个报错是什么问题?感谢🙏

[WARNING] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/DataObject.scala:91: warning: non-variable type argument String in type pattern scala.collection.Map[String,_] is unchecked since it is eliminated by erasure
[WARNING]           case (key: String, valueMap: scala.collection.Map[String, _]) => {
[WARNING]                                                         ^
[WARNING] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/TData.scala:144: warning: non-variable type argument String in type pattern scala.collection.Map[String,_] is unchecked since it is eliminated by erasure
[WARNING]           case (key: String, valueMap: scala.collection.Map[String, _]) => {
[WARNING]                                                         ^
[WARNING] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/TData.scala:203: warning: non-variable type argument String in type scala.collection.mutable.Map[String,Any] is unchecked since it is eliminated by erasure
[WARNING]         if (origin(keys.head).isInstanceOf[mutable.Map[String, Any]] == false) {
[WARNING]                                           ^
[WARNING] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/TData.scala:224: warning: abstract type K in type pattern scala.collection.immutable.Map[K,_] (the underlying of Map[K,_]) is unchecked since it is eliminated by erasure
[WARNING]               case (v1: Map[K, _], v2: Map[K, _]) => deepMerge(v1, v2)
[WARNING]                         ^
[WARNING] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/TData.scala:224: warning: abstract type K in type pattern scala.collection.immutable.Map[K,_] (the underlying of Map[K,_]) is unchecked since it is eliminated by erasure
[WARNING]               case (v1: Map[K, _], v2: Map[K, _]) => deepMerge(v1, v2)
[WARNING]                                        ^
[WARNING] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/TData.scala:348: warning: non-variable type argument String in type pattern scala.collection.immutable.Map[String,_] (the underlying of Map[String,_]) is unchecked since it is eliminated by erasure
[WARNING]       case kv: Map[String, _] => {
[WARNING]                ^
[WARNING] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/driver/AppiumClient.scala:51: warning: a pure expression does nothing in statement position
[WARNING]       case _ => command
[WARNING]                 ^
[ERROR] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/driver/AppiumClient.scala:226: error: too many arguments (2) for method press: (x$1: io.appium.java_client.touch.offset.PointOption[T] forSome { type T <: io.appium.java_client.touch.offset.PointOption[T] })T
[ERROR]           .press((screenWidth * startX).toInt, (screenHeight * startY).toInt)
[ERROR]                                                                        ^
[ERROR] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/driver/AppiumClient.scala:278: error: overloaded method value tap with alternatives:
[ERROR]   (x$1: io.appium.java_client.touch.offset.PointOption[T] forSome { type T <: io.appium.java_client.touch.offset.PointOption[T] })T <and>
[ERROR]   (x$1: io.appium.java_client.touch.TapOptions)T
[ERROR]  cannot be applied to (org.openqa.selenium.WebElement)
[ERROR]     driver.performTouchAction(new TouchAction(driver).tap(currentElement))
[ERROR]                                                       ^
[ERROR] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/driver/AppiumClient.scala:283: error: overloaded method value longPress with alternatives:
[ERROR]   (x$1: io.appium.java_client.touch.offset.PointOption[T] forSome { type T <: io.appium.java_client.touch.offset.PointOption[T] })T <and>
[ERROR]   (x$1: io.appium.java_client.touch.LongPressOptions)T
[ERROR]  cannot be applied to (org.openqa.selenium.WebElement)
[ERROR]     driver.performTouchAction(new TouchAction(driver).longPress(currentElement))
[ERROR]                                                       ^
[ERROR] /Users/xinmei0413/AppCrawler/src/main/scala/com/testerhome/appcrawler/driver/MacacaDriver.scala:183: error: value swipe is not a member of macaca.client.MacacaClient
[ERROR]     retry(driver.swipe(
[ERROR]                  ^
[WARNING] 7 warnings found
[ERROR] four errors found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  10.685 s
[INFO] Finished at: 2019-11-13T10:23:38+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.4.2:compile (scala-compile-first) on project appcrawler: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]

鱼骨 回复

重点是这句,你好好琢磨:

/AppiumClient.scala:226: error: too many arguments (2) for method press: (x$1: io.appium.java_client.touch.offset.PointOption[T] forSome { type T <: io.appium.java_client.touch.offset.PointOption[T] })T
[ERROR]           .press((screenWidth * startX).toInt, (screenHeight * startY).toInt)
cmlanche 回复

感谢指点,我研究一下!

可以提供个 jar 包出来么,iOS 小白,不会跑

hcxyzlm 回复

不建议用这个工具,推荐用 maxim

😏 原来是你

fdeferf 回复

是我咋了😂

cmlanche 回复

为什么最近一直再研究这个,能否加个联系方式

cmlanche 回复

大神,我也是一样的错,在网上下载 jar 包:appcrawler-2.4.0-jar-with-dependencies.jar 这个包是你的么?我的 appium 版本是 1.17.1

yiran酱 回复

你好,我和你也是一个错,换移动设备都是这个错 appcrawler-2.4.0-jar-with-dependencies.jar appium 版本 1.17.1。能提供下解决思路么?

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册