Skip to content

Commit

Permalink
Merge branch 'master' into enhancement/use-native-open-new-tab-function
Browse files Browse the repository at this point in the history
  • Loading branch information
mialeska committed Feb 15, 2024
2 parents 26b504a + 9445843 commit 71b5013
Show file tree
Hide file tree
Showing 34 changed files with 383 additions and 155 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 }}
6 changes: 6 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mode: Mainline
increment: Inherit
branches: {}
ignore:
sha: []

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
39 changes: 26 additions & 13 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.0</version>
<version>${revision}</version>
<packaging>jar</packaging>
<name>Aquality Selenium</name>
<description>Library around Selenium WebDriver</description>
Expand All @@ -15,16 +15,17 @@
<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>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

Expand Down Expand Up @@ -81,25 +82,28 @@
<dependency>
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium-core</artifactId>
<version>3.0.0</version>
<version>3.1.2</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>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.10</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<version>7.5.1</version>
<scope>test</scope>
</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 All @@ -217,7 +230,7 @@
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</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
28 changes: 23 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 All @@ -22,6 +22,7 @@ public enum JavaScript {
GET_COMBOBOX_SELECTED_TEXT("getCmbText.js"),
GET_COMBOBOX_TEXTS("getCmbValues.js"),
GET_ELEMENT_BY_XPATH("getElementByXpath.js"),
GET_ELEMENT_CSS_SELECTOR("getElementCssSelector.js"),
GET_ELEMENT_XPATH("getElementXPath.js"),
GET_ELEMENT_TEXT("getElementText.js"),
GET_TEXT_FIRST_CHILD("getTextFirstChild.js"),
Expand Down Expand Up @@ -59,11 +60,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)));
}
}
19 changes: 5 additions & 14 deletions src/main/java/aquality/selenium/browser/LocalBrowserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
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.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
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,35 +31,29 @@ 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:
WebDriverManager.chromedriver().driverVersion(webDriverVersion).setup();
driver = new ChromeDriver((ChromeOptions) driverSettings.getDriverOptions());
break;
case YANDEX:
case OPERA:
WebDriverManager.operadriver().driverVersion(webDriverVersion).setup();
driver = new ChromeDriver((ChromeOptions) driverSettings.getDriverOptions());
driver = new ChromeDriver(new ChromeDriverService.Builder().withBuildCheckDisabled(true).build(),
(ChromeOptions) driverSettings.getDriverOptions());
break;
case FIREFOX:
WebDriverManager.firefoxdriver().driverVersion(webDriverVersion).setup();
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
Loading

0 comments on commit 71b5013

Please sign in to comment.