From 590f0c2583eb1513759282a583178ae4efb4d392 Mon Sep 17 00:00:00 2001 From: Aliaksej Mialeshka Date: Fri, 19 Jan 2024 20:33:22 +0100 Subject: [PATCH 1/4] Remove WebDriverManager dependency and update to Selenium 4.13 - 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 --- .github/workflows/release-maven-central.yml | 61 +++++++++++++++++++ LICENSE | 2 +- pom.xml | 37 +++++++---- .../aquality/selenium/browser/Browser.java | 15 ++--- .../aquality/selenium/browser/JavaScript.java | 27 ++++++-- .../selenium/browser/LocalBrowserFactory.java | 10 +-- .../browser/devtools/DevToolsHandling.java | 3 +- .../browser/devtools/JavaScriptHandling.java | 5 +- .../configuration/BrowserProfile.java | 5 +- .../driversettings/DriverSettings.java | 17 ------ .../driversettings/IDriverSettings.java | 13 ---- .../driversettings/IExplorerSettings.java | 2 +- .../driversettings/OperaSettings.java | 27 -------- .../driversettings/SafariSettings.java | 2 +- src/main/resources/settings.json | 21 ------- .../java/manytools/RequestHeadersForm.java | 3 +- .../tests/usecases/BrowserFactoryTests.java | 2 - .../devtools/DeviceEmulationTest.java | 4 +- .../devtools/NetworkInterceptionTests.java | 5 +- .../devtools/NetworkSpeedEmulationTest.java | 2 +- .../devtools/OverrideUserAgentTest.java | 2 +- src/test/resources/settings.incorrect.json | 4 -- src/test/resources/settings.json | 23 +------ src/test/resources/settings.local.json | 4 -- 24 files changed, 130 insertions(+), 166 deletions(-) create mode 100644 .github/workflows/release-maven-central.yml delete mode 100644 src/main/java/aquality/selenium/configuration/driversettings/OperaSettings.java diff --git a/.github/workflows/release-maven-central.yml b/.github/workflows/release-maven-central.yml new file mode 100644 index 0000000..75fd3f3 --- /dev/null +++ b/.github/workflows/release-maven-central.yml @@ -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 }} diff --git a/LICENSE b/LICENSE index a6ceff9..ecef83a 100644 --- a/LICENSE +++ b/LICENSE @@ -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. diff --git a/pom.xml b/pom.xml index 22c0765..2eb7393 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.aquality-automation aquality-selenium - 4.0.1 + ${revision} jar Aquality Selenium Library around Selenium WebDriver @@ -15,6 +15,7 @@ UTF-8 UTF-8 + 4.0.0-SNAPSHOT @@ -81,26 +82,29 @@ com.github.aquality-automation aquality-selenium-core - 3.0.0 + 3.1.0 - - io.github.bonigarcia - webdrivermanager - 5.3.2 + org.apache.commons + commons-lang3 + 3.13.0 - - com.fasterxml.jackson.core - jackson-databind - 2.14.2 + org.slf4j + slf4j-simple + 2.0.10 - org.testng testng - 7.5 + 7.5.1 test + + + org.webjars + jquery + + @@ -187,6 +191,9 @@ org.apache.maven.plugins maven-javadoc-plugin + + 8 + attach-javadocs @@ -207,6 +214,12 @@ sign + + + --pinentry-mode + loopback + + diff --git a/src/main/java/aquality/selenium/browser/Browser.java b/src/main/java/aquality/selenium/browser/Browser.java index 8b6a998..e10ec5f 100644 --- a/src/main/java/aquality/selenium/browser/Browser.java +++ b/src/main/java/aquality/selenium/browser/Browser.java @@ -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; @@ -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; @@ -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 + * ...) * * @param timeout seconds to wait */ @@ -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); } /** @@ -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); } /** @@ -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."); } } diff --git a/src/main/java/aquality/selenium/browser/JavaScript.java b/src/main/java/aquality/selenium/browser/JavaScript.java index b9a4c19..967b769 100644 --- a/src/main/java/aquality/selenium/browser/JavaScript.java +++ b/src/main/java/aquality/selenium/browser/JavaScript.java @@ -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; @@ -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))); + } } diff --git a/src/main/java/aquality/selenium/browser/LocalBrowserFactory.java b/src/main/java/aquality/selenium/browser/LocalBrowserFactory.java index 516d712..c53963b 100644 --- a/src/main/java/aquality/selenium/browser/LocalBrowserFactory.java +++ b/src/main/java/aquality/selenium/browser/LocalBrowserFactory.java @@ -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; @@ -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; @@ -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: @@ -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; } diff --git a/src/main/java/aquality/selenium/browser/devtools/DevToolsHandling.java b/src/main/java/aquality/selenium/browser/devtools/DevToolsHandling.java index 387eb9c..6187ec5 100644 --- a/src/main/java/aquality/selenium/browser/devtools/DevToolsHandling.java +++ b/src/main/java/aquality/selenium/browser/devtools/DevToolsHandling.java @@ -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; @@ -132,7 +131,7 @@ public Map executeCdpCommand(String commandName, Map getPinnedScripts() { logger.info("loc.browser.javascript.snippets.get"); @@ -227,7 +226,7 @@ public void onLogEvent(EventType 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)); } } diff --git a/src/main/java/aquality/selenium/configuration/BrowserProfile.java b/src/main/java/aquality/selenium/configuration/BrowserProfile.java index 0dc583a..55206fe 100644 --- a/src/main/java/aquality/selenium/configuration/BrowserProfile.java +++ b/src/main/java/aquality/selenium/configuration/BrowserProfile.java @@ -49,9 +49,6 @@ public IDriverSettings getDriverSettings() { case IEXPLORER: driverSettings = new IExplorerSettings(settingsFile); break; - case OPERA: - driverSettings = new OperaSettings(settingsFile); - break; case SAFARI: driverSettings = new SafariSettings(settingsFile); break; @@ -59,7 +56,7 @@ public IDriverSettings getDriverSettings() { 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; } diff --git a/src/main/java/aquality/selenium/configuration/driversettings/DriverSettings.java b/src/main/java/aquality/selenium/configuration/driversettings/DriverSettings.java index 96092b4..5c804fd 100644 --- a/src/main/java/aquality/selenium/configuration/driversettings/DriverSettings.java +++ b/src/main/java/aquality/selenium/configuration/driversettings/DriverSettings.java @@ -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; @@ -101,22 +100,6 @@ private final 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"); diff --git a/src/main/java/aquality/selenium/configuration/driversettings/IDriverSettings.java b/src/main/java/aquality/selenium/configuration/driversettings/IDriverSettings.java index 912d4b8..43fd1d4 100644 --- a/src/main/java/aquality/selenium/configuration/driversettings/IDriverSettings.java +++ b/src/main/java/aquality/selenium/configuration/driversettings/IDriverSettings.java @@ -1,7 +1,6 @@ package aquality.selenium.configuration.driversettings; import aquality.selenium.browser.BrowserName; -import io.github.bonigarcia.wdm.config.Architecture; import org.openqa.selenium.Capabilities; import org.openqa.selenium.PageLoadStrategy; import org.openqa.selenium.remote.AbstractDriverOptions; @@ -23,18 +22,6 @@ public interface IDriverSettings { */ PageLoadStrategy getPageLoadStrategy(); - /** - * Gets version of web driver for WebDriverManager. - * @return Version of web driver. - */ - String getWebDriverVersion(); - - /** - * Gets target system architecture for WebDriverManager. - * @return initialized {@link Architecture}. - */ - Architecture getSystemArchitecture(); - /** * Gets download directory for web driver. * @return Path to download directory. diff --git a/src/main/java/aquality/selenium/configuration/driversettings/IExplorerSettings.java b/src/main/java/aquality/selenium/configuration/driversettings/IExplorerSettings.java index 9269c80..b2ae379 100644 --- a/src/main/java/aquality/selenium/configuration/driversettings/IExplorerSettings.java +++ b/src/main/java/aquality/selenium/configuration/driversettings/IExplorerSettings.java @@ -22,7 +22,7 @@ public AbstractDriverOptions getDriverOptions() { @Override public String getDownloadDirCapabilityKey() { - throw new IllegalArgumentException("Download directory for Internet Explorer profiles is not supported"); + throw new UnsupportedOperationException("Download directory for Internet Explorer profiles is not supported"); } @Override diff --git a/src/main/java/aquality/selenium/configuration/driversettings/OperaSettings.java b/src/main/java/aquality/selenium/configuration/driversettings/OperaSettings.java deleted file mode 100644 index 30ca499..0000000 --- a/src/main/java/aquality/selenium/configuration/driversettings/OperaSettings.java +++ /dev/null @@ -1,27 +0,0 @@ -package aquality.selenium.configuration.driversettings; - -import aquality.selenium.browser.BrowserName; -import aquality.selenium.core.utilities.ISettingsFile; -import org.openqa.selenium.chrome.ChromeOptions; -import org.openqa.selenium.remote.AbstractDriverOptions; - -public class OperaSettings extends ChromeSettings { - private static final String DEFAULT_BINARY_LOCATION = "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe"; - - public OperaSettings(ISettingsFile settingsFile) { - super(settingsFile); - } - - @Override - public BrowserName getBrowserName() { - return BrowserName.OPERA; - } - - @Override - public AbstractDriverOptions getDriverOptions() { - ChromeOptions options = (ChromeOptions) super.getDriverOptions(); - options.setExperimentalOption("w3c", true); - options.setBinary(getBinaryLocation(DEFAULT_BINARY_LOCATION)); - return options; - } -} diff --git a/src/main/java/aquality/selenium/configuration/driversettings/SafariSettings.java b/src/main/java/aquality/selenium/configuration/driversettings/SafariSettings.java index 3acd382..14d716d 100644 --- a/src/main/java/aquality/selenium/configuration/driversettings/SafariSettings.java +++ b/src/main/java/aquality/selenium/configuration/driversettings/SafariSettings.java @@ -20,7 +20,7 @@ public AbstractDriverOptions getDriverOptions() { @Override public String getDownloadDirCapabilityKey() { - throw new IllegalArgumentException("Download directory for Safari profiles is not supported in capabilities. Please, use separate 'downloadDir' property"); + throw new UnsupportedOperationException("Download directory for Safari profiles is not supported in capabilities. Please, use separate 'downloadDir' property"); } @Override diff --git a/src/main/resources/settings.json b/src/main/resources/settings.json index 57f0c68..b25b7b0 100644 --- a/src/main/resources/settings.json +++ b/src/main/resources/settings.json @@ -6,7 +6,6 @@ "driverSettings": { "chrome": { - "webDriverVersion": "latest", "capabilities": { }, "options": { @@ -24,7 +23,6 @@ "startArguments": [] }, "edge": { - "webDriverVersion": "latest", "capabilities": { }, "options": { @@ -41,7 +39,6 @@ "startArguments": [] }, "firefox": { - "webDriverVersion": "latest", "capabilities": { }, "options": { @@ -62,32 +59,14 @@ "startArguments": [] }, "iexplorer": { - "webDriverVersion": "latest", - "systemArchitecture": "X32", "capabilities": { "ignoreProtectedModeSettings": true } }, - "opera": { - "webDriverVersion": "latest", - "binaryLocation": "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe", - "capabilities": { - }, - "options": { - "intl.accept_languages": "en", - "safebrowsing.enabled": "true", - "profile.default_content_settings.popups": "0", - "disable-popup-blocking": "true", - "download.prompt_for_download": "false", - "download.default_directory": "./downloads" - }, - "startArguments": ["--remote-debugging-port=9222", "--no-sandbox", "--disable-dev-shm-usage"] - }, "safari": { "downloadDir": "/Users/username/Downloads" }, "yandex": { - "webDriverVersion": "102.0.5005.61", "binaryLocation": "%USERPROFILE%\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe", "capabilities": { }, diff --git a/src/test/java/manytools/RequestHeadersForm.java b/src/test/java/manytools/RequestHeadersForm.java index 5cfa3b8..96a5ba6 100644 --- a/src/test/java/manytools/RequestHeadersForm.java +++ b/src/test/java/manytools/RequestHeadersForm.java @@ -1,7 +1,6 @@ package manytools; import aquality.selenium.elements.interfaces.ILabel; -import org.apache.commons.lang3.NotImplementedException; import org.openqa.selenium.By; import java.util.function.Function; @@ -20,7 +19,7 @@ protected String getUrlPart() { @Override public String getValue() { - throw new NotImplementedException("Please call the method getNullableValue with parameter instead"); + throw new UnsupportedOperationException("Please call the method getNullableValue with parameter instead"); } public String getNullableValue(String headerName) { diff --git a/src/test/java/tests/usecases/BrowserFactoryTests.java b/src/test/java/tests/usecases/BrowserFactoryTests.java index 80f46d2..8e4980d 100644 --- a/src/test/java/tests/usecases/BrowserFactoryTests.java +++ b/src/test/java/tests/usecases/BrowserFactoryTests.java @@ -9,7 +9,6 @@ import aquality.selenium.core.utilities.IActionRetrier; import aquality.selenium.core.utilities.ISettingsFile; import com.google.inject.Provider; -import io.github.bonigarcia.wdm.WebDriverManager; import org.openqa.selenium.SessionNotCreatedException; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebDriverException; @@ -53,7 +52,6 @@ public void testShouldBePossibleToSetFactory() { private IBrowserFactory getCustomFactory() { return () -> { FirefoxSettings firefoxSettings = new FirefoxSettings(AqualityServices.get(ISettingsFile.class)); - WebDriverManager.firefoxdriver().setup(); FirefoxOptions options = ((FirefoxOptions) firefoxSettings.getDriverOptions()).addArguments("--headless"); final List> handledExceptions = Arrays.asList( SessionNotCreatedException.class, diff --git a/src/test/java/tests/usecases/devtools/DeviceEmulationTest.java b/src/test/java/tests/usecases/devtools/DeviceEmulationTest.java index 346d7eb..c9a6c16 100644 --- a/src/test/java/tests/usecases/devtools/DeviceEmulationTest.java +++ b/src/test/java/tests/usecases/devtools/DeviceEmulationTest.java @@ -3,8 +3,8 @@ import aquality.selenium.browser.AqualityServices; import aquality.selenium.browser.devtools.EmulationHandling; import com.google.common.collect.ImmutableMap; -import org.openqa.selenium.devtools.v110.emulation.Emulation; -import org.openqa.selenium.devtools.v110.emulation.model.DisplayFeature; +import org.openqa.selenium.devtools.v117.emulation.Emulation; +import org.openqa.selenium.devtools.v117.emulation.model.DisplayFeature; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/src/test/java/tests/usecases/devtools/NetworkInterceptionTests.java b/src/test/java/tests/usecases/devtools/NetworkInterceptionTests.java index e8bada1..81134ee 100644 --- a/src/test/java/tests/usecases/devtools/NetworkInterceptionTests.java +++ b/src/test/java/tests/usecases/devtools/NetworkInterceptionTests.java @@ -4,7 +4,6 @@ import aquality.selenium.browser.devtools.NetworkHandling; import com.google.common.net.MediaType; import manytools.RequestHeadersForm; -import org.apache.hc.core5.http.HttpStatus; import org.openqa.selenium.devtools.NetworkInterceptor; import org.openqa.selenium.remote.http.HttpHandler; import org.openqa.selenium.remote.http.HttpRequest; @@ -40,7 +39,7 @@ public void testAllRequestsInterception() { WelcomeForm welcomeForm = new WelcomeForm(); NetworkInterceptor interceptor = network().interceptAllRequests(new HttpResponse() - .setStatus(HttpStatus.SC_OK) + .setStatus(200) .addHeader("Content-Type", MediaType.HTML_UTF_8.toString()) .setContent(utf8String(SOME_PHRASE))); Assert.assertNotNull(interceptor, "Network interceptor must not be null"); @@ -56,7 +55,7 @@ public void testAllRequestsInterception() { public void testRequestsInterception() { WelcomeForm welcomeForm = new WelcomeForm(); NetworkInterceptor interceptor = network().startNetworkInterceptor((HttpHandler) request -> new HttpResponse() - .setStatus(HttpStatus.SC_OK) + .setStatus(200) .addHeader("Content-Type", MediaType.HTML_UTF_8.toString()) .setContent(utf8String(SOME_PHRASE))); Assert.assertNotNull(interceptor, "Network interceptor must not be null"); diff --git a/src/test/java/tests/usecases/devtools/NetworkSpeedEmulationTest.java b/src/test/java/tests/usecases/devtools/NetworkSpeedEmulationTest.java index ead1a18..bfbc8ca 100644 --- a/src/test/java/tests/usecases/devtools/NetworkSpeedEmulationTest.java +++ b/src/test/java/tests/usecases/devtools/NetworkSpeedEmulationTest.java @@ -2,7 +2,7 @@ import aquality.selenium.browser.AqualityServices; import org.openqa.selenium.TimeoutException; -import org.openqa.selenium.devtools.v110.network.model.ConnectionType; +import org.openqa.selenium.devtools.v117.network.model.ConnectionType; import org.testng.Assert; import org.testng.annotations.Test; import tests.BaseTest; diff --git a/src/test/java/tests/usecases/devtools/OverrideUserAgentTest.java b/src/test/java/tests/usecases/devtools/OverrideUserAgentTest.java index 1a4386f..d8d0c06 100644 --- a/src/test/java/tests/usecases/devtools/OverrideUserAgentTest.java +++ b/src/test/java/tests/usecases/devtools/OverrideUserAgentTest.java @@ -5,7 +5,7 @@ import manytools.BrowserLanguageForm; import manytools.UserAgentForm; import org.openqa.selenium.devtools.idealized.Network; -import org.openqa.selenium.devtools.v110.emulation.Emulation; +import org.openqa.selenium.devtools.v117.emulation.Emulation; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/src/test/resources/settings.incorrect.json b/src/test/resources/settings.incorrect.json index 0e5c550..cf95279 100644 --- a/src/test/resources/settings.incorrect.json +++ b/src/test/resources/settings.incorrect.json @@ -6,7 +6,6 @@ "driverSettings": { "chrome": { - "webDriverVersion": "latest", "capabilities": { }, "options": { @@ -20,7 +19,6 @@ "startArguments": [] }, "firefox": { - "webDriverVersion": "latest", "capabilities": { }, "options": { @@ -41,8 +39,6 @@ "startArguments": [] }, "iexplorer": { - "webDriverVersion": "latest", - "systemArchitecture": "X32", "capabilities": { "ignoreProtectedModeSettings": true } diff --git a/src/test/resources/settings.json b/src/test/resources/settings.json index a20c520..65dda0a 100644 --- a/src/test/resources/settings.json +++ b/src/test/resources/settings.json @@ -1,12 +1,11 @@ { - "browserName" : "chrome", + "browserName" : "iexplorer", "isRemote": false, "remoteConnectionUrl": "http://localhost:4444/wd/hub", "isElementHighlightEnabled" : true, "driverSettings": { "chrome": { - "webDriverVersion": "latest", "capabilities": { }, "options": { @@ -23,7 +22,6 @@ "startArguments": [] }, "edge": { - "webDriverVersion": "latest", "capabilities": { }, "options": { @@ -40,7 +38,6 @@ "startArguments": [] }, "firefox": { - "webDriverVersion": "latest", "capabilities": { }, "options": { @@ -61,32 +58,14 @@ "startArguments": [] }, "iexplorer": { - "webDriverVersion": "latest", - "systemArchitecture": "X32", "capabilities": { "ignoreProtectedModeSettings": true } }, - "opera": { - "webDriverVersion": "latest", - "binaryLocation": "%USERPROFILE%\\AppData\\Local\\Programs\\Opera\\launcher.exe", - "capabilities": { - }, - "options": { - "intl.accept_languages": "en", - "safebrowsing.enabled": "true", - "profile.default_content_settings.popups": "0", - "disable-popup-blocking": "true", - "download.prompt_for_download": "false", - "download.default_directory": "./downloads" - }, - "startArguments": ["--remote-debugging-port=9222", "--no-sandbox", "--disable-dev-shm-usage"] - }, "safari": { "downloadDir": "/Users/username/Downloads" }, "yandex": { - "webDriverVersion": "102.0.5005.61", "binaryLocation": "%USERPROFILE%\\AppData\\Local\\Yandex\\YandexBrowser\\Application\\browser.exe", "capabilities": { }, diff --git a/src/test/resources/settings.local.json b/src/test/resources/settings.local.json index 1f82288..cddfee0 100644 --- a/src/test/resources/settings.local.json +++ b/src/test/resources/settings.local.json @@ -6,7 +6,6 @@ "driverSettings": { "chrome": { - "webDriverVersion": "latest", "capabilities": { }, "options": { @@ -23,8 +22,6 @@ "startArguments": [] }, "firefox": { - "webDriverVersion": "latest", - "systemArchitecture": "X32", "capabilities": { }, "options": { @@ -45,7 +42,6 @@ "startArguments": [] }, "iexplorer": { - "webDriverVersion": "latest", "capabilities": { "ignoreProtectedModeSettings": true } From dfc8ed68addb12979e7baa96dfa970f9bb05356c Mon Sep 17 00:00:00 2001 From: Aliaksej Mialeshka Date: Fri, 19 Jan 2024 20:50:24 +0100 Subject: [PATCH 2/4] remove exclusion --- pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pom.xml b/pom.xml index 2eb7393..e23c67a 100644 --- a/pom.xml +++ b/pom.xml @@ -99,12 +99,6 @@ testng 7.5.1 test - - - org.webjars - jquery - - From 34660a82963542aa69bd4c1572691b3de1a6f9e0 Mon Sep 17 00:00:00 2001 From: Aliaksej Mialeshka Date: Fri, 19 Jan 2024 21:27:31 +0100 Subject: [PATCH 3/4] Update tests --- src/test/java/forms/MyLocationForm.java | 11 ++++++++++- src/test/java/theinternet/forms/JQueryMenuForm.java | 2 +- src/test/java/theinternet/forms/TheInternetForm.java | 2 +- src/test/resources/settings.json | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/test/java/forms/MyLocationForm.java b/src/test/java/forms/MyLocationForm.java index 39f7007..2d94aed 100644 --- a/src/test/java/forms/MyLocationForm.java +++ b/src/test/java/forms/MyLocationForm.java @@ -1,5 +1,6 @@ package forms; +import aquality.selenium.elements.interfaces.IButton; import aquality.selenium.elements.interfaces.ILabel; import aquality.selenium.forms.Form; import org.openqa.selenium.By; @@ -8,13 +9,21 @@ public class MyLocationForm extends Form { private final ILabel lblLatitude = getElementFactory().getLabel(By.id("latitude"), "Latitude"); private final ILabel lblLongitude = getElementFactory().getLabel(By.id("longitude"), "Longitude"); + private final IButton btnConsent = getElementFactory().getButton(By.xpath("//button[@aria-label='Consent']"), "Consent"); public MyLocationForm() { super(By.xpath("//h1[contains(text(),'My Location')]"), "My Location"); } public double getLatitude() { - return Double.parseDouble(lblLatitude.getText()); + if (!lblLatitude.state().isDisplayed() && btnConsent.state().isDisplayed()) { + clickConsent(); + } + return Double.parseDouble(lblLatitude.getText()); + } + + public void clickConsent() { + btnConsent.click(); } public double getLongitude() { diff --git a/src/test/java/theinternet/forms/JQueryMenuForm.java b/src/test/java/theinternet/forms/JQueryMenuForm.java index 1b911be..fcbb9b0 100644 --- a/src/test/java/theinternet/forms/JQueryMenuForm.java +++ b/src/test/java/theinternet/forms/JQueryMenuForm.java @@ -5,7 +5,7 @@ import org.openqa.selenium.By; public class JQueryMenuForm extends TheInternetForm { - private final IButton btnEnabled = getElementFactory().getButton(By.id("ui-id-2"), "Enabled"); + private final IButton btnEnabled = getElementFactory().getButton(By.id("ui-id-3"), "Enabled"); public JQueryMenuForm(){ super(By.id("menu"), "JQueryUI menu"); diff --git a/src/test/java/theinternet/forms/TheInternetForm.java b/src/test/java/theinternet/forms/TheInternetForm.java index 67b8603..67bb737 100644 --- a/src/test/java/theinternet/forms/TheInternetForm.java +++ b/src/test/java/theinternet/forms/TheInternetForm.java @@ -10,7 +10,7 @@ public abstract class TheInternetForm extends Form { super(locator, name); } - private static final String THE_INTERNET_FORM_URL = "http://the-internet.herokuapp.com"; + private static final String THE_INTERNET_FORM_URL = "https://the-internet.herokuapp.com"; private final ILink elementalSeleniumLink = getElementFactory().getLink(By.xpath("//a[contains(@href,'elementalselenium')]"), "Elemental Selenium"); public String getUrl() { diff --git a/src/test/resources/settings.json b/src/test/resources/settings.json index 65dda0a..db5aad0 100644 --- a/src/test/resources/settings.json +++ b/src/test/resources/settings.json @@ -1,5 +1,5 @@ { - "browserName" : "iexplorer", + "browserName" : "chrome", "isRemote": false, "remoteConnectionUrl": "http://localhost:4444/wd/hub", "isElementHighlightEnabled" : true, From 079bb3561a56ddcf0e50ff743142505393fe5019 Mon Sep 17 00:00:00 2001 From: Aliaksej Mialeshka Date: Fri, 19 Jan 2024 21:42:16 +0100 Subject: [PATCH 4/4] Update the-internet URL in tests to use https --- src/test/java/theinternet/TheInternetPage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/theinternet/TheInternetPage.java b/src/test/java/theinternet/TheInternetPage.java index 80c1938..c987500 100644 --- a/src/test/java/theinternet/TheInternetPage.java +++ b/src/test/java/theinternet/TheInternetPage.java @@ -13,7 +13,7 @@ public enum TheInternetPage { TABLES, CHALLENGING_DOM; - private static final String BASE_URL = "http://the-internet.herokuapp.com/"; + private static final String BASE_URL = "https://the-internet.herokuapp.com/"; private final String postfix;