Skip to content

Commit 842c2b8

Browse files
authored
Merge pull request #360 from testsigmahq/selenium4
Selenium 4 and Appium 2 Upgrade
2 parents df5070f + 50889d9 commit 842c2b8

File tree

155 files changed

+1551
-630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+1551
-630
lines changed

agent-launcher/dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
</plugins>
5858
</build>
5959
<properties>
60-
<lombok.version>1.18.10</lombok.version>
60+
<lombok.version>1.18.22</lombok.version>
6161
<systemtray.version>3.17</systemtray.version>
6262
<maven.compiler.plugin>3.8.1</maven.compiler.plugin>
6363
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

agent-launcher/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<maven.compiler.plugin>3.8.1</maven.compiler.plugin>
1414
<commons.lang.version>3.4</commons.lang.version>
1515
<systemtray.version>3.17</systemtray.version>
16-
<lombok.version>1.18.10</lombok.version>
16+
<lombok.version>1.18.22</lombok.version>
1717
<httpcomponents.version>4.5.13</httpcomponents.version>
1818
</properties>
1919

agent/pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
<maven.compiler.source>11</maven.compiler.source>
2121
<maven.compiler.target>11</maven.compiler.target>
2222
<maven.compiler.plugin>3.8.1</maven.compiler.plugin>
23-
<lombok.version>1.18.20</lombok.version>
23+
<selenium.version>4.8.2</selenium.version>
24+
<guava.version>31.1-jre</guava.version>
25+
<lombok.version>1.18.22</lombok.version>
2426
<mapstruct.version>1.4.2.Final</mapstruct.version>
2527
<aws.version>1.11.46</aws.version>
2628
<android.tools.version>25.3.0</android.tools.version>
@@ -139,6 +141,12 @@
139141
<groupId>com.android.tools.ddms</groupId>
140142
<artifactId>ddmlib</artifactId>
141143
<version>${android.tools.version}</version>
144+
<exclusions>
145+
<exclusion>
146+
<groupId>com.google.guava</groupId>
147+
<artifactId>guava</artifactId>
148+
</exclusion>
149+
</exclusions>
142150
</dependency>
143151

144152
<dependency>

agent/src/main/java/com/testsigma/agent/TestsigmaAgent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
@Log4j2
2525
public class TestsigmaAgent {
2626
public static void main(String[] args) {
27+
System.setProperty("webdriver.http.factory", "jdk-http-client");
2728
String wrapperPort = System.getProperty("agent.wrapper.port");
2829
if (StringUtils.isNotBlank(wrapperPort)) {
2930
WrapperConnector.getInstance().disconnectHook();

agent/src/main/java/com/testsigma/agent/mobile/DeviceContainer.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.testsigma.agent.mappers.MobileDeviceMapper;
2020
import com.fasterxml.jackson.core.type.TypeReference;
2121
import com.testsigma.automator.AutomatorConfig;
22-
import com.testsigma.automator.drivers.DriversUpdateService;
2322
import com.testsigma.automator.entity.Browsers;
2423
import com.testsigma.automator.entity.OsBrowserType;
2524
import com.testsigma.automator.exceptions.AutomatorException;
@@ -97,7 +96,6 @@ public void syncBrowserDrivers(MobileDevice mobileDevice) {
9796
Browsers browser = OsBrowserType.getBrowserType(browserType);
9897
String driverPath = AutomatorConfig.getInstance().getAppBridge().getDriverExecutablePath(browser.getKey(),
9998
browserVersion);
100-
new DriversUpdateService().syncBrowserDriver(browserType, browserVersion, driverPath);
10199
} catch (AutomatorException e) {
102100
log.error(e.getMessage(), e);
103101
}

agent/src/main/java/com/testsigma/agent/mobile/MobileAutomationServer.java

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,29 @@
1616
import lombok.extern.log4j.Log4j2;
1717
import org.apache.commons.lang3.SystemUtils;
1818
import org.springframework.stereotype.Component;
19-
2019
import javax.annotation.PreDestroy;
2120
import java.io.File;
2221
import java.io.IOException;
2322
import java.net.InetAddress;
2423
import java.net.UnknownHostException;
24+
import java.nio.file.Files;
25+
import java.nio.file.Paths;
26+
import java.util.Enumeration;
27+
import java.util.concurrent.ExecutorService;
28+
import java.util.concurrent.Executors;
29+
import java.util.concurrent.Future;
30+
import java.util.concurrent.TimeUnit;
31+
import java.util.zip.ZipEntry;
32+
import java.util.zip.ZipFile;
2533

2634
@Log4j2
2735
@Component
2836
public class MobileAutomationServer {
2937
private Process mobileAutomationServerProcess;
3038
private File androidHome;
3139
private File jreHome;
40+
41+
private File appiumHome;
3242
private File mobileAutomationServerExecutablePath;
3343
private File logFilePath;
3444
private String serverIpAddress;
@@ -46,6 +56,10 @@ private File jreHome() {
4656
return new File(PathUtil.getInstance().getJrePath());
4757
}
4858

59+
private File appiumHome(){
60+
return new File(PathUtil.getInstance().getMobileAutomationDriverPath());
61+
}
62+
4963
private String serverIP() {
5064
String address = "127.0.0.1";
5165
try {
@@ -64,15 +78,16 @@ public void start() {
6478
}
6579
this.androidHome = androidHome();
6680
this.jreHome = jreHome();
81+
this.appiumHome = appiumHome();
6782
this.mobileAutomationServerExecutablePath = new File(PathUtil.getInstance().getMobileAutomationServerPath(), "appium");
6883
if (SystemUtils.IS_OS_WINDOWS) {
6984
this.mobileAutomationServerExecutablePath = new File(PathUtil.getInstance().getMobileAutomationServerPath(), "appium.exe");
7085
}
7186
this.serverIpAddress = serverIP();
7287
this.logFilePath = new File(PathUtil.getInstance().getLogsPath() + File.separator + "appium.log");
7388
Integer serverPort = NetworkUtil.getFreePort();
74-
this.serverURL = String.format("http://%s:%d/wd/hub", serverIpAddress, serverPort);
75-
89+
this.serverURL = String.format("http://%s:%d", serverIpAddress, serverPort);
90+
extractMobileAutomationDrivers();
7691
log.info("Starting Mobile Automation Server at - " + serverURL);
7792

7893
(new Thread(() -> {
@@ -87,6 +102,7 @@ public void start() {
87102
"--log-timestamp",
88103
"--allow-insecure", "chromedriver_autodownload");
89104
processBuilder.directory(new File(PathUtil.getInstance().getMobileAutomationServerPath()));
105+
processBuilder.environment().put("APPIUM_HOME", appiumHome.getAbsolutePath());
90106
processBuilder.environment().put("ANDROID_HOME", androidHome.getAbsolutePath());
91107
processBuilder.environment().put("JAVA_HOME", jreHome.getAbsolutePath());
92108
processBuilder.redirectErrorStream(true);
@@ -103,6 +119,81 @@ public void start() {
103119
}
104120
}
105121

122+
private void extractMobileAutomationDrivers(){
123+
log.info("Trying to check if driver folder is present inside Appium directory");
124+
try{
125+
if (!isDriverFolderExists()) {
126+
log.info("Driver folder does not exits.Extracting from the zip files");
127+
File androidDriverLocalPath = Paths.get(PathUtil.getInstance().getMobileAutomationServerPath(), "appium-uiautomator2-driver.zip").toFile();
128+
File iOsDriverLocalPath = Paths.get(PathUtil.getInstance().getMobileAutomationServerPath(), "appium-xcuitest-driver.zip").toFile();
129+
File destinationPath = new File(PathUtil.getInstance().getMobileAutomationDriverDestinationPath());
130+
ExecutorService executor = Executors.newFixedThreadPool(2);
131+
Future<?> unzipAndroidDriver = executor.submit(() -> {
132+
try {
133+
unzipDriver(androidDriverLocalPath,destinationPath);
134+
} catch (Exception e) {
135+
log.error(e.getMessage(), e);
136+
}
137+
});
138+
Future<?> unzipIosDriver = executor.submit(() -> {
139+
try {
140+
unzipDriver(iOsDriverLocalPath,destinationPath);
141+
} catch (Exception e) {
142+
log.error(e.getMessage(), e);
143+
}
144+
});
145+
try {
146+
// Wait for the tasks to complete within the timeout duration
147+
int timeoutSeconds = 120;
148+
unzipAndroidDriver.get(timeoutSeconds, TimeUnit.SECONDS);
149+
unzipIosDriver.get(timeoutSeconds, TimeUnit.SECONDS);
150+
log.info("Unzip completed successfully");
151+
} catch (Exception e) {
152+
log.error(e.getMessage(), e);
153+
} finally {
154+
executor.shutdown();
155+
}
156+
}
157+
} catch (Exception e){
158+
log.error(e.getMessage(), e);
159+
}
160+
}
161+
162+
private boolean isDriverFolderExists() {
163+
String dirPath = appiumHome.getAbsolutePath();
164+
log.info("Verifying if driver folder exists: " + dirPath);
165+
File driverDirectoryFile = new File(dirPath);
166+
if (driverDirectoryFile.exists()) {
167+
File driverFile = new File(driverDirectoryFile.getAbsolutePath());
168+
return driverFile.exists() && driverFile.isDirectory();
169+
}
170+
return false;
171+
}
172+
173+
private void unzipDriver(File sourcePath,File destinationPath) throws IOException {
174+
File fileZip = new File(String.valueOf(sourcePath));
175+
File destDir = new File(String.valueOf(destinationPath));
176+
177+
try (ZipFile zipFile = new ZipFile(fileZip)) {
178+
Enumeration<? extends ZipEntry> entries = zipFile.entries();
179+
180+
while (entries.hasMoreElements()) {
181+
ZipEntry entry = entries.nextElement();
182+
if (!entry.isDirectory()) {
183+
String entryName = entry.getName();
184+
// to skip creating the "_MACOSX" directory
185+
if (!entryName.startsWith("__MACOSX")) {
186+
File entryFile = new File(destDir, entryName);
187+
Files.createDirectories(entryFile.getParentFile().toPath());
188+
Files.copy(zipFile.getInputStream(entry), entryFile.toPath());
189+
}
190+
}
191+
}
192+
} catch (Exception e) {
193+
log.error(e.getMessage(),e);
194+
}
195+
}
196+
106197
@PreDestroy
107198
public void stop() {
108199
log.info("Stopping Mobile Automation Server...");

agent/src/main/java/com/testsigma/agent/mobile/android/AndroidMobileAutomationServer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public class AndroidMobileAutomationServer {
2727
private final DeviceContainer deviceContainer;
2828
private final CommandExecutor commandExecutor;
2929

30-
private final String UI_AUTOMATOR2_SERVER_TEST_APK = "appium-uiautomator2-server-test.apk";
31-
private final String UI_AUTOMATOR2_SERVER_APK = "appium-uiautomator2-server.apk";
30+
private final String UI_AUTOMATOR2_SERVER_TEST_APK = "appium-uiautomator2-server-debug-androidTest.apk";
31+
private final String UI_AUTOMATOR2_SERVER_APK = "appium-uiautomator2-server-v5.8.2.apk";
3232
private final String APPIUM_SETTINGS_APK = "settings_apk-debug.apk";
3333
private final String UI_AUTOMATOR2_PACKAGE = "io.appium.uiautomator2.server";
3434
private final String UI_AUTOMATOR2_TEST_PACKAGE = "io.appium.uiautomator2.server.test";
@@ -38,7 +38,6 @@ public void installDrivers(String uniqueId) throws MobileLibraryInstallException
3838
try {
3939
MobileDevice mobileDevice = deviceContainer.getDevice(uniqueId);
4040
IDevice device = mobileDevice.getIDevice();
41-
4241
this.installAppiumSettings(device);
4342
this.startAppiumSettings(device);
4443
this.installUIAutomatorServer(device);

agent/src/main/java/com/testsigma/agent/mobile/ios/IosMobileAutomationServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void createSession(String uniqueId) throws MobileAutomationServerSessionE
5858
desiredCapabilities.setCapability("xcodeOrgId", "6F4CKCA4LX");
5959
desiredCapabilities.setCapability("xcodeSigningId", "iPhone Developer");
6060
desiredCapabilities.setCapability("app", "/Users/vikram/ios-apps/ios-test-app/build/Release-iphoneos/TestApp-iphoneos.app");
61-
device.setRemoteWebDriver(new IOSDriver<>(new URL(mobileAutomationServerService.getMobileAutomationServer().getServerURL()),
61+
device.setRemoteWebDriver(new IOSDriver(new URL(mobileAutomationServerService.getMobileAutomationServer().getServerURL()),
6262
desiredCapabilities));
6363
} catch (Exception e) {
6464
throw new MobileAutomationServerSessionException(e.getMessage());

agent/src/main/java/com/testsigma/agent/mobile/ios/WdaService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void startWdaOnDevice(MobileDevice device) throws TestsigmaException {
145145

146146
private void checkWDAProcessStatus(MobileDevice device) throws TestsigmaException, AutomatorException, InterruptedException {
147147
int retries = 3;
148-
while (device.getWdaProcess() == null && (device.getWdaProcess().isAlive() || device.getWdaProcess().exitValue() == 0) && retries-- > 0) {
148+
while (device.getWdaProcess() == null && retries-- > 0) {
149149
log.info("WDA process not started yet, waiting for 5 seconds...");
150150
Thread.sleep(5000);
151151
}
@@ -161,7 +161,7 @@ private void checkWDAProcessStatus(MobileDevice device) throws TestsigmaExceptio
161161

162162
private void checkWDARelayProcessStatus(MobileDevice device) throws TestsigmaException, AutomatorException, InterruptedException {
163163
int retries = 3;
164-
while (device.getWdaRelayProcess() == null && !device.getWdaRelayProcess().isAlive() && retries-- > 0) {
164+
while (device.getWdaRelayProcess() == null && retries-- > 0) {
165165
log.info("WDA process not started yet, waiting for 5 seconds...");
166166
Thread.sleep(5000);
167167
}

agent/src/main/java/com/testsigma/agent/services/DriverSessionsService.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,40 +136,22 @@ private void setRemoteServerURL(TestsigmaDriver testsigmaDriver, DriverSessionRe
136136
}
137137

138138
private void handleLocalDevice(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)
139-
throws TestsigmaException, AutomatorException {
139+
throws TestsigmaException, AutomatorException {
140140
if (driverSessionRequest.getExecutionLabType().equals(ExecutionLabType.Hybrid)) {
141-
appendChromeDriverExecutable(caps, driverSessionRequest);
142141
if (driverSessionRequest.getWorkspaceType() == WorkspaceType.IOSNative) {
143142
setupIosDevice(caps, driverSessionRequest);
144143
}
145144
}
146145
}
147-
148-
private void appendChromeDriverExecutable(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)
149-
throws TestsigmaException {
150-
MobileDevice device = deviceContainer.getDevice(driverSessionRequest.getUniqueId());
151-
if (device.getBrowserList() != null && device.getBrowserList().size() > 0) {
152-
AgentBrowser browser = device.getBrowserList().get(0);
153-
File chromePath = driverExecutableExists(Browsers.GoogleChrome.getKey(),
154-
browser.getMajorVersion() + "");
155-
if (chromePath != null) {
156-
WebDriverCapability cap = new WebDriverCapability(TSCapabilityType.CHROME_DRIVER_EXECUTABLE, chromePath.getAbsolutePath());
157-
caps.add(cap);
158-
} else {
159-
log.warn("Chrome Driver is not yet downloaded.. please try after some time");
160-
}
161-
}
162-
}
163-
164146
public void setupIosDevice(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)
165-
throws TestsigmaException, AutomatorException {
147+
throws TestsigmaException, AutomatorException {
166148
MobileDevice device = deviceContainer.getDevice(driverSessionRequest.getUniqueId());
167149
iosDeviceService.setupWda(device);
168150
WebDriverCapability bundleIdCapability = caps.stream().filter(cap -> cap.getCapabilityName()
169-
.equals(TSCapabilityType.BUNDLE_ID)).findFirst().orElse(null);
151+
.equals(TSCapabilityType.BUNDLE_ID)).findFirst().orElse(null);
170152
if ((bundleIdCapability == null) || StringUtils.isBlank((String) bundleIdCapability.getCapabilityValue())) {
171153
WebDriverCapability appCapability = caps.stream().filter(cap -> cap.getCapabilityName()
172-
.equals(MobileCapabilityType.APP)).findFirst().orElse(null);
154+
.equals(MobileCapabilityType.APP)).findFirst().orElse(null);
173155
AppPathType appPathType = driverSessionRequest.getApplicationPathType();
174156
if ((appCapability != null) && appPathType != AppPathType.APP_DETAILS) {
175157
caps.remove(appCapability);

0 commit comments

Comments
 (0)