Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start WDA proxy if we need ios driver before test start #426

Merged
merged 4 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void runAppiumT2CTest(TestRunDevice testRunDevice, File jsonFile, Logger
reportLogger.info("Successfully init a Edge driver");
}
if (driverInfo.getPlatform().equalsIgnoreCase(DeviceType.IOS.name())) {
deviceInfo = getDeviceByType(testRunDevice, DeviceType.ANDROID.name());
deviceInfo = getDeviceByType(testRunDevice, DeviceType.IOS.name());
IOSDriverController iosDriverController = new IOSDriverController(
appiumServerManager.getIOSDriver(deviceInfo, reportLogger),
deviceInfo.getSerialNum(), reportLogger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public IOSDriver getIOSDriver(DeviceInfo deviceInfo, Logger logger) {
}

int wdaPort = IOSUtils.getWdaPortByUdid(udid, logger);
if (!IOSUtils.isWdaRunningByPort(wdaPort, logger)) {
IOSUtils.proxyWDA(deviceInfo, logger);
}

DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 4000);
Expand Down Expand Up @@ -274,6 +278,7 @@ public WindowsDriver getWindowsRootDriver(Logger logger) {

public Boolean isDriverAlive(AppiumDriver driver) {
try {
driver.getStatus();
driver.getScreenshotAs(OutputType.FILE);
return true;
} catch (WebDriverException e) {
Expand Down Expand Up @@ -393,6 +398,8 @@ public void quitIOSDriver(DeviceInfo deviceInfo, Logger logger) {
} catch (Exception e) {
logger.info("Error happened when quitting driver for device: " + udid);
e.printStackTrace();
} finally {
IOSUtils.killProxyWDA(deviceInfo, logger);
}
}
iOSDrivers.remove(udid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public boolean grantProjectionAndBatteryPermission(DeviceInfo deviceInfo, String

@Override
public void testDeviceSetup(DeviceInfo deviceInfo, Logger logger) {
IOSUtils.proxyWDA(deviceInfo, logger);

}

@Override
Expand All @@ -263,7 +263,7 @@ public void removeFileInDevice(DeviceInfo deviceInfo, String pathOnDevice, Logge

@Override
public void testDeviceUnset(DeviceInfo deviceInfo, Logger logger) {
IOSUtils.killProxyWDA(deviceInfo, logger);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private IOSPerfTestHelper() {
needUpdate = true;
} else {
String[] currentVersionParts = versionString.trim().split("\\.");
String[] lowestVersionParts = versionString.trim().split("\\.");
String[] lowestVersionParts = lowestVersion.trim().split("\\.");
for (int i = 0; i < currentVersionParts.length; i++) {
int currentPart = Integer.parseInt(currentVersionParts[i]);
int requiredPart = Integer.parseInt(lowestVersionParts[i]);
Expand Down Expand Up @@ -80,7 +80,7 @@ public void stop(String key) {

public static IOSPerfTestHelper getInstance() {
if (instance == null) {
synchronized (instance) {
synchronized (IOSPerfTestHelper.class) {
if (instance == null) {
instance = new IOSPerfTestHelper();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static String getAppList(String udid, Logger logger) {
}

public static void installApp(String udid, String packagePath, Logger logger) {
ShellUtils.execLocalCommand(String.format("tidevice -u %s install %s", udid, packagePath.replace(" ", "\\ ")), logger);
ShellUtils.execLocalCommand(String.format("tidevice -u %s install \"%s\"", udid, packagePath.replace(" ", "\\ ")), logger);
}

@Nullable
Expand All @@ -97,6 +97,9 @@ public static void stopApp(String udid, String packageName, Logger logger) {
public static void proxyWDA(DeviceInfo deviceInfo, Logger logger) {
String udid = deviceInfo.getSerialNum();
int wdaPort = getWdaPortByUdid(udid, logger);
if (isWdaRunningByPort(wdaPort, logger)) {
return;
}
// String command = "tidevice -u " + udid + " wdaproxy -B " + WDA_BUNDLE_ID + " --port " + getWdaPortByUdid(udid, logger);
String portRelayCommand = "tidevice -u " + udid + " relay " + wdaPort + " 8100";
String startWDACommand = "tidevice -u " + udid + " xctest --bundle_id " + WDA_BUNDLE_ID;
Expand All @@ -112,6 +115,7 @@ public static void killProxyWDA(DeviceInfo deviceInfo, Logger logger) {
String udid = deviceInfo.getSerialNum();
int wdaPort = getWdaPortByUdid(udid, logger);
// String command = "tidevice -u " + udid + " wdaproxy -B " + WDA_BUNDLE_ID + " --port " + getWdaPortByUdid(udid, logger);
// We can still try to kill the process even the proxy is not running.
String portRelayCommand = "tidevice -u " + udid + " relay " + wdaPort + " 8100";
String startWDACommand = "tidevice -u " + udid + " xctest --bundle_id " + WDA_BUNDLE_ID;

Expand All @@ -125,7 +129,7 @@ public static String getIOSDeviceDetailInfo(String udid, Logger logger) {
}

public static void takeScreenshot(String udid, String screenshotFilePath, Logger logger) {
ShellUtils.execLocalCommand("tidevice -u " + udid + " screenshot " + screenshotFilePath, logger);
ShellUtils.execLocalCommand("tidevice -u " + udid + " screenshot \"" + screenshotFilePath + "\"", logger);
}

public static boolean isWdaRunningByPort(int port, Logger logger) {
Expand Down
1 change: 1 addition & 0 deletions taps_to_cases/runner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ classes.finalizedBy checkstyleMain

dependencies {
compile project(":sdk")
compile project(":common")
implementation "com.google.guava:guava:30.1.1-jre"
// implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'org.jetbrains:annotations:21.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
package com.microsoft.hydralab.t2c.runner.controller;

import com.google.common.collect.ImmutableMap;
import com.microsoft.hydralab.common.util.IOSUtils;
import com.microsoft.hydralab.performance.PerformanceInspection;
import com.microsoft.hydralab.performance.PerformanceInspectionService;
import com.microsoft.hydralab.t2c.runner.T2CAppiumUtils;
import io.appium.java_client.appmanagement.ApplicationState;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
Expand All @@ -16,13 +16,15 @@
import org.openqa.selenium.interactions.PointerInput;
import org.openqa.selenium.interactions.Sequence;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.List;

public class IOSDriverController extends BaseDriverController {
private final IOSDriver iosDriver;
private String clipboardString;
private Logger logger = LoggerFactory.getLogger(getClass());

public IOSDriverController(IOSDriver iosDriver, String udid, Logger logger) {
super(iosDriver, udid, logger);
Expand All @@ -31,21 +33,12 @@ public IOSDriverController(IOSDriver iosDriver, String udid, Logger logger) {

@Override
public void activateApp(String appPackageName) {
if (iosDriver.isAppInstalled(appPackageName)) {
if (iosDriver.queryAppState(appPackageName) != ApplicationState.RUNNING_IN_FOREGROUND) {
iosDriver.activateApp(appPackageName);
}
} else {
throw new RuntimeException("the app " + appPackageName + " is not installed");
}
IOSUtils.launchApp(udid, appPackageName, logger);
}

@Override
public void terminateApp(String appPackageName) {
if (iosDriver.queryAppState(appPackageName) != ApplicationState.NOT_RUNNING &&
iosDriver.queryAppState(appPackageName) != ApplicationState.NOT_INSTALLED) {
iosDriver.terminateApp(appPackageName);
}
IOSUtils.stopApp(udid, appPackageName, logger);
}

@Override
Expand Down