Skip to content

Commit

Permalink
Remove WebDriverManager dependency and update to Selenium 4.13
Browse files Browse the repository at this point in the history
- As now built-in Selenium Manager allows to download driver, we don't need to maintain webDriverManager dependency.

- updated core library to use Selenium 4.13 (latest supported for Java 8)
- removed jackson-databind dependency
- update testng to 7.5.1 (latest supported for Java 8)
- added commons-lang dependency
- add workflow to automatically deploy to maven central after PR merge
  • Loading branch information
mialeska committed Jan 19, 2024
1 parent 122e911 commit 590f0c2
Show file tree
Hide file tree
Showing 24 changed files with 130 additions and 166 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/release-maven-central.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Publish package to Maven Central
on:
pull_request:
branches:
- master
types: [closed]

jobs:
publish:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Step 1 - Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Step 2 - Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: "8"
distribution: "adopt"
server-id: ossrh
server-username: MVN_CENTRAL_USERNAME
server-password: MVN_CENTRAL_PASSWORD
gpg-private-key: ${{ secrets.GPG_SECRET_KEY }}
gpg-passphrase: MVN_GPG_PASSPHRASE

- name: Step 3 - Install GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'

- name: Step 4 - Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0
with:
useConfigFile: true

- name: Step 5 - Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TITLE: ${{ github.event.pull_request.title }}
BODY: ${{ github.event.pull_request.body }}
VERSION: "v${{ steps.gitversion.outputs.semVer }}"
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }} ${{ env.TITLE }}
body: ${{ env.BODY }}
draft: false
prerelease: false

- name: Step 6 - Publish package
run: |
mvn -Dmaven.test.skip=true -P release -Drevision=${{ steps.gitversion.outputs.semVer }} deploy
env:
MVN_CENTRAL_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MVN_CENTRAL_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MVN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2023 Aquality Automation
Copyright 2024 Aquality Automation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
37 changes: 25 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium</artifactId>
<version>4.0.1</version>
<version>${revision}</version>
<packaging>jar</packaging>
<name>Aquality Selenium</name>
<description>Library around Selenium WebDriver</description>
Expand All @@ -15,6 +15,7 @@
<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>4.0.0-SNAPSHOT</revision>
</properties>

<distributionManagement>
Expand Down Expand Up @@ -81,26 +82,29 @@
<dependency>
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium-core</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
</dependency>

<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.3.2</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.13.0</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.2</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.10</version>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<version>7.5.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down Expand Up @@ -187,6 +191,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -207,6 +214,12 @@
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/aquality/selenium/browser/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import aquality.selenium.core.localization.ILocalizationManager;
import aquality.selenium.core.localization.ILocalizedLogger;
import aquality.selenium.core.waitings.IConditionalWait;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.NotImplementedException;
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.devtools.HasDevTools;
Expand All @@ -21,7 +19,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.function.Supplier;

Expand Down Expand Up @@ -147,7 +144,8 @@ public IBrowserTabNavigation tabs() {
}

/**
* Sets page load timeout (Will be ignored for Safari https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/687)
* Sets page load timeout (Will be ignored for Safari
* <a href="https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/687">...</a>)
*
* @param timeout seconds to wait
*/
Expand Down Expand Up @@ -248,10 +246,9 @@ public Object executeAsyncScript(JavaScript scriptName, Object... args) {
* @param file Java Script file
* @param arguments Arguments for the script (web elements, values etc.
* @return Result object of script execution
* @throws IOException in case of problems with the File
*/
public Object executeAsyncScript(final File file, Object... arguments) throws IOException {
return executeAsyncScript(IOUtils.toString(file.toURI(), StandardCharsets.UTF_8.name()), arguments);
public Object executeAsyncScript(final File file, Object... arguments) {
return executeAsyncScript(JavaScript.readScript(file), arguments);
}

/**
Expand Down Expand Up @@ -303,7 +300,7 @@ public Object executeScript(JavaScript scriptName, Object... args) {
* @throws IOException in case of problems with the File
*/
public Object executeScript(final File file, Object... arguments) throws IOException {
return executeScript(IOUtils.toString(file.toURI(), StandardCharsets.UTF_8.name()), arguments);
return executeScript(JavaScript.readScript(file), arguments);
}

/**
Expand Down Expand Up @@ -400,7 +397,7 @@ public DevToolsHandling devTools() {
return devTools;
}
else {
throw new NotImplementedException("DevTools protocol is not supported for current browser.");
throw new UnsupportedOperationException("DevTools protocol is not supported for current browser.");
}
}

Expand Down
27 changes: 22 additions & 5 deletions src/main/java/aquality/selenium/browser/JavaScript.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package aquality.selenium.browser;

import aquality.selenium.core.logging.Logger;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.core.util.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import static java.lang.String.format;

Expand Down Expand Up @@ -59,11 +59,28 @@ public String getScript() {
URL scriptFile = getClass().getResource("/js/" + filename);
if (scriptFile != null) {
try (InputStream stream = scriptFile.openStream()) {
return IOUtils.toString(stream, StandardCharsets.UTF_8.name());
return readScript(stream);
} catch (IOException e) {
Logger.getInstance().fatal(format("Couldn't find the script \"%s\"", filename), e);
logScriptAbsence(filename, e);
}
}
return "";
}

static String readScript(final File file) {
try (InputStream stream = Files.newInputStream(file.toPath())) {
return readScript(stream);
} catch (IOException e) {
logScriptAbsence(file.getName(), e);
return "";
}
}

private static void logScriptAbsence(String filename, IOException e) {
Logger.getInstance().fatal(format("Couldn't find the script \"%s\"", filename), e);
}

private static String readScript(InputStream stream) throws IOException {
return IOUtils.toString(new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import aquality.selenium.configuration.driversettings.IDriverSettings;
import aquality.selenium.core.localization.ILocalizedLogger;
import aquality.selenium.core.utilities.IActionRetrier;
import io.github.bonigarcia.wdm.WebDriverManager;
import io.github.bonigarcia.wdm.config.Architecture;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
Expand All @@ -15,7 +12,6 @@
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.remote.AbstractDriverOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.safari.SafariOptions;
Expand All @@ -34,8 +30,6 @@ protected RemoteWebDriver getDriver() {
BrowserName browserName = browserProfile.getBrowserName();
RemoteWebDriver driver;
IDriverSettings driverSettings = browserProfile.getDriverSettings();
String webDriverVersion = driverSettings.getWebDriverVersion();
Architecture systemArchitecture = driverSettings.getSystemArchitecture();
switch (browserName) {
case CHROME:
case YANDEX:
Expand All @@ -45,18 +39,16 @@ protected RemoteWebDriver getDriver() {
driver = new FirefoxDriver((FirefoxOptions) driverSettings.getDriverOptions());
break;
case IEXPLORER:
WebDriverManager.iedriver().architecture(systemArchitecture).driverVersion(webDriverVersion).setup();
driver = new InternetExplorerDriver((InternetExplorerOptions) driverSettings.getDriverOptions());
break;
case EDGE:
WebDriverManager.edgedriver().driverVersion(webDriverVersion).setup();
driver = new EdgeDriver((EdgeOptions) driverSettings.getDriverOptions());
break;
case SAFARI:
driver = new SafariDriver((SafariOptions) driverSettings.getDriverOptions());
break;
default:
throw new IllegalArgumentException(String.format("Browser [%s] is not supported.", browserName));
throw new UnsupportedOperationException(String.format("Browser [%s] is not supported.", browserName));
}
return driver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import aquality.selenium.browser.AqualityServices;
import aquality.selenium.core.localization.ILocalizedLogger;
import org.apache.commons.lang3.NotImplementedException;
import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.DevTools;
Expand Down Expand Up @@ -132,7 +131,7 @@ public Map<String, Object> executeCdpCommand(String commandName, Map<String, Obj
return result;
}
else {
throw new NotImplementedException("Execution of CDP command directly is not supported for current browser. Try sendCommand method instead.");
throw new UnsupportedOperationException("Execution of CDP command directly is not supported for current browser. Try sendCommand method instead.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import aquality.selenium.browser.AqualityServices;
import aquality.selenium.core.localization.ILocalizedLogger;
import org.apache.commons.lang3.NotImplementedException;
import org.openqa.selenium.JavascriptException;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.ScriptKey;
Expand Down Expand Up @@ -174,7 +173,7 @@ public void unpinScript(ScriptKey pinnedScript) {

/**
* Gets list of previously pinned scripts.
* @return a list of previously pinned scripts.
* @return a set of previously pinned scripts.
*/
public Set<ScriptKey> getPinnedScripts() {
logger.info("loc.browser.javascript.snippets.get");
Expand Down Expand Up @@ -227,7 +226,7 @@ public <X> void onLogEvent(EventType<X> kind) {
}
}).augment(driver);
if (!(driver instanceof HasLogEvents)) {
throw new NotImplementedException(
throw new UnsupportedOperationException(
String.format("Driver for the current browser [%s] doesn't implement HasLogEvents", browserName));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,14 @@ public IDriverSettings getDriverSettings() {
case IEXPLORER:
driverSettings = new IExplorerSettings(settingsFile);
break;
case OPERA:
driverSettings = new OperaSettings(settingsFile);
break;
case SAFARI:
driverSettings = new SafariSettings(settingsFile);
break;
case YANDEX:
driverSettings = new YandexSettings(settingsFile);
break;
default:
throw new IllegalArgumentException("There are no assigned behaviour for retrieving driver driversettings for browser " + getBrowserName());
throw new UnsupportedOperationException("There are no assigned behaviour for retrieving driver driversettings for browser " + getBrowserName());
}
return driverSettings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import aquality.selenium.core.localization.ILocalizationManager;
import aquality.selenium.core.logging.Logger;
import aquality.selenium.core.utilities.ISettingsFile;
import io.github.bonigarcia.wdm.config.Architecture;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.PageLoadStrategy;
Expand Down Expand Up @@ -101,22 +100,6 @@ private final <T> void logCollection(String messageKey, final T... elements) {
}
}

@Override
public String getWebDriverVersion() {
return String.valueOf(getSettingsFile().getValueOrDefault(
getDriverSettingsPath("webDriverVersion"), "Latest"));
}

@Override
public Architecture getSystemArchitecture() {
String strValue = String.valueOf(getSettingsFile().getValueOrDefault(
getDriverSettingsPath("systemArchitecture"), "Auto"));
return Arrays.stream(Architecture.values())
.filter(value -> value.name().equals(strValue))
.findFirst()
.orElse(Architecture.X32);
}

@Override
public PageLoadStrategy getPageLoadStrategy() {
String value = (String) getSettingsFile().getValueOrDefault(getDriverSettingsPath("pageLoadStrategy"), "normal");
Expand Down
Loading

0 comments on commit 590f0c2

Please sign in to comment.