From c5242631fa4e9958383ef3926db9ace0777d8fc1 Mon Sep 17 00:00:00 2001 From: seveniruby Date: Tue, 14 Dec 2021 01:04:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=87=B32.7.4=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlog4j=E7=9A=84=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- pom.xml | 6 +- .../com/ceshiren/appcrawler/Banner.scala | 4 +- .../ceshiren/appcrawler/core/Crawler.scala | 3 - .../driver/UIAutomator2ServerDriver.scala | 123 ------------------ 5 files changed, 6 insertions(+), 132 deletions(-) delete mode 100644 src/main/scala/com/ceshiren/appcrawler/driver/UIAutomator2ServerDriver.scala diff --git a/README.md b/README.md index 99e111fa..e2d4bdec 100644 --- a/README.md +++ b/README.md @@ -396,7 +396,7 @@ pluginList: [] ## 编译 ```bash -mvn clean package -DskipTests +mvn clean package ``` ## 技术交流 diff --git a/pom.xml b/pom.xml index f57454e7..4a1373fb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,11 +6,11 @@ com.ceshiren.appcrawler appcrawler - 2.7.3 + 2.7.4 appcrawler ------------------------------------------------- - appcrawler v2.7.3 全平台自动遍历测试工具 + appcrawler v2.7.4 全平台自动遍历测试工具 Q&A: https://ceshiren.com/c/opensource/appcrawler author: 思寒 seveniruby@霍格沃兹测试开发学社 ------------------------------------------------- @@ -168,7 +168,7 @@ org.apache.logging.log4j log4j-core - 2.14.1 + 2.15.0 org.slf4j diff --git a/src/main/scala/com/ceshiren/appcrawler/Banner.scala b/src/main/scala/com/ceshiren/appcrawler/Banner.scala index 1ffc6d6e..cf3082df 100644 --- a/src/main/scala/com/ceshiren/appcrawler/Banner.scala +++ b/src/main/scala/com/ceshiren/appcrawler/Banner.scala @@ -4,9 +4,9 @@ object Banner { val banner = """ |------------------------------------------------- - |appcrawler v2.7.3 全平台自动遍历测试工具 + |appcrawler v2.7.4 全平台自动遍历测试工具 |Q&A: https://ceshiren.com/c/opensource/appcrawler - |author: 思寒 seveniruby@霍格沃兹测试开发学社 + |author: 思寒_seveniruby 天马 霍格沃兹测试开发学社 |------------------------------------------------- |""".stripMargin diff --git a/src/main/scala/com/ceshiren/appcrawler/core/Crawler.scala b/src/main/scala/com/ceshiren/appcrawler/core/Crawler.scala index f12ebd0b..7dc82e03 100644 --- a/src/main/scala/com/ceshiren/appcrawler/core/Crawler.scala +++ b/src/main/scala/com/ceshiren/appcrawler/core/Crawler.scala @@ -333,9 +333,6 @@ class Crawler { } }*/ - case "uiautomator2server" => - log.info("use uiautomator2server") - new UIAutomator2ServerDriver(conf.capability) case className if className.contains(".") => log.info(s"use ${className}") val clazz=Class.forName(className) diff --git a/src/main/scala/com/ceshiren/appcrawler/driver/UIAutomator2ServerDriver.scala b/src/main/scala/com/ceshiren/appcrawler/driver/UIAutomator2ServerDriver.scala deleted file mode 100644 index d5c1ec5d..00000000 --- a/src/main/scala/com/ceshiren/appcrawler/driver/UIAutomator2ServerDriver.scala +++ /dev/null @@ -1,123 +0,0 @@ -package com.ceshiren.appcrawler.driver - -import com.ceshiren.appcrawler.utils.Log.log -import com.ceshiren.appcrawler.utils.LogicUtils.retryToSuccess - -class UIAutomator2ServerDriver extends AdbDriver { - private val session = requests.Session() - - //本地映射的地址 - systemPort = "6791" - var serverPort = "6790" - val driverPackageName = "io.appium.uiautomator2.server.test" - val driverActivityName = "androidx.test.runner.AndroidJUnitRunner" - otherApps = List[String]() - var sessionid = "" - - var daemon: Thread = _ - - def this(configMap: Map[String, Any] = Map[String, Any]()) { - this - initConfig(configMap) - // 安装辅助APP - installOtherApps() - // 确认设备中Driver状态 - val apkPath = adb(s"shell 'pm list packages | grep ${driverPackageName} ||:'") - if (apkPath.indexOf(s"${driverPackageName}") == -1) { - log.info("Not Exist In Device,Need Install") - } - - //设备driver连接设置 - initDriver() - - if (configMap.getOrElse("noReset", "").toString.toLowerCase.equals("false") - && !packageName.contains("tencent")) { - adb(s"shell pm clear ${packageName}") - } else { - log.info("need need to reset app") - } - - if (packageName.nonEmpty && configMap.getOrElse("dontStopAppOnReset", "").toString.toLowerCase.equals("true")) { - adb(s"shell am start -W -n ${packageName}/${activityName}") - } - else if (packageName.nonEmpty && configMap.getOrElse("dontStopAppOnReset", "").toString.toLowerCase.equals("false")) { - adb(s"shell am start -S -W -n ${packageName}/${activityName}") - } else { - //小程序不能运行am start - log.info("dont run am start") - } - } - - // 安装辅助APP - def installOtherApps(): Unit = { - log.info("Install otherApps") - otherApps.foreach(app => { - log.info(s"Install App To Device From ${app}") - adb(s"install '${app}'") - }) - } - - - //设备driver连接设置 - def initDriver(): Unit = { - //设置端口转发,将driver的端口映射到本地,方便进行请求 - adb(s"forward tcp:${systemPort} tcp:${serverPort}") - // 启动Driver - driverStart() - } - - def driverStart(): Unit = { - adb(s"shell 'am force-stop ${driverPackageName} && ps | grep ${driverPackageName} ||: ' ") - adb(s"shell 'am force-stop ${driverPackageName} && ps | grep ${driverPackageName} ||: ' ") - //放入后台 - - daemon = new Thread(() => { - log.info("daemon start") - adb(s"shell am instrument -w -e disableAnalytics true ${driverPackageName}/${driverActivityName} ") - log.info("daemon finish") - }) - daemon.start() - retryToSuccess(timeoutMS = 20000, name = "wait driver")(session.get(s"${getServerUrl}/sessions").text().contains("sessionId")) - retryToSuccess(timeoutMS = 20000, name = "wait session created") { - val res = session.post(s"${getServerUrl}/session", data = "{\"capabilities\": {}}").text() - sessionid = res.split("\"")(3) - log.debug(s"sessionid = ${sessionid}") - sessionid.nonEmpty - } - log.debug(session.get(s"${getServerUrl}/sessions").text()) - } - - override def stopDriver(): Unit = { - session.delete(s"${getServerUrl}/session/${sessionid}") - log.info(s"stop session ${sessionid}") - daemon.stop() - } - - //拼接Driver访问地址 - def getServerUrl: String = { - s"http://127.0.0.1:${systemPort}/wd/hub" - } - - - override def getPageSource(): String = { - val r = session.get(s"${getServerUrl}/session/${sessionid}/source").text() - r - } - - - override def getAppName(): String = { - page.getNodeListByKey("/*/*").head.getOrElse("package", "").toString - } - - override def reStartDriver(waitTime: Int, action: String): Unit = { - log.info("reStartDriver") - driverStart() - // todo:需要优化 - // 重启服务后需要通过页面动作触发page source刷新,保证能够获取到最新的界面数据 - swipe(0.5, 0.4, 0.5, 0.5) - Thread.sleep(1000) - - } - -} -