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

Selenium 4 and Appium 2 Upgrade #360

Merged
merged 47 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
32a3ff3
(feat): Selenium 4 upgrade part 1
gayathri-testsigma Mar 7, 2023
03a43b6
TRD-217_upgrade
vikramvr20 Mar 7, 2023
b03c05d
Merge remote-tracking branch 'origin/TRD-217_upgrade' into selenium4
gayathri-testsigma Mar 7, 2023
db730c9
(feat): merge conflicts
gayathri-testsigma Mar 7, 2023
9c3ad06
Made changes wrt to appium java client 8
vikramvr20 Mar 7, 2023
defc58f
(feat): dependency updates
gayathri-testsigma Mar 14, 2023
a234597
fix merging capabailities
gayathri-testsigma Mar 14, 2023
7ad4771
(feat): selenium fixes
gayathri-testsigma Mar 21, 2023
2ab5966
feat: selenium 4 latest dependency
gayathri-testsigma Apr 5, 2023
61195a3
selenium 4 minor changes
gayathri-testsigma Apr 5, 2023
a07855f
Merge branch 'dev' into selenium4
gayathri-testsigma Apr 5, 2023
6482009
TRD-217
vikramvr20 Apr 24, 2023
ee23069
feat(Se4): fixes
gayathri-testsigma Apr 26, 2023
99552e1
TRD-217
vikramvr20 May 2, 2023
19eab55
fix(se4): remove hardcoded desired capability
gayathri-testsigma May 3, 2023
9f573a4
Merge branch 'selenium4' of https://github.com/testsigmahq/testsigma …
gayathri-testsigma May 3, 2023
c06fd97
fix(se4): address review comment
gayathri-testsigma May 4, 2023
09f1b45
TRD-217
vikramvr20 May 8, 2023
083eb0a
TRD-217
vikramvr20 May 8, 2023
bec7769
TRD-217
vikramvr20 May 9, 2023
942ae33
TRD-217
vikramvr20 May 16, 2023
a91f012
TRD-217
vikramvr20 May 16, 2023
052178a
TRD-217
vikramvr20 May 16, 2023
7aaf834
TRD-217
vikramvr20 May 18, 2023
4e52ce4
TRD-217
vikramvr20 May 19, 2023
6223dc4
TRD-217
vikramvr20 May 22, 2023
8be562e
TRD-217
vikramvr20 May 22, 2023
7f83678
TRD-217
vikramvr20 May 22, 2023
ca66b72
TRD-217
vikramvr20 May 23, 2023
e3883f6
(feat): private grid + se4 features
gayathri-testsigma May 25, 2023
334a08a
(feat): grid fixes
gayathri-testsigma May 26, 2023
42b88e0
fixes for grid
gayathri-testsigma May 26, 2023
ab37e02
(feat): Element level screenshot
gayathri-testsigma May 29, 2023
8c0dd8d
(feat): Driver Manager
gayathri-testsigma Jun 2, 2023
62dcbdd
TRD-217
vikramvr20 Jun 6, 2023
47a9d84
bug: name for edge browser is changed in grid4
gayathri-testsigma Jun 8, 2023
9779297
TRD-217
vikramvr20 Jun 9, 2023
6146b41
TRD-217
vikramvr20 Jun 13, 2023
374a7a1
TRD-217
vikramvr20 Jun 13, 2023
b1b94f6
chore: remove unused imports
gayathri-testsigma Jun 13, 2023
349fd98
Merge branch 'selenium4' of https://github.com/testsigmahq/testsigma …
gayathri-testsigma Jun 13, 2023
e8967b4
Merge branch 'dev' into selenium4
gayathri-testsigma Jun 13, 2023
d8ba1e4
chore: remove unused imports
gayathri-testsigma Jun 13, 2023
0732973
chore: code style fixes
gayathri-testsigma Jun 13, 2023
634f468
TRD-217
vikramvr20 Jun 13, 2023
bbe930a
Merge branch 'selenium4' of https://github.com/testsigmahq/testsigma …
vikramvr20 Jun 13, 2023
50889d9
bug: name key in desiredcap for local run
gayathri-testsigma Jun 13, 2023
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
2 changes: 1 addition & 1 deletion agent-launcher/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</plugins>
</build>
<properties>
<lombok.version>1.18.10</lombok.version>
<lombok.version>1.18.22</lombok.version>
<systemtray.version>3.17</systemtray.version>
<maven.compiler.plugin>3.8.1</maven.compiler.plugin>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion agent-launcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<maven.compiler.plugin>3.8.1</maven.compiler.plugin>
<commons.lang.version>3.4</commons.lang.version>
<systemtray.version>3.17</systemtray.version>
<lombok.version>1.18.10</lombok.version>
<lombok.version>1.18.22</lombok.version>
<httpcomponents.version>4.5.13</httpcomponents.version>
</properties>

Expand Down
10 changes: 9 additions & 1 deletion agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.plugin>3.8.1</maven.compiler.plugin>
<lombok.version>1.18.20</lombok.version>
<selenium.version>4.8.2</selenium.version>
<guava.version>31.1-jre</guava.version>
<lombok.version>1.18.22</lombok.version>
<mapstruct.version>1.4.2.Final</mapstruct.version>
<aws.version>1.11.46</aws.version>
<android.tools.version>25.3.0</android.tools.version>
Expand Down Expand Up @@ -139,6 +141,12 @@
<groupId>com.android.tools.ddms</groupId>
<artifactId>ddmlib</artifactId>
<version>${android.tools.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@Log4j2
public class TestsigmaAgent {
public static void main(String[] args) {
System.setProperty("webdriver.http.factory", "jdk-http-client");
String wrapperPort = System.getProperty("agent.wrapper.port");
if (StringUtils.isNotBlank(wrapperPort)) {
WrapperConnector.getInstance().disconnectHook();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.testsigma.agent.mappers.MobileDeviceMapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.testsigma.automator.AutomatorConfig;
import com.testsigma.automator.drivers.DriversUpdateService;
import com.testsigma.automator.entity.Browsers;
import com.testsigma.automator.entity.OsBrowserType;
import com.testsigma.automator.exceptions.AutomatorException;
Expand Down Expand Up @@ -97,7 +96,6 @@ public void syncBrowserDrivers(MobileDevice mobileDevice) {
Browsers browser = OsBrowserType.getBrowserType(browserType);
String driverPath = AutomatorConfig.getInstance().getAppBridge().getDriverExecutablePath(browser.getKey(),
browserVersion);
new DriversUpdateService().syncBrowserDriver(browserType, browserVersion, driverPath);
} catch (AutomatorException e) {
log.error(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,29 @@
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

@Log4j2
@Component
public class MobileAutomationServer {
private Process mobileAutomationServerProcess;
private File androidHome;
private File jreHome;

private File appiumHome;
private File mobileAutomationServerExecutablePath;
private File logFilePath;
private String serverIpAddress;
Expand All @@ -46,6 +56,10 @@ private File jreHome() {
return new File(PathUtil.getInstance().getJrePath());
}

private File appiumHome(){
return new File(PathUtil.getInstance().getMobileAutomationDriverPath());
}

private String serverIP() {
String address = "127.0.0.1";
try {
Expand All @@ -64,15 +78,16 @@ public void start() {
}
this.androidHome = androidHome();
this.jreHome = jreHome();
this.appiumHome = appiumHome();
this.mobileAutomationServerExecutablePath = new File(PathUtil.getInstance().getMobileAutomationServerPath(), "appium");
if (SystemUtils.IS_OS_WINDOWS) {
this.mobileAutomationServerExecutablePath = new File(PathUtil.getInstance().getMobileAutomationServerPath(), "appium.exe");
}
this.serverIpAddress = serverIP();
this.logFilePath = new File(PathUtil.getInstance().getLogsPath() + File.separator + "appium.log");
Integer serverPort = NetworkUtil.getFreePort();
this.serverURL = String.format("http://%s:%d/wd/hub", serverIpAddress, serverPort);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vikramvr20 we need to have Appium server also need to upgraded. jfyi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vikramvr20 Please confirm and do necessary changes..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PratheepV - Yes that's already been done and discussed the approach with Rajesh and Vikram.


this.serverURL = String.format("http://%s:%d", serverIpAddress, serverPort);
extractMobileAutomationDrivers();
log.info("Starting Mobile Automation Server at - " + serverURL);

(new Thread(() -> {
Expand All @@ -87,6 +102,7 @@ public void start() {
"--log-timestamp",
"--allow-insecure", "chromedriver_autodownload");
processBuilder.directory(new File(PathUtil.getInstance().getMobileAutomationServerPath()));
processBuilder.environment().put("APPIUM_HOME", appiumHome.getAbsolutePath());
processBuilder.environment().put("ANDROID_HOME", androidHome.getAbsolutePath());
processBuilder.environment().put("JAVA_HOME", jreHome.getAbsolutePath());
processBuilder.redirectErrorStream(true);
Expand All @@ -103,6 +119,81 @@ public void start() {
}
}

private void extractMobileAutomationDrivers(){
log.info("Trying to check if driver folder is present inside Appium directory");
try{
if (!isDriverFolderExists()) {
log.info("Driver folder does not exits.Extracting from the zip files");
File androidDriverLocalPath = Paths.get(PathUtil.getInstance().getMobileAutomationServerPath(), "appium-uiautomator2-driver.zip").toFile();
File iOsDriverLocalPath = Paths.get(PathUtil.getInstance().getMobileAutomationServerPath(), "appium-xcuitest-driver.zip").toFile();
File destinationPath = new File(PathUtil.getInstance().getMobileAutomationDriverDestinationPath());
ExecutorService executor = Executors.newFixedThreadPool(2);
Future<?> unzipAndroidDriver = executor.submit(() -> {
try {
unzipDriver(androidDriverLocalPath,destinationPath);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
Future<?> unzipIosDriver = executor.submit(() -> {
try {
unzipDriver(iOsDriverLocalPath,destinationPath);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
try {
// Wait for the tasks to complete within the timeout duration
int timeoutSeconds = 120;
unzipAndroidDriver.get(timeoutSeconds, TimeUnit.SECONDS);
unzipIosDriver.get(timeoutSeconds, TimeUnit.SECONDS);
log.info("Unzip completed successfully");
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
executor.shutdown();
}
}
} catch (Exception e){
log.error(e.getMessage(), e);
}
}

private boolean isDriverFolderExists() {
String dirPath = appiumHome.getAbsolutePath();
log.info("Verifying if driver folder exists: " + dirPath);
File driverDirectoryFile = new File(dirPath);
if (driverDirectoryFile.exists()) {
File driverFile = new File(driverDirectoryFile.getAbsolutePath());
return driverFile.exists() && driverFile.isDirectory();
}
return false;
}

private void unzipDriver(File sourcePath,File destinationPath) throws IOException {
File fileZip = new File(String.valueOf(sourcePath));
File destDir = new File(String.valueOf(destinationPath));

try (ZipFile zipFile = new ZipFile(fileZip)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();

while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
String entryName = entry.getName();
// to skip creating the "_MACOSX" directory
if (!entryName.startsWith("__MACOSX")) {
File entryFile = new File(destDir, entryName);
Files.createDirectories(entryFile.getParentFile().toPath());
Files.copy(zipFile.getInputStream(entry), entryFile.toPath());
}
}
}
} catch (Exception e) {
log.error(e.getMessage(),e);
}
}

@PreDestroy
public void stop() {
log.info("Stopping Mobile Automation Server...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class AndroidMobileAutomationServer {
private final DeviceContainer deviceContainer;
private final CommandExecutor commandExecutor;

private final String UI_AUTOMATOR2_SERVER_TEST_APK = "appium-uiautomator2-server-test.apk";
private final String UI_AUTOMATOR2_SERVER_APK = "appium-uiautomator2-server.apk";
private final String UI_AUTOMATOR2_SERVER_TEST_APK = "appium-uiautomator2-server-debug-androidTest.apk";
private final String UI_AUTOMATOR2_SERVER_APK = "appium-uiautomator2-server-v5.8.2.apk";
private final String APPIUM_SETTINGS_APK = "settings_apk-debug.apk";
private final String UI_AUTOMATOR2_PACKAGE = "io.appium.uiautomator2.server";
private final String UI_AUTOMATOR2_TEST_PACKAGE = "io.appium.uiautomator2.server.test";
Expand All @@ -38,7 +38,6 @@ public void installDrivers(String uniqueId) throws MobileLibraryInstallException
try {
MobileDevice mobileDevice = deviceContainer.getDevice(uniqueId);
IDevice device = mobileDevice.getIDevice();

this.installAppiumSettings(device);
this.startAppiumSettings(device);
this.installUIAutomatorServer(device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void createSession(String uniqueId) throws MobileAutomationServerSessionE
desiredCapabilities.setCapability("xcodeOrgId", "6F4CKCA4LX");
desiredCapabilities.setCapability("xcodeSigningId", "iPhone Developer");
desiredCapabilities.setCapability("app", "/Users/vikram/ios-apps/ios-test-app/build/Release-iphoneos/TestApp-iphoneos.app");
device.setRemoteWebDriver(new IOSDriver<>(new URL(mobileAutomationServerService.getMobileAutomationServer().getServerURL()),
device.setRemoteWebDriver(new IOSDriver(new URL(mobileAutomationServerService.getMobileAutomationServer().getServerURL()),
desiredCapabilities));
} catch (Exception e) {
throw new MobileAutomationServerSessionException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void startWdaOnDevice(MobileDevice device) throws TestsigmaException {

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

private void checkWDARelayProcessStatus(MobileDevice device) throws TestsigmaException, AutomatorException, InterruptedException {
int retries = 3;
while (device.getWdaRelayProcess() == null && !device.getWdaRelayProcess().isAlive() && retries-- > 0) {
while (device.getWdaRelayProcess() == null && retries-- > 0) {
log.info("WDA process not started yet, waiting for 5 seconds...");
Thread.sleep(5000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,40 +136,22 @@ private void setRemoteServerURL(TestsigmaDriver testsigmaDriver, DriverSessionRe
}

private void handleLocalDevice(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)
throws TestsigmaException, AutomatorException {
throws TestsigmaException, AutomatorException {
if (driverSessionRequest.getExecutionLabType().equals(ExecutionLabType.Hybrid)) {
appendChromeDriverExecutable(caps, driverSessionRequest);
if (driverSessionRequest.getWorkspaceType() == WorkspaceType.IOSNative) {
setupIosDevice(caps, driverSessionRequest);
}
}
}

private void appendChromeDriverExecutable(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)
throws TestsigmaException {
MobileDevice device = deviceContainer.getDevice(driverSessionRequest.getUniqueId());
if (device.getBrowserList() != null && device.getBrowserList().size() > 0) {
AgentBrowser browser = device.getBrowserList().get(0);
File chromePath = driverExecutableExists(Browsers.GoogleChrome.getKey(),
browser.getMajorVersion() + "");
if (chromePath != null) {
WebDriverCapability cap = new WebDriverCapability(TSCapabilityType.CHROME_DRIVER_EXECUTABLE, chromePath.getAbsolutePath());
caps.add(cap);
} else {
log.warn("Chrome Driver is not yet downloaded.. please try after some time");
}
}
}

public void setupIosDevice(List<WebDriverCapability> caps, DriverSessionRequest driverSessionRequest)
throws TestsigmaException, AutomatorException {
throws TestsigmaException, AutomatorException {
MobileDevice device = deviceContainer.getDevice(driverSessionRequest.getUniqueId());
iosDeviceService.setupWda(device);
WebDriverCapability bundleIdCapability = caps.stream().filter(cap -> cap.getCapabilityName()
.equals(TSCapabilityType.BUNDLE_ID)).findFirst().orElse(null);
.equals(TSCapabilityType.BUNDLE_ID)).findFirst().orElse(null);
if ((bundleIdCapability == null) || StringUtils.isBlank((String) bundleIdCapability.getCapabilityValue())) {
WebDriverCapability appCapability = caps.stream().filter(cap -> cap.getCapabilityName()
.equals(MobileCapabilityType.APP)).findFirst().orElse(null);
.equals(MobileCapabilityType.APP)).findFirst().orElse(null);
AppPathType appPathType = driverSessionRequest.getApplicationPathType();
if ((appCapability != null) && appPathType != AppPathType.APP_DETAILS) {
caps.remove(appCapability);
Expand Down
6 changes: 6 additions & 0 deletions agent/src/main/java/com/testsigma/agent/utils/PathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class PathUtil {
@Getter
private String mobileAutomationServerPath = null;
@Getter
private String mobileAutomationDriverPath = null;
@Getter
private String mobileAutomationDriverDestinationPath = null;
@Getter
private String upgradePath = null;
@Getter
private String rootPath = null;
Expand Down Expand Up @@ -79,6 +83,8 @@ public void setPathsFromContext(boolean reset) {
driversPath = rootPath + File.separator + "drivers";
jrePath = rootPath + File.separator + "jre";
mobileAutomationServerPath = rootPath + File.separator + "appium";
mobileAutomationDriverPath = mobileAutomationServerPath + File.separator +"drivers";
mobileAutomationDriverDestinationPath = mobileAutomationDriverPath + File.separator + "node_modules";
androidPath = rootPath + File.separator + "android";
iosPath = rootPath + File.separator + "ios";

Expand Down
2 changes: 1 addition & 1 deletion agent/src/main/resources/agent.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
cloud.url=${CLOUD_URL:https://local.testsigmaos.com}
local.server.url=${LOCAL_SERVER_URL:http://localhost:9090}
local.agent.register=${LOCAL_AGENT_REGISTER:true}
agent.version=2.9.1
agent.version=3.0.0
Loading