Skip to content

Commit

Permalink
Handle windows for electron application
Browse files Browse the repository at this point in the history
  • Loading branch information
MedhaGupta-Ril committed Dec 14, 2023
1 parent 9215f76 commit dedff14
Show file tree
Hide file tree
Showing 24 changed files with 131 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/BrowserStack_Android_CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/BrowserStack_Web_CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Build_And_Run_Unit_Tests_CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: Build with Gradle and run unit tests
uses: gradle/gradle-build-action@87a9a15658c426a54dd469d4fc7dc1a73ca9d4a6
uses: gradle/gradle-build-action@0280eb7de5ad3fb0deb50017b8ce842980b4789a
with:
arguments: build --refresh-dependencies
- name: Get Latest Commit ID and save in GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![CodeQL](https://github.com/znsio/teswiz/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/znsio/teswiz/actions/workflows/codeql-analysis.yml)

## Latest successful build id:
[![Latest Commit](https://img.shields.io/badge/commit-85c91c10b5-blue.svg)](https://jitpack.io/#znsio/teswiz)
[![Latest Commit](https://img.shields.io/badge/commit-d6d8288d03-blue.svg)](https://jitpack.io/#znsio/teswiz)

# To Build
`./gradlew clean build`
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import java.text.SimpleDateFormat

buildscript {
ext {
gradleVersion = "8.4"
gradleVersion = "8.5"
assertJVersion = "3.24.2"
atdVersion = "14.0.1"
applitoolsAppiumVersion = "5.65.0"
applitoolsAppiumVersion = "5.66.0"
seleniumVersion = "4.13.0"
commonsLang3Version = "3.14.0"
commonsRngSimpleVersion = "1.5"
Expand All @@ -19,8 +19,8 @@ buildscript {
browserStackLocalVersion = "1.1.0"
jetbrainsAnnotationsVersion = "24.1.0"
aspectJVersion = "1.9.20.1"
specmaticVersion = '0.81.2'
webDriverManager = '5.5.3'
specmaticVersion = '1.0.3'
}
}

Expand Down Expand Up @@ -147,6 +147,7 @@ tasks.register('run', JavaExec) {
def logDirectory = "target/" + getCurrentDatestamp() + "/" + getCurrentTimestamp()
println "Using LOG_DIR: $logDirectory"
System.setProperty "LOG_DIR", "$logDirectory"

def configFile = System.getenv("CONFIG")
if (null == configFile || !file(configFile).exists()) {
println("CONFIG file not provided, or does not exist")
Expand Down
1 change: 0 additions & 1 deletion caps/ajio/ajio_browserstack_capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"browserstack.appium_version": "2.0.1",
"browserstack.enableCameraImageInjection": true,
"browserstack.debug": true,
"browserstack.geoLocation": "IN",
"browserstack.timezone": "Kolkata",
"browserstack.networkLogs": "true",
"browserstack.gpsLocation": "22,75",
Expand Down
1 change: 0 additions & 1 deletion caps/jio/jiomeet_browserStack_capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"noSign": true,
"autoAcceptAlerts": true,
"browserstack.enableCameraImageInjection": true,
"browserstack.geoLocation": "IN",
"browserstack.timezone": "Kolkata",
"browserstack.debug": "false",
"browserstack.networkLogs": "true",
Expand Down
1 change: 0 additions & 1 deletion caps/theapp/theapp_browserstack_capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"browserstack.appium_version": "2.0.1",
"browserstack.enableCameraImageInjection": true,
"browserstack.debug": true,
"browserstack.geoLocation": "IN",
"browserstack.timezone": "Kolkata",
"browserstack.networkLogs": "true",
"browserstack.gpsLocation": "22,75",
Expand Down
1 change: 0 additions & 1 deletion caps/vodqa/vodqa_browserstack_capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"browserstack.appium_version": "2.0.1",
"browserstack.enableCameraImageInjection": true,
"browserstack.debug": true,
"browserstack.geoLocation": "IN",
"browserstack.timezone": "Kolkata",
"browserstack.networkLogs": "true",
"browserstack.gpsLocation": "22,75",
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -144,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
42 changes: 28 additions & 14 deletions src/main/java/com/znsio/teswiz/runner/BrowserDriverManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;

import static com.znsio.teswiz.runner.Runner.DEFAULT;
Expand Down Expand Up @@ -196,7 +198,7 @@ private static WebDriver createChromeDriver(String forUserPersona,
shouldBrowserBeMaximized = chromeConfiguration.getBoolean(MAXIMIZE);

WebDriver driver = Runner.isRunningInCI() ? createRemoteWebDriver(chromeOptions)
: new ChromeDriver(chromeOptions);
: new ChromeDriver(chromeOptions);
LOGGER.info("Chrome driver created");
Capabilities capabilities =
Runner.isRunningInCI() ? ((RemoteWebDriver) driver).getCapabilities()
Expand All @@ -212,17 +214,9 @@ private static ChromeOptions getChromeOptions(String forUserPersona, TestExecuti
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setAcceptInsecureCerts(chromeConfiguration.getBoolean(ACCEPT_INSECURE_CERTS));

if (Runner.getPlatform().equals(Platform.electron)) {
chromeOptions.setBinary(chromeConfiguration.getString("binary"));
Toolkit toolkit = Toolkit.getDefaultToolkit();
int width = toolkit.getScreenSize().width;
int height = toolkit.getScreenSize().height;
chromeOptions.addArguments(String.format("window-size=%s,%s", width, height));
}

String browserVersion = getOverriddenStringValue(BROWSER_VERSION,
chromeConfiguration.getString("browserVersion"));
if(Runner.getPlatform().equals(Platform.web) && !browserVersion.equalsIgnoreCase("latest"))
if (Runner.getPlatform().equals(Platform.web) && !browserVersion.equalsIgnoreCase("latest"))
chromeOptions.setBrowserVersion(browserVersion);

setLogFileName(forUserPersona, testExecutionContext, "Chrome");
Expand All @@ -235,6 +229,14 @@ private static ChromeOptions getChromeOptions(String forUserPersona, TestExecuti
return chromeOptions;
}

private static void addWindowSizeToChromeOptions(JSONObject chromeConfiguration, ChromeOptions chromeOptions) {
chromeOptions.setBinary(chromeConfiguration.getString("binary"));
Toolkit toolkit = Toolkit.getDefaultToolkit();
int width = toolkit.getScreenSize().width;
int height = toolkit.getScreenSize().height;
chromeOptions.addArguments(String.format("window-size=%s,%s", width, height));
}

private static WebDriver createFirefoxDriver(String forUserPersona,
TestExecutionContext testExecutionContext,
JSONObject firefoxConfiguration) {
Expand All @@ -243,7 +245,7 @@ private static WebDriver createFirefoxDriver(String forUserPersona,
shouldBrowserBeMaximized = firefoxConfiguration.getBoolean(MAXIMIZE);

WebDriver driver = Runner.isRunningInCI() ? createRemoteWebDriver(firefoxOptions)
: new FirefoxDriver(firefoxOptions);
: new FirefoxDriver(firefoxOptions);
LOGGER.info("Firefox driver created");
Capabilities capabilities =
Runner.isRunningInCI() ? ((RemoteWebDriver) driver).getCapabilities()
Expand Down Expand Up @@ -423,7 +425,7 @@ private static WebDriver createSafariDriver(String forUserPersona,
shouldBrowserBeMaximized = safariConfigurations.getBoolean(MAXIMIZE);

WebDriver driver = Runner.isRunningInCI() ? createRemoteWebDriver(safariOptions)
: new SafariDriver(safariOptions);
: new SafariDriver(safariOptions);
LOGGER.info("Safari driver created");
Capabilities capabilities =
Runner.isRunningInCI() ? ((RemoteWebDriver) driver).getCapabilities()
Expand Down Expand Up @@ -499,8 +501,8 @@ private static RemoteWebDriver createRemoteWebDriver(MutableCapabilities capabil
Map hostMachines = (Map) hostMachinesList.get(0);
String remoteServerURL = String.valueOf(hostMachines.get("machineIP"));
remoteUrl = remoteServerURL.endsWith("/")
? remoteServerURL + authenticationKey + webDriverHubSuffix
: remoteServerURL + "/" + authenticationKey + webDriverHubSuffix;
? remoteServerURL + authenticationKey + webDriverHubSuffix
: remoteServerURL + "/" + authenticationKey + webDriverHubSuffix;
remoteUrl = remoteUrl.startsWith("https") ? remoteUrl : "https://" + remoteUrl;
} else if (cloudName.equalsIgnoreCase("browserstack")) {
String authenticationUser = Runner.getCloudUser();
Expand Down Expand Up @@ -572,6 +574,8 @@ static Driver createElectronDriverForUser(String userPersona, String browserName
LOGGER.info(BrowserDriverManager.class.getName() + "-createNewElectronDriver: " + browserName.toLowerCase());
JSONObject browserConfigForBrowserType = browserConfig.getJSONObject(browserName.toLowerCase());
ChromeOptions chromeOptions = getChromeOptions(userPersona, context, browserConfigForBrowserType);
addWindowSizeToChromeOptions(browserConfigForBrowserType, chromeOptions);

shouldBrowserBeMaximized = browserConfigForBrowserType.getBoolean(MAXIMIZE);

WebDriverManager.chromedriver().clearDriverCache().driverVersion(getOverriddenStringValue(BROWSER_VERSION,
Expand All @@ -586,6 +590,16 @@ static Driver createElectronDriverForUser(String userPersona, String browserName
Drivers.addUserPersonaDriverCapabilities(userPersona, capabilities);
LOGGER.info("Electron driver capabilities extracted for further use");
loadBaseUrl(baseUrl, driver);

String parentWindowHandle = driver.getWindowHandle();
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(50));
Set<String> windowHandles = driver.getWindowHandles();
for (String handle : windowHandles) {
if (!handle.equals(parentWindowHandle)) {
driver.switchTo().window(handle);
break;
}
}
Driver currentDriver = new Driver(updatedTestName, forPlatform, userPersona, appName, driver, isRunInHeadlessMode);
numberOfWebDriversUsed++;
LOGGER.info(String.format("createElectronDriverForUser: done: userPersona: '%s', Platform: '%s', appName: '%s', Number of ElectronDrivers: '%d'",
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/com/znsio/teswiz/runner/Visual.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,12 @@ private RectangleSize getBrowserViewPortSize(String driverType, WebDriver innerD
return providedBrowserViewPortSizeFromConfig;
} else {
JavascriptExecutor js = (JavascriptExecutor) innerDriver;
if (Runner.getPlatform().equals(Platform.electron)) {
Set<String> windowHandles = innerDriver.getWindowHandles();
if (windowHandles.size() > 0) {
innerDriver.switchTo().window((String) windowHandles.toArray()[0]);
}
} else {
Dimension actualBrowserSize = innerDriver.manage().window().getSize();
LOGGER.info(String.format("Actual browser dimensions: %s", actualBrowserSize));
}
Dimension actualBrowserSize;
if(Runner.getPlatform().equals(Platform.electron))
actualBrowserSize = new Dimension(100, 100);
else
actualBrowserSize = innerDriver.manage().window().getSize();
LOGGER.info(String.format("Actual browser dimensions: %s", actualBrowserSize));
Long actualHeight = (Long) js.executeScript("return (window.innerHeight);");
Long actualWidth = (Long) js.executeScript("return (window.innerWidth);");

Expand Down
13 changes: 7 additions & 6 deletions src/test/java/com/znsio/teswiz/businessLayer/jiomeet/AuthBL.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ public LandingBL signIn(Map userDetails) {
String password = String.valueOf(userDetails.get("password"));
String firstName = String.valueOf(userDetails.get("firstName"));
String lastName = String.valueOf(userDetails.get("lastName"));

String expectedWelcomeMessageAndroid = "Hello " + firstName + " \n" + "what would you " +
"like to do?";
"like to do?";
String expectedWelcomeMessageWeb = "Hello " + firstName + " " + lastName + ", what would " +
"you like to do?";
"you like to do?";
String expectedWelcomeMessage =
currentPlatform.equals(Platform.web) ? expectedWelcomeMessageWeb
: expectedWelcomeMessageAndroid;
currentPlatform.equals(Platform.web) || currentPlatform.equals(Platform.electron) ? expectedWelcomeMessageWeb
: expectedWelcomeMessageAndroid;

String signedInWelcomeMessage = SignInScreen.get().signIn(username, password)
.getSignedInWelcomeMessage();
.getSignedInWelcomeMessage();

LOGGER.info(String.format("signedInWelcomeMessage: '%s'", signedInWelcomeMessage));

assertThat(signedInWelcomeMessage).as("Welcome message is incorrect")
.isEqualTo(expectedWelcomeMessage);
.isEqualTo(expectedWelcomeMessage);
return new LandingBL(currentUserPersona, currentPlatform);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public InAMeetingScreen openJioMeetNotification() {
driver.selectNotificationFromNotificationDrawer(byMeetingNotificationXpath);
return this;
}

@Override
public InAMeetingScreen unmute() {
enableInMeetingControls("unmute");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public static InAMeetingScreen get() {
LOGGER.info(SCREEN_NAME + ": Driver type: " + driver.getType() + ": Platform: " + platform);
Visual visually = Drivers.getVisualDriverForCurrentUser(Thread.currentThread().getId());

switch(platform) {
switch (platform) {
case android:
return new InAMeetingScreenAndroid(driver, visually);
case web:
case electron:
return new InAMeetingScreenWeb(driver, visually);
}
throw new NotImplementedException(
Expand All @@ -43,5 +44,4 @@ public static InAMeetingScreen get() {
public abstract String getMicLabelText();

public abstract InAMeetingScreen openJioMeetNotification();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public static LandingScreen get() {
LOGGER.info(SCREEN_NAME + ": Driver type: " + driver.getType() + ": Platform: " + platform);
Visual visually = Drivers.getVisualDriverForCurrentUser(Thread.currentThread().getId());

switch(platform) {
switch (platform) {
case android:
return new LandingScreenAndroid(driver, visually);
case web:
case electron:
return new LandingScreenWeb(driver, visually);
}
throw new NotImplementedException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public static SignInScreen get() {
LOGGER.info(SCREEN_NAME + ": Driver type: " + driver.getType() + ": Platform: " + platform);
Visual visually = Drivers.getVisualDriverForCurrentUser(Thread.currentThread().getId());

switch(platform) {
switch (platform) {
case android:
return new SignInScreenAndroid(driver, visually);
case web:
case electron:
return new SignInScreenWeb(driver, visually);
}
throw new NotImplementedException(
Expand Down
Loading

0 comments on commit dedff14

Please sign in to comment.