Skip to content

Commit

Permalink
Merge branch 'main' into AllureReportHotFix
Browse files Browse the repository at this point in the history
  • Loading branch information
MustafaAgamy authored Feb 22, 2024
2 parents be1538d + e34272b commit 9ccb50b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 128 deletions.
8 changes: 0 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ updates:
interval: "daily"
time: "00:00"
timezone: "Africa/Cairo"
groups:
dev-dependencies:
patterns:
- "*"

# Maintain dependencies for maven
- package-ecosystem: "maven"
Expand All @@ -20,7 +16,3 @@ updates:
interval: "daily"
time: "00:00"
timezone: "Africa/Cairo"
groups:
dev-dependencies:
patterns:
- "*"
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-all-deps</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
Expand Down
92 changes: 7 additions & 85 deletions src/main/java/com/shaft/driver/DriverFactory.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.shaft.driver;

import com.shaft.api.BrowserStack;
import com.shaft.api.LambdaTest;
import com.shaft.api.RestActions;
import com.shaft.cli.TerminalActions;
import com.shaft.db.DatabaseActions;
import com.shaft.db.DatabaseActions.DatabaseType;
import com.shaft.driver.internal.DriverFactory.BrowserStackHelper;
import com.shaft.driver.internal.DriverFactory.DriverFactoryHelper;
import com.shaft.driver.internal.DriverFactory.LambdaTestHelper;
import com.shaft.listeners.TestNGListener;
import com.shaft.listeners.internal.TestNGListenerHelper;
import com.shaft.tools.io.internal.ProjectStructureManager;
Expand Down Expand Up @@ -55,74 +55,6 @@ public static void reloadProperties() {
}
}

/**
* Creates a new Selenium WebDriver instance using BrowserStack, use this to test Native Mobile apps over BrowserStack
*
* @param browserStackOptions custom browserstack options to be merged with the default in the browserStack.properties file
* @return a new Selenium WebDriver instance using BrowserStack
*/
private static DriverFactoryHelper getBrowserStackDriver(MutableCapabilities browserStackOptions) {
String appUrl = SHAFT.Properties.browserStack.appUrl();
var helper = new DriverFactoryHelper();
if ("".equals(appUrl)) {
// new native app OR web execution
if ("".equals(SHAFT.Properties.browserStack.appRelativeFilePath())) {
// this means it's a web execution (desktop or mobile)
if (DriverFactoryHelper.isMobileWebExecution()) {
browserStackOptions = BrowserStack.setupMobileWebExecution().merge(browserStackOptions);
} else {
// desktop web
browserStackOptions = BrowserStack.setupDesktopWebExecution().merge(browserStackOptions);
}
helper.initializeDriver(browserStackOptions);
} else {
// this is the new native app scenario
browserStackOptions = BrowserStack.setupNativeAppExecution(SHAFT.Properties.browserStack.username(), SHAFT.Properties.browserStack.accessKey(),
SHAFT.Properties.browserStack.deviceName(), SHAFT.Properties.browserStack.platformVersion(), SHAFT.Properties.browserStack.appRelativeFilePath(), SHAFT.Properties.browserStack.appName()).merge(browserStackOptions);
helper.initializeDriver(DriverType.APPIUM_MOBILE_NATIVE, browserStackOptions);
}
} else {
// this is the existing version from a native app scenario
browserStackOptions = BrowserStack.setupNativeAppExecution(SHAFT.Properties.browserStack.username(), SHAFT.Properties.browserStack.accessKey(),
SHAFT.Properties.browserStack.deviceName(), SHAFT.Properties.browserStack.platformVersion(), appUrl).merge(browserStackOptions);
helper.initializeDriver(DriverType.APPIUM_MOBILE_NATIVE, browserStackOptions);
}
return helper;
}

/**
* Creates a new Selenium WebDriver instance using lambdaTest, use this to test Native Mobile apps over lambdaTest
*
* @param lambdaTestOptions custom lambdaTest options to be merged with the default in the lambdaTest.properties file
* @return a new Selenium WebDriver instance using lambdaTest
*/
private static DriverFactoryHelper getLambdaTestDriver(MutableCapabilities lambdaTestOptions) {
String appUrl = SHAFT.Properties.lambdaTest.appUrl();
var helper = new DriverFactoryHelper();
if ("".equals(appUrl)) {
// new native app OR web execution
if ("".equals(SHAFT.Properties.lambdaTest.appRelativeFilePath())) {
// this means it's a web execution (desktop or mobile)
if (DriverFactoryHelper.isMobileWebExecution()) {
lambdaTestOptions = LambdaTest.setupMobileWebExecution().merge(lambdaTestOptions);
} else {
// desktop web
lambdaTestOptions = LambdaTest.setupDesktopWebExecution().merge(lambdaTestOptions);
}
helper.initializeDriver(lambdaTestOptions);
} else {
// this is the new native app scenario
lambdaTestOptions = LambdaTest.setupNativeAppExecution(SHAFT.Properties.lambdaTest.username(), SHAFT.Properties.lambdaTest.accessKey(), SHAFT.Properties.lambdaTest.deviceName(), SHAFT.Properties.lambdaTest.platformVersion(), SHAFT.Properties.lambdaTest.appRelativeFilePath(), SHAFT.Properties.lambdaTest.appName()).merge(lambdaTestOptions);
helper.initializeDriver(DriverType.APPIUM_MOBILE_NATIVE, lambdaTestOptions);
}
} else {
// this is the existing version from a native app scenario
lambdaTestOptions = LambdaTest.setupNativeAppExecution(SHAFT.Properties.lambdaTest.username(), SHAFT.Properties.lambdaTest.accessKey(), SHAFT.Properties.lambdaTest.deviceName(), SHAFT.Properties.lambdaTest.platformVersion(), appUrl).merge(lambdaTestOptions);
helper.initializeDriver(DriverType.APPIUM_MOBILE_NATIVE, lambdaTestOptions);
}
return helper;
}

/**
* Creates a new API instance to facilitate using the Rest Actions Library
*
Expand Down Expand Up @@ -169,10 +101,9 @@ public DriverFactoryHelper getHelper() {
if (helper == null) {
readLastMinuteUpdatedProperties();
if (SHAFT.Properties.platform.executionAddress().toLowerCase().contains("browserstack")) {
return getBrowserStackDriver(new MutableCapabilities());
return getHelper(DriverType.BROWSERSTACK, new MutableCapabilities());
} else if (SHAFT.Properties.platform.executionAddress().toLowerCase().contains("lambdatest")) {
return getLambdaTestDriver(new MutableCapabilities());

return getHelper(DriverType.LAMBDATEST, new MutableCapabilities());
} else {
var helper = new DriverFactoryHelper();
helper.initializeDriver();
Expand All @@ -193,16 +124,7 @@ public WebDriver getDriver() {
* @return a new Selenium WebDriver instance
*/
public DriverFactoryHelper getHelper(DriverType driverType) {
readLastMinuteUpdatedProperties();
if (driverType.equals(DriverType.BROWSERSTACK)) {
return getBrowserStackDriver(new MutableCapabilities());
} else if (driverType.equals(DriverType.LAMBDATEST)) {
return getLambdaTestDriver(new MutableCapabilities());
} else {
var helper = new DriverFactoryHelper();
helper.initializeDriver(driverType);
return helper;
}
return getHelper(driverType, new MutableCapabilities());
}

/**
Expand All @@ -215,9 +137,9 @@ public DriverFactoryHelper getHelper(DriverType driverType) {
public DriverFactoryHelper getHelper(DriverType driverType, MutableCapabilities customDriverOptions) {
readLastMinuteUpdatedProperties();
if (driverType.equals(DriverType.BROWSERSTACK)) {
return getBrowserStackDriver(customDriverOptions);
return BrowserStackHelper.getBrowserStackDriver(customDriverOptions);
} else if (driverType.equals(DriverType.LAMBDATEST)) {
return getLambdaTestDriver(customDriverOptions);
return LambdaTestHelper.getLambdaTestDriver(customDriverOptions);
} else {
var helper = new DriverFactoryHelper();
helper.initializeDriver(driverType, customDriverOptions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.shaft.api;
package com.shaft.driver.internal.DriverFactory;

import com.shaft.api.RequestBuilder;
import com.shaft.api.RestActions;
import com.shaft.cli.FileActions;
import com.shaft.driver.DriverFactory;
import com.shaft.driver.SHAFT;
import com.shaft.tools.io.ReportManager;
import com.shaft.tools.io.internal.FailureReporter;
Expand All @@ -12,14 +15,44 @@
import java.util.*;
import java.util.regex.Pattern;

@SuppressWarnings("SpellCheckingInspection")
public class BrowserStack {
public class BrowserStackHelper {
private static final String hubUrl = "hub-cloud.browserstack.com";
private static final String serviceUri = "https://api-cloud.browserstack.com/";
private static final String appUploadServiceName = "app-automate/upload";

private BrowserStack() {
throw new IllegalStateException("Utility class");
/**
* Creates a new Selenium WebDriver instance using BrowserStack, use this to test Native Mobile apps over BrowserStack
*
* @param browserStackOptions custom browserstack options to be merged with the default in the browserStack.properties file
* @return a new Selenium WebDriver instance using BrowserStack
*/
public static DriverFactoryHelper getBrowserStackDriver(MutableCapabilities browserStackOptions) {
String appUrl = SHAFT.Properties.browserStack.appUrl();
var helper = new DriverFactoryHelper();
if ("".equals(appUrl)) {
// new native app OR web execution
if ("".equals(SHAFT.Properties.browserStack.appRelativeFilePath())) {
// this means it's a web execution (desktop or mobile)
if (DriverFactoryHelper.isMobileWebExecution()) {
browserStackOptions = setupMobileWebExecution().merge(browserStackOptions);
} else {
// desktop web
browserStackOptions = setupDesktopWebExecution().merge(browserStackOptions);
}
helper.initializeDriver(browserStackOptions);
} else {
// this is the new native app scenario
browserStackOptions = setupNativeAppExecution(SHAFT.Properties.browserStack.username(), SHAFT.Properties.browserStack.accessKey(),
SHAFT.Properties.browserStack.deviceName(), SHAFT.Properties.browserStack.platformVersion(), SHAFT.Properties.browserStack.appRelativeFilePath(), SHAFT.Properties.browserStack.appName()).merge(browserStackOptions);
helper.initializeDriver(DriverFactory.DriverType.APPIUM_MOBILE_NATIVE, browserStackOptions);
}
} else {
// this is the existing version from a native app scenario
browserStackOptions = setupNativeAppExecution(SHAFT.Properties.browserStack.username(), SHAFT.Properties.browserStack.accessKey(),
SHAFT.Properties.browserStack.deviceName(), SHAFT.Properties.browserStack.platformVersion(), appUrl).merge(browserStackOptions);
helper.initializeDriver(DriverFactory.DriverType.APPIUM_MOBILE_NATIVE, browserStackOptions);
}
return helper;
}

/**
Expand All @@ -34,7 +67,7 @@ private BrowserStack() {
* @param appName Name of your APK (excluding version number). This will be used as your CustomID so that you can keep uploading new versions of the same app and run your tests against them.
* @return appURL for the newly uploaded app file on BrowserStack to be used for future tests
*/
public static MutableCapabilities setupNativeAppExecution(String username, String password, String deviceName, String osVersion, String relativePathToAppFile, String appName) {
private static MutableCapabilities setupNativeAppExecution(String username, String password, String deviceName, String osVersion, String relativePathToAppFile, String appName) {
SHAFT.Properties.timeouts.set().apiSocketTimeout(600); //increasing socket timeout to 10 minutes to upload a new app file
ReportManager.logDiscrete("Setting up BrowserStack configuration for new native app version...");
String testData = "Username: " + username + ", Password: " + "•".repeat(password.length()) + ", Device Name: " + deviceName + ", OS Version: " + osVersion + ", Relative Path to App File: " + relativePathToAppFile + ", App Name: " + appName;
Expand Down Expand Up @@ -85,7 +118,7 @@ public static MutableCapabilities setupNativeAppExecution(String username, Strin
* @param appUrl Url of the target app that was previously uploaded to be tested via BrowserStack
* @return native app capabilities
*/
public static MutableCapabilities setupNativeAppExecution(String username, String password, String deviceName, String osVersion, String appUrl) {
private static MutableCapabilities setupNativeAppExecution(String username, String password, String deviceName, String osVersion, String appUrl) {
ReportManager.logDiscrete("Setting up BrowserStack configuration for existing native app version...");
String testData = "Username: " + username + ", Password: " + password + ", Device Name: " + deviceName + ", OS Version: " + osVersion + ", App URL: " + appUrl;
// set properties
Expand All @@ -94,7 +127,7 @@ public static MutableCapabilities setupNativeAppExecution(String username, Strin
return browserStackCapabilities;
}

public static MutableCapabilities setupMobileWebExecution() {
private static MutableCapabilities setupMobileWebExecution() {
ReportManager.logDiscrete("Setting up BrowserStack configuration for mobile web execution...");
String username = SHAFT.Properties.browserStack.username();
String password = SHAFT.Properties.browserStack.accessKey();
Expand Down Expand Up @@ -123,7 +156,7 @@ public static MutableCapabilities setupMobileWebExecution() {
return browserStackCapabilities;
}

public static MutableCapabilities setupDesktopWebExecution() {
private static MutableCapabilities setupDesktopWebExecution() {
ReportManager.logDiscrete("Setting up BrowserStack configuration for desktop web execution...");
String username = SHAFT.Properties.browserStack.username();
String password = SHAFT.Properties.browserStack.accessKey();
Expand Down Expand Up @@ -193,7 +226,7 @@ private static void passAction(String testData) {

private static void failAction(String testData, Throwable... rootCauseException) {
String message = reportActionResult(Thread.currentThread().getStackTrace()[2].getMethodName(), testData, false, rootCauseException);
FailureReporter.fail(BrowserStack.class, message, rootCauseException[0]);
FailureReporter.fail(BrowserStackHelper.class, message, rootCauseException[0]);
}

private static String reportActionResult(String actionName, String testData, Boolean passFailStatus, Throwable... rootCauseException) {
Expand Down
Loading

0 comments on commit 9ccb50b

Please sign in to comment.