Skip to content

Commit

Permalink
Merge pull request #50 from ZhouYixun/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ZhouYixun authored Nov 10, 2021
2 parents 8072e84 + cf18238 commit 9e88ea6
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 158 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.sonic</groupId>
<artifactId>sonic-agent</artifactId>
<version>1.0.0</version>
<version>1.1.2</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.5.1</version>
<version>7.6.0</version>
</dependency>
<!-- 压缩图片 -->
<dependency>
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/com/sonic/agent/automation/AndroidStepHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import com.sonic.agent.interfaces.PlatformType;
import com.sonic.agent.tools.PortTool;
import com.sonic.agent.tools.UploadTools;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MultiTouchAction;
import io.appium.java_client.TouchAction;
import io.appium.java_client.*;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidStartScreenRecordingOptions;
import io.appium.java_client.android.appmanagement.AndroidInstallApplicationOptions;
Expand Down Expand Up @@ -48,6 +46,7 @@
import java.time.Duration;
import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static org.testng.Assert.*;
Expand All @@ -62,7 +61,7 @@ public class AndroidStepHandler {
private AndroidDriver androidDriver;
private JSONObject globalParams = new JSONObject();
//包版本
private String version = "";
// private String version = "";
//测试起始时间
private long startTime;
//测试的包名
Expand Down Expand Up @@ -134,6 +133,7 @@ public void startAndroidDriver(String udId) throws InterruptedException {
desiredCapabilities.setCapability("skipLogcatCapture", true);
try {
androidDriver = new AndroidDriver(AppiumServer.service.getUrl(), desiredCapabilities);
androidDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
log.sendStepLog(StepType.PASS, "连接设备驱动成功", "");
} catch (Exception e) {
log.sendStepLog(StepType.ERROR, "连接设备驱动失败!", "");
Expand Down Expand Up @@ -1378,10 +1378,10 @@ public void runMonkey(HandleDes handleDes, JSONObject content, List<JSONObject>
} catch (InterruptedException e) {
e.printStackTrace();
}
if (version.length() == 0) {
version = AndroidDeviceBridgeTool.getAppOnlyVersion(udId, packageName);
}
log.sendStepLog(StepType.INFO, "", packageName + "包版本:" + version +
// if (version.length() == 0) {
// version = AndroidDeviceBridgeTool.getAppOnlyVersion(udId, packageName);
// }
log.sendStepLog(StepType.INFO, "", "测试目标包:" + packageName +
(isOpenPackageListener ? "<br>应用包名监听器已开启..." : "") +
(isOpenH5Listener ? "<br>H5页面监听器已开启..." : "") +
(isOpenActivityListener ? "<br>黑名单Activity监听器..." : "") +
Expand All @@ -1406,32 +1406,31 @@ public void publicStep(HandleDes handleDes, String name, JSONArray stepArray) {
}

public WebElement findEle(String selector, String pathValue) {
WebDriverWait wait = new WebDriverWait(androidDriver, 10);//显式等待
WebElement we = null;
switch (selector) {
case "id":
we = wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.id(pathValue)));
we = androidDriver.findElementById(pathValue);
break;
case "name":
we = wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.name(pathValue)));
we = androidDriver.findElementByName(pathValue);
break;
case "xpath":
we = wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.xpath(pathValue)));
we = androidDriver.findElementByXPath(pathValue);
break;
case "cssSelector":
we = wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.cssSelector(pathValue)));
we = androidDriver.findElementByCssSelector(pathValue);
break;
case "className":
we = wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.className(pathValue)));
we = androidDriver.findElementByClassName(pathValue);
break;
case "tagName":
we = wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.tagName(pathValue)));
we = androidDriver.findElementByTagName(pathValue);
break;
case "linkText":
we = wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.linkText(pathValue)));
we = androidDriver.findElementByLinkText(pathValue);
break;
case "partialLinkText":
we = wait.until(ExpectedConditions.presenceOfElementLocated(MobileBy.partialLinkText(pathValue)));
we = androidDriver.findElementByPartialLinkText(pathValue);
break;
default:
log.sendStepLog(StepType.ERROR, "查找控件元素失败", "这个控件元素类型: " + selector + " 不存在!!!");
Expand Down
35 changes: 23 additions & 12 deletions src/main/java/com/sonic/agent/automation/RemoteDebugDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.google.common.collect.ImmutableMap;
import com.sonic.agent.tools.PortTool;
import com.sonic.agent.websockets.WebViewWSServer;
import org.mitre.dsmiley.httpproxy.ProxyServlet;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
Expand All @@ -24,6 +27,7 @@
*/
@Configuration
public class RemoteDebugDriver {
private static final Logger logger = LoggerFactory.getLogger(RemoteDebugDriver.class);
private static String chromePath;
public static int port = 0;
public static WebDriver webDriver;
Expand Down Expand Up @@ -54,19 +58,26 @@ public ServletRegistrationBean proxyServletRegistration() {
@Bean
@DependsOn(value = "setChromePath")
public static void startChromeDriver() {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
ChromeOptions chromeOptions = new ChromeOptions();
System.setProperty("webdriver.chrome.driver", chromePath);
if (port == 0) {
int debugPort = PortTool.getPort();
port = debugPort;
chromeOptions.addArguments("--remote-debugging-port=" + debugPort);
} else {
chromeOptions.addArguments("--remote-debugging-port=" + port);
try {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
ChromeOptions chromeOptions = new ChromeOptions();
System.setProperty("webdriver.chrome.driver", chromePath);
if (port == 0) {
int debugPort = PortTool.getPort();
port = debugPort;
chromeOptions.addArguments("--remote-debugging-port=" + debugPort);
} else {
chromeOptions.addArguments("--remote-debugging-port=" + port);
}
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("--disable-dev-shm-usage");
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
webDriver = new ChromeDriver(desiredCapabilities);
} catch (Exception e) {
logger.info("chromeDriver启动失败!");
}
chromeOptions.addArguments("--headless");
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
webDriver = new ChromeDriver(desiredCapabilities);
}

public static void close() {
Expand Down
Loading

0 comments on commit 9e88ea6

Please sign in to comment.