|
@@ -18,6 +18,7 @@ import net.mooctest.www.android_auto_test.models.Device;
|
|
|
import net.mooctest.www.android_auto_test.services.DeviceService;
|
|
|
import org.openqa.selenium.NoSuchSessionException;
|
|
|
import org.openqa.selenium.WebDriverException;
|
|
|
+import org.openqa.selenium.WebElement;
|
|
|
import org.openqa.selenium.remote.CapabilityType;
|
|
|
import org.openqa.selenium.remote.DesiredCapabilities;
|
|
|
import org.openqa.selenium.remote.UnreachableBrowserException;
|
|
@@ -53,7 +54,7 @@ public class CoverageTest extends Thread{
|
|
|
private String udid;
|
|
|
private String logPath;
|
|
|
private String port;
|
|
|
- private AndroidDriver driver;
|
|
|
+ private AndroidDriver<WebElement> driver;
|
|
|
private LogMonitor mLogMonitor;
|
|
|
private Thread logThread;
|
|
|
private Long startTime;
|
|
@@ -213,14 +214,10 @@ public class CoverageTest extends Thread{
|
|
|
FileUtil.newFile(execErrorLog);
|
|
|
|
|
|
// 这里先创建一些测试脚本时才会创建的内容,是为了提供给报告生成服务一个兜底的东西
|
|
|
- /**
|
|
|
- * 设备执行信息
|
|
|
- */
|
|
|
+ // 设备执行信息
|
|
|
File deviceExecFile = new File(AddressUtil.getDeviceExecInfoPath(traceId, udid));
|
|
|
FileUtil.newFile(deviceExecFile);
|
|
|
- /**
|
|
|
- * 具体脚本用到的文件和文件夹
|
|
|
- */
|
|
|
+ // 具体脚本用到的文件和文件夹
|
|
|
File myTestLog = new File(AddressUtil.getMyTestLogPath(traceId, udid));
|
|
|
File testScript = new File(AddressUtil.getTestScript(traceId, udid));
|
|
|
File testAction = new File(AddressUtil.getTestAction(traceId, udid));
|
|
@@ -229,9 +226,7 @@ public class CoverageTest extends Thread{
|
|
|
File pageSourceDir = new File(AddressUtil.getPageSourceDir(traceId, udid));
|
|
|
File pageImgDir = new File(AddressUtil.getPageImgDir(traceId, udid));
|
|
|
FileUtil.newDirs(Arrays.asList(pageXmlDir, pageImgDir, pageSourceDir));
|
|
|
- /**
|
|
|
- * 监控用到的文件和文件夹
|
|
|
- */
|
|
|
+ // 监控用到的文件和文件夹
|
|
|
File logcatFile = new File(AddressUtil.getLogCatLogPath(traceId, udid));
|
|
|
File appiumLogFile = new File(AddressUtil.getAppiumLogPath(traceId, udid));
|
|
|
File exceptionLogsPath = new File(AddressUtil.getExceptionPath(traceId, udid));
|
|
@@ -363,7 +358,7 @@ public class CoverageTest extends Thread{
|
|
|
int index = 0;
|
|
|
while (! success && index <= Consts.INIT_DRIVER_TIMES) {
|
|
|
try {
|
|
|
- driver = new AndroidDriver(new URL("http://127.0.0.1:" + port + "/wd/hub"), capabilities);
|
|
|
+ driver = new AndroidDriver<>(new URL("http://127.0.0.1:" + port + "/wd/hub"), capabilities);
|
|
|
success = true;
|
|
|
} catch (MalformedURLException e1) {
|
|
|
writeExecErrorLog(e1);
|
|
@@ -451,14 +446,10 @@ public class CoverageTest extends Thread{
|
|
|
|
|
|
private static String getStackTrace(Throwable t){
|
|
|
StringWriter sw = new StringWriter();
|
|
|
- PrintWriter pw = new PrintWriter(sw);
|
|
|
- try{
|
|
|
+ try (PrintWriter pw = new PrintWriter(sw)) {
|
|
|
t.printStackTrace(pw);
|
|
|
return sw.toString();
|
|
|
}
|
|
|
- finally{
|
|
|
- pw.close();
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
public void endTest(){
|
|
@@ -466,6 +457,7 @@ public class CoverageTest extends Thread{
|
|
|
if (script != null){
|
|
|
script.endScript();
|
|
|
}
|
|
|
+ stopAppiumServer(this.port);
|
|
|
}
|
|
|
|
|
|
private void checkEndFlag(){
|