Skip to content

Commit

Permalink
init driver in async (#772)
Browse files Browse the repository at this point in the history
* init driver in async

* fix server path

* downgrade webdrivermanager dependency

* set ios 14.0

* install WDA

* BS app path

* set unique derivedPath for better ios parallel

* fix checkstyle
  • Loading branch information
saikrishna321 committed Nov 12, 2020
1 parent 68ab21c commit 2a63c41
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 31 deletions.
2 changes: 1 addition & 1 deletion caps/browserstack.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"project": "ATD",
"app": {
"local": "https://github.com/shridharkalagi/AppiumSample/raw/master/VodQA.apk",
"cloud": "bs://640067fac4a9a8f88729c8555c6955c2e0ef3434"
"cloud": "bs://4539c04882cabb281498b531516352e0c6b3c11c"
},
"noSign": true
},
Expand Down
8 changes: 7 additions & 1 deletion caps/capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"clearSystemFiles": true,
"shouldUseSingletonTestManager": false,
"simpleIsVisibleCheck": true,
"wdaStartupRetries": 10,
"wdaStartupRetryInterval": 100,
"maxTypingFrequency": 10
},
"hostMachines": [
Expand All @@ -31,7 +33,11 @@
"simulators": [
{
"deviceName": "iPhone 11",
"OS": "13.5"
"OS": "14.0"
},
{
"deviceName": "iPhone 8",
"OS": "14.0"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.2.2</version>
<version>3.8.1</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.appium.capabilities;

import com.appium.entities.MobilePlatform;
import com.appium.filelocations.FileLocations;
import com.appium.ios.IOSDeviceConfiguration;
import com.appium.manager.AppiumDevice;
import com.appium.manager.AppiumDeviceManager;
Expand All @@ -18,6 +19,7 @@
import org.openqa.selenium.remote.DesiredCapabilities;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -153,6 +155,13 @@ private void desiredCapabilityForLocalAndRemoteATD(String platform,
"XCUITest");
desiredCapabilities.setCapability(MobileCapabilityType.UDID,
AppiumDeviceManager.getAppiumDevice().getDevice().getUdid());
File derivedDataPath = new File(System.getProperty("user.dir")
+ FileLocations.DERIVED_DATA
+ AppiumDeviceManager.getAppiumDevice().getDevice().getUdid());
if (!derivedDataPath.exists()) {
derivedDataPath.mkdirs();
}
desiredCapabilities.setCapability("derivedDataPath", derivedDataPath.getAbsolutePath());
}
desiredCapabilities.setCapability(MobileCapabilityType.UDID,
AppiumDeviceManager.getAppiumDevice().getDevice().getUdid());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/appium/filelocations/FileLocations.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface FileLocations {

String APPIUM_LOGS_DIRECTORY = OUTPUT_DIRECTORY + "appiumlogs/";
String ADB_LOGS_DIRECTORY = OUTPUT_DIRECTORY + "adblogs/";
String DERIVED_DATA = OUTPUT_DIRECTORY + "derivedData/";
}
55 changes: 27 additions & 28 deletions src/main/java/com/appium/manager/AppiumDriverManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.github.bonigarcia.wdm.WebDriverManager;
import lombok.Synchronized;
import org.apache.commons.lang3.ArrayUtils;
import org.openqa.selenium.remote.DesiredCapabilities;

Expand Down Expand Up @@ -42,43 +41,43 @@ protected static void setDriver(AppiumDriver driver) {
appiumDriver.set(driver);
}

@Synchronized

private AppiumDriver<MobileElement> initialiseDriver(
Optional<DesiredCapabilities> capabilities)
throws Exception {
Optional<DesiredCapabilities> capabilities)
throws Exception {
AppiumDriver currentDriverSession;
DesiredCapabilities desiredCapabilities = capabilities.get();
String isChromDriverPath = (String) desiredCapabilities.getCapability(
AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE);
AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE);
boolean isPlatformAndroid = AppiumDeviceManager.getMobilePlatform().name()
.equalsIgnoreCase("android");
.equalsIgnoreCase("android");
addChromeDriverPathIfChromeOnDevice(
desiredCapabilities,
isChromDriverPath,
isPlatformAndroid);
desiredCapabilities,
isChromDriverPath,
isPlatformAndroid);
LOGGER.info("Capabilities: " + desiredCapabilities.toString());
String remoteWDHubIP = getRemoteWDHubIP();
if (!AppiumDeviceManager.getAppiumDevice().getDevice().isCloud()
&& AppiumDeviceManager.getMobilePlatform().name().equalsIgnoreCase("iOS")) {
&& AppiumDeviceManager.getMobilePlatform().name().equalsIgnoreCase("iOS")) {
currentDriverSession = new IOSDriver(new URL(remoteWDHubIP),
desiredCapabilities);
desiredCapabilities);
LOGGER.info("Session Created for iOS ---- "
+ currentDriverSession.getSessionId() + "---"
+ currentDriverSession.getSessionDetail("udid"));
+ currentDriverSession.getSessionId() + "---"
+ currentDriverSession.getSessionDetail("udid"));
} else if (!AppiumDeviceManager.getAppiumDevice().getDevice().isCloud()
&& isPlatformAndroid) {
&& isPlatformAndroid) {
currentDriverSession = new AndroidDriver(new URL(remoteWDHubIP),
desiredCapabilities);
desiredCapabilities);
LOGGER.info("Session Created for Android ---- "
+ currentDriverSession.getSessionId() + "---"
+ currentDriverSession.getSessionDetail("udid"));
+ currentDriverSession.getSessionId() + "---"
+ currentDriverSession.getSessionDetail("udid"));
} else {
currentDriverSession = new AppiumDriver<>(new URL(remoteWDHubIP),
desiredCapabilities);
desiredCapabilities);
LOGGER.info("Session Created ---- "
+ currentDriverSession.getSessionId() + "---"
+ currentDriverSession.getRemoteAddress().getHost() + "---"
+ currentDriverSession.getSessionDetail("udid"));
+ currentDriverSession.getSessionId() + "---"
+ currentDriverSession.getRemoteAddress().getHost() + "---"
+ currentDriverSession.getSessionDetail("udid"));

}
return currentDriverSession;
Expand All @@ -92,8 +91,8 @@ private void addChromeDriverPathIfChromeOnDevice(DesiredCapabilities desiredCapa
String pathForChromDriverForDevice = getPathForChromeDriver(udid);
if (null != pathForChromDriverForDevice) {
desiredCapabilities.setCapability(
AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE,
pathForChromDriverForDevice);
AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE,
pathForChromDriverForDevice);
}
}
}
Expand All @@ -103,11 +102,11 @@ private String getPathForChromeDriver(String id) throws IOException {
if (versionNamesArr.length > 0) {
int highestChromeVersion = Arrays.stream(versionNamesArr).max().getAsInt();
String message = "ChromeDriver for Chrome version " + highestChromeVersion
+ " on device: " + id;
+ " on device: " + id;
LOGGER.info(message);
WebDriverManager.chromedriver()
.browserVersion(String.valueOf(highestChromeVersion)).setup();
return WebDriverManager.chromedriver().getDownloadedDriverVersion();
.version(String.valueOf(highestChromeVersion)).setup();
return WebDriverManager.chromedriver().getBinaryPath();
} else {
return null;
}
Expand All @@ -116,7 +115,7 @@ private String getPathForChromeDriver(String id) throws IOException {
private int[] getChromeVersionsFor(String id) throws IOException {
CommandPrompt cmd = new CommandPrompt();
String resultStdOut = cmd.runCommandThruProcess("adb -s " + id
+ " shell dumpsys package com.android.chrome | grep versionName");
+ " shell dumpsys package com.android.chrome | grep versionName");
int[] versionNamesArr = {};
if (resultStdOut.contains("versionName=")) {
String[] foundVersions = resultStdOut.split("\n");
Expand All @@ -138,7 +137,7 @@ private String getRemoteWDHubIP() throws Exception {
return appiumManager.getRemoteWDHubIP(hostName);
}

@Synchronized

private void startAppiumDriverInstance(Optional<DesiredCapabilities> desiredCapabilities)
throws Exception {
AppiumDriver<MobileElement> currentDriverSession;
Expand Down

0 comments on commit 2a63c41

Please sign in to comment.