diff --git a/docs/modules/plugins/pages/plugin-web-app.adoc b/docs/modules/plugins/pages/plugin-web-app.adoc index effab78cc1..d91519f3e5 100644 --- a/docs/modules/plugins/pages/plugin-web-app.adoc +++ b/docs/modules/plugins/pages/plugin-web-app.adoc @@ -48,9 +48,9 @@ a|The command line (CLI) arguments to use when starting browser. `` is one of the browsers supporting CLI arguments: -* https://peter.sh/experiments/chromium-command-line-switches/[`CHROME`] -* https://www-archive.mozilla.org/docs/command-line-args/[`FIREFOX`], -* https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/general-info/hh826025(v=vs.85)?redirectedfrom=MSDN/[`IEXPLORE`]. +* https://peter.sh/experiments/chromium-command-line-switches/[`chrome`] +* https://www-archive.mozilla.org/docs/command-line-args/[`firefox`], +* https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/general-info/hh826025(v=vs.85)?redirectedfrom=MSDN/[`iexplore`]. |`web-application.sticky-header-size-percentage` |header size as a viewport size percent @@ -67,7 +67,7 @@ Here is an example how to configure third-party cookies behaviour. .Add the following property to allow all cookies [source,properties] ---- -web.driver.CHROME.experimental-options={"prefs": {"profile": {"cookie_controls_mode": 0}}} +web.driver.chrome.experimental-options={"prefs": {"profile": {"cookie_controls_mode": 0}}} ---- The allowed values for the preference from the example are: diff --git a/docs/modules/plugins/partials/plugin-web-app-profiles.adoc b/docs/modules/plugins/partials/plugin-web-app-profiles.adoc index 15aab55de1..4e0e534931 100644 --- a/docs/modules/plugins/partials/plugin-web-app-profiles.adoc +++ b/docs/modules/plugins/partials/plugin-web-app-profiles.adoc @@ -139,7 +139,7 @@ Chrome allows to emulate view on mobile devices using https://developer.chrome.c + [source, properties] ---- -web.driver.CHROME.mobile-emulation.device-name=DEVICE_NAME +web.driver.chrome.mobile-emulation.device-name=DEVICE_NAME ---- Available for emulation devices you can find in the https://developer.chrome.com/docs/devtools/device-mode/#device[Dimensions list] in chrome. @@ -149,8 +149,8 @@ In case you need to use https://developer.chrome.com/docs/devtools/device-mode/# + [source, properties] ---- -web.driver.CHROME.mobile-emulation.width=1440 -web.driver.CHROME.mobile-emulation.height=900 +web.driver.chrome.mobile-emulation.width=1440 +web.driver.chrome.mobile-emulation.height=900 ---- === Docker diff --git a/vividus-plugin-electron/src/main/java/org/vividus/electron/ApplicationSteps.java b/vividus-plugin-electron/src/main/java/org/vividus/electron/ApplicationSteps.java index 0d5fe4437a..741ef6dbe7 100644 --- a/vividus-plugin-electron/src/main/java/org/vividus/electron/ApplicationSteps.java +++ b/vividus-plugin-electron/src/main/java/org/vividus/electron/ApplicationSteps.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 the original author or authors. + * Copyright 2019-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ public ApplicationSteps(IWebDriverProvider webDriverProvider) /** * Starts Electron application by creation of chrome driver session; * Please mind that you should pass path to an executable via property: - *
web.driver.CHROME.binary-path + *
web.driver.chrome.binary-path */ @Given("I start electron application") public void startApplication() diff --git a/vividus-plugin-electron/src/main/resources/properties/profile/desktop/electron/profile.properties b/vividus-plugin-electron/src/main/resources/properties/profile/desktop/electron/profile.properties index c7c0c2deb4..9615926604 100644 --- a/vividus-plugin-electron/src/main/resources/properties/profile/desktop/electron/profile.properties +++ b/vividus-plugin-electron/src/main/resources/properties/profile/desktop/electron/profile.properties @@ -6,6 +6,6 @@ selenium.screenshot.strategy=SIMPLE electron-app.command-line-arguments= -web.driver.CHROME.binary-path=${electron-app.binary-path} +web.driver.chrome.binary-path=${electron-app.binary-path} system.wdm.chromeDriverVersion=${electron-app.chromium-version} -web.driver.CHROME.command-line-arguments=${electron-app.command-line-arguments} +web.driver.crhome.command-line-arguments=${electron-app.command-line-arguments} diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/selenium/WebDriverFactory.java b/vividus-plugin-web-app/src/main/java/org/vividus/selenium/WebDriverFactory.java index af1d54755f..0e99d7d326 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/selenium/WebDriverFactory.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/selenium/WebDriverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 the original author or authors. + * Copyright 2019-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -183,8 +183,9 @@ private void checkCommandLineArgumentsSupported(WebDriverType webDriverType) private Optional getPropertyValue(String propertyKey, WebDriverType webDriverType) { - return Optional - .ofNullable(getPropertyParser().getPropertyValue("web.driver." + webDriverType + "." + propertyKey)); + return Optional.ofNullable( + getPropertyParser().getPropertyValue("web.driver.%s.%s", webDriverType.toString().toLowerCase(), + propertyKey)); } public void setWebDriverType(WebDriverType webDriverType) diff --git a/vividus-plugin-web-app/src/main/resources/properties/deprecated/deprecated.properties b/vividus-plugin-web-app/src/main/resources/properties/deprecated/deprecated.properties index 9fc750f6db..25ffb12096 100644 --- a/vividus-plugin-web-app/src/main/resources/properties/deprecated/deprecated.properties +++ b/vividus-plugin-web-app/src/main/resources/properties/deprecated/deprecated.properties @@ -1 +1,8 @@ -web\.driver\.edge_chromium.driver-executable-path=web.driver.edge.driver-executable-path +web\\.driver\\.edge_chromium.driver-executable-path=web.driver.edge.driver-executable-path + +web\\.driver\\.CHROME\\.(.+)=web.driver.chrome.$1 +web\\.driver\\.EDGE\\.(.+)=web.driver.edge.$1 +web\\.driver\\.FIREFOX\\.(.+)=web.driver.firefox.$1 +web\\.driver\\.IEXPLORE\\.(.+)=web.driver.iexplore.$1 +web\\.driver\\.OPERA\\.(.+)=web.driver.opera.$1 +web\\.driver\\.SAFARI\\.(.+)=web.driver.safari.$1 diff --git a/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/phone/profile.properties b/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/phone/profile.properties index 176474e5e7..2a1f19e2e2 100644 --- a/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/phone/profile.properties +++ b/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/phone/profile.properties @@ -1,4 +1,4 @@ bdd.all-meta-filters=groovy: layout && layout.toString().tokenize(' ').contains('chrome_phone') && !skip && (${bdd.meta-filters}) -web.driver.CHROME.experimental-options={"mobileEmulation": {"deviceName": "${web.driver.CHROME.mobile-emulation.device-name}"}} -web.driver.CHROME.mobile-emulation.device-name=iPhone 8 +web.driver.chrome.experimental-options={"mobileEmulation": {"deviceName": "${web.driver.chrome.mobile-emulation.device-name}"}} +web.driver.chrome.mobile-emulation.device-name=iPhone 8 diff --git a/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/responsive/profile.properties b/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/responsive/profile.properties index 7423cdb3de..d36c4dcc21 100644 --- a/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/responsive/profile.properties +++ b/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/responsive/profile.properties @@ -1,11 +1,11 @@ bdd.all-meta-filters=groovy: layout && layout.toString().tokenize(' ').contains('chrome_responsive') && !skip && (${bdd.meta-filters}) -web.driver.CHROME.experimental-options={"mobileEmulation": {"deviceMetrics": \ +web.driver.chrome.experimental-options={"mobileEmulation": {"deviceMetrics": \ {\ - "width":${web.driver.CHROME.mobile-emulation.width},\ - "height": ${web.driver.CHROME.mobile-emulation.height},\ + "width":${web.driver.chrome.mobile-emulation.width},\ + "height": ${web.driver.chrome.mobile-emulation.height},\ "pixelRatio": 2.0\ },\ "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19"}} -web.driver.CHROME.mobile-emulation.width=408 -web.driver.CHROME.mobile-emulation.height=887 +web.driver.chrome.mobile-emulation.width=408 +web.driver.chrome.mobile-emulation.height=887 diff --git a/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/tablet/profile.properties b/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/tablet/profile.properties index 2a606b3b00..86a7e1da6c 100644 --- a/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/tablet/profile.properties +++ b/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/chrome/mobile_emulation/tablet/profile.properties @@ -1,4 +1,4 @@ bdd.all-meta-filters=groovy: layout && layout.toString().tokenize(' ').contains('chrome_tablet') && !skip && (${bdd.meta-filters}) -web.driver.CHROME.experimental-options={"mobileEmulation": {"deviceName": "${web.driver.CHROME.mobile-emulation.device-name}"}} -web.driver.CHROME.mobile-emulation.device-name=iPad +web.driver.chrome.experimental-options={"mobileEmulation": {"deviceName": "${web.driver.chrome.mobile-emulation.device-name}"}} +web.driver.chrome.mobile-emulation.device-name=iPad diff --git a/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/opera/profile.properties b/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/opera/profile.properties index 04c1eba1c2..8be71f4385 100644 --- a/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/opera/profile.properties +++ b/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/opera/profile.properties @@ -2,4 +2,4 @@ selenium.browser=opera selenium.grid.screen-resolution=1920x1080 -web.driver.OPERA.binary-path= +web.driver.opera.binary-path= diff --git a/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/profile.properties b/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/profile.properties index f06ad89ec6..f0397fc739 100644 --- a/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/profile.properties +++ b/vividus-plugin-web-app/src/main/resources/properties/profile/web/desktop/profile.properties @@ -10,8 +10,8 @@ selenium.screenshot.strategy=VIEWPORT_PASTING selenium.screenshot.full-page=false selenium.screenshot.highlighter=MONOCHROME -#web.driver.[WEB-DRIVER-TYPE].driver-executable-path=/path/to/driver/executable -#web.driver.[WEB-DRIVER-TYPE].binary-path=/path/to/custom/browser -# [WEB-DRIVER-TYPE] is one of the supported web driver types. For example: -#web.driver.CHROME.driver-executable-path=/path/to/chromedriver.exe -#web.driver.CHROME.binary-path=/path/to/custom/chrome +#web.driver.[web-driver-type].driver-executable-path=/path/to/driver/executable +#web.driver.[web-driver-type].binary-path=/path/to/custom/browser +# [web-driver-type] is one of the supported web driver types. For example: +#web.driver.chrome.driver-executable-path=/path/to/chromedriver.exe +#web.driver.chrome.binary-path=/path/to/custom/chrome diff --git a/vividus-plugin-web-app/src/main/resources/properties/profile/web/headless/chrome/profile.properties b/vividus-plugin-web-app/src/main/resources/properties/profile/web/headless/chrome/profile.properties index 6445f9d63a..ddd74ee2fa 100644 --- a/vividus-plugin-web-app/src/main/resources/properties/profile/web/headless/chrome/profile.properties +++ b/vividus-plugin-web-app/src/main/resources/properties/profile/web/headless/chrome/profile.properties @@ -1,2 +1,2 @@ selenium.browser=chrome -web.driver.CHROME.command-line-arguments=--headless --hide-scrollbars +web.driver.chrome.command-line-arguments=--headless --hide-scrollbars diff --git a/vividus-plugin-web-app/src/test/java/org/vividus/selenium/WebDriverFactoryTests.java b/vividus-plugin-web-app/src/test/java/org/vividus/selenium/WebDriverFactoryTests.java index d117cb34a1..735d64a666 100644 --- a/vividus-plugin-web-app/src/test/java/org/vividus/selenium/WebDriverFactoryTests.java +++ b/vividus-plugin-web-app/src/test/java/org/vividus/selenium/WebDriverFactoryTests.java @@ -33,7 +33,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.net.MalformedURLException; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -83,14 +82,17 @@ class WebDriverFactoryTests private static final String TRUE = "true"; private static final String KEY2 = "key2"; private static final String KEY1 = "key1"; - private static final String BINARY_PATH_PROPERTY_FORMAT = "web.driver.%s.binary-path"; - private static final String COMMAND_LINE_ARGUMENTS_PROPERTY_FORMAT = "web.driver.%s.command-line-arguments"; - private static final String EXPERIMENTAL_OPTIONS_PROPERTY_FORMAT = "web.driver.%s.experimental-options"; + private static final String PROPERTY_FORMAT = "web.driver.%s.%s"; + private static final String BINARY_PATH = "binary-path"; + private static final String COMMAND_LINE_ARGUMENTS = "command-line-arguments"; + private static final String EXPERIMENTAL_OPTIONS = "experimental-options"; private static final String CLI_ARGS_NOT_SUPPORTED = "Configuring of command-line-arguments is not supported for "; private static final String PATH = "testPath"; private static final String ARG_1 = "--arg1"; private static final String ARG_2 = "--arg2"; private static final String ARGS = ARG_1 + " " + ARG_2; + private static final String CHROME_BROWSER_NAME = "chrome"; + private static final String FIREFOX_BROWSER_NAME = "firefox"; private final TestLogger logger = TestLoggerFactory.getTestLogger(AbstractWebDriverFactory.class); @@ -130,9 +132,9 @@ void testGetWebDriverWithWebDriverType(boolean proxyStarted, Boolean acceptsInsecureCerts) throws IllegalAccessException { mockCapabilities((HasCapabilities) driver); - WebDriverType webDriverType = mock(WebDriverType.class); + WebDriverType webDriverType = mock(); webDriverFactory.setWebDriverType(webDriverType); - WebDriverConfiguration configuration = mock(WebDriverConfiguration.class); + WebDriverConfiguration configuration = mock(); Map capabilities = Map.of(KEY1, TRUE, KEY2, FALSE); when(propertyParser.getPropertyValuesTreeByPrefix(SELENIUM_CAPABILITIES)).thenReturn(capabilities); when(proxy.isStarted()).thenReturn(proxyStarted); @@ -159,10 +161,10 @@ void testGetWebDriverWithWebDriverTypeWOBinary() throws IllegalAccessException { mockCapabilities((HasCapabilities) driver); WebDriverConfiguration configuration = new WebDriverConfiguration(); - WebDriverType webDriverType = mock(WebDriverType.class); + WebDriverType webDriverType = mock(); webDriverFactory.setWebDriverType(webDriverType); injectConfigurations(webDriverType, configuration); - DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); + DesiredCapabilities desiredCapabilities = mock(); when(webDriverType.getWebDriver(new DesiredCapabilities(), configuration)).thenReturn(driver); Timeouts timeouts = mockTimeouts(driver); assertEquals(driver, ((WrapsDriver) webDriverFactory.getWebDriver(desiredCapabilities)).getWrappedDriver()); @@ -174,14 +176,15 @@ void testGetWebDriverWithWebDriverTypeWOBinary() throws IllegalAccessException void testGetWebDriverWithWebDriverTypeAndBinaryPathConfiguration() { mockCapabilities((HasCapabilities) driver); - WebDriverType webDriverType = mock(WebDriverType.class); + WebDriverType webDriverType = mock(); + when(webDriverType.toString()).thenReturn(WebDriverType.EDGE.toString()); when(webDriverType.isBinaryPathSupported()).thenReturn(Boolean.TRUE); webDriverFactory.setWebDriverType(webDriverType); - lenient().when(propertyParser.getPropertyValue("web.driver." + webDriverType + ".driver-executable-path")) + String browserName = "edge"; + lenient().when(propertyParser.getPropertyValue(PROPERTY_FORMAT, browserName, "driver-executable-path")) .thenReturn(PATH); - lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType))) - .thenReturn(PATH); - DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); + lenient().when(propertyParser.getPropertyValue(PROPERTY_FORMAT, browserName, BINARY_PATH)).thenReturn(PATH); + DesiredCapabilities desiredCapabilities = mock(); when(webDriverType.getWebDriver(eq(new DesiredCapabilities()), argThat(config -> Optional.of(PATH).equals(config.getBinaryPath()) && Optional.of(PATH).equals(config.getDriverExecutablePath())))).thenReturn(driver); @@ -196,15 +199,15 @@ void testGetWebDriverWithWebDriverTypeAndBinaryPathConfiguration() void testGetWebDriverWithWebDriverTypeAndCommandLineArgumentsConfiguration() { mockCapabilities((HasCapabilities) driver); - WebDriverType webDriverType = mock(WebDriverType.class); + WebDriverType webDriverType = mock(); + when(webDriverType.toString()).thenReturn(WebDriverType.FIREFOX.toString()); when(webDriverType.isCommandLineArgumentsSupported()).thenReturn(Boolean.TRUE); webDriverFactory.setWebDriverType(webDriverType); - lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType))) - .thenReturn(null); - lenient().when( - propertyParser.getPropertyValue(String.format(COMMAND_LINE_ARGUMENTS_PROPERTY_FORMAT, webDriverType))) + String browserName = FIREFOX_BROWSER_NAME; + lenient().when(propertyParser.getPropertyValue(PROPERTY_FORMAT, browserName, BINARY_PATH)).thenReturn(null); + lenient().when(propertyParser.getPropertyValue(PROPERTY_FORMAT, browserName, COMMAND_LINE_ARGUMENTS)) .thenReturn(ARGS); - DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); + DesiredCapabilities desiredCapabilities = mock(); when(webDriverType.getWebDriver(eq(new DesiredCapabilities()), argThat(config -> Arrays.equals(new String[] { ARG_1, ARG_2 }, config.getCommandLineArguments())))) .thenReturn(driver); @@ -219,14 +222,17 @@ void testGetWebDriverWithWebDriverTypeAndCommandLineArgumentsConfiguration() void testGetWebDriverWithCommandLineArgumentsOverride() { mockCapabilities((HasCapabilities) driver); - WebDriverType webDriverType = mock(WebDriverType.class); + WebDriverType webDriverType = mock(); + when(webDriverType.toString()).thenReturn(WebDriverType.CHROME.toString()); when(webDriverType.isCommandLineArgumentsSupported()).thenReturn(Boolean.TRUE); webDriverFactory.setWebDriverType(webDriverType); - lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType))) + lenient().when( + propertyParser.getPropertyValue(String.format(PROPERTY_FORMAT, CHROME_BROWSER_NAME, + BINARY_PATH))) .thenReturn(null); when(webDriverStartContext.get(WebDriverStartParameters.COMMAND_LINE_ARGUMENTS)) .thenReturn(ARGS); - DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); + DesiredCapabilities desiredCapabilities = mock(); when(webDriverType.getWebDriver(eq(new DesiredCapabilities()), argThat(config -> Arrays.equals(new String[] { ARG_1, ARG_2 }, config.getCommandLineArguments())))) .thenReturn(driver); @@ -240,13 +246,14 @@ void testGetWebDriverWithCommandLineArgumentsOverride() @Test void testGetWebDriverWithCommandLineArgumentsOverrideNotSupported() { - WebDriverType webDriverType = mock(WebDriverType.class); + WebDriverType webDriverType = mock(); + when(webDriverType.toString()).thenReturn(WebDriverType.CHROME.toString()); webDriverFactory.setWebDriverType(webDriverType); when(webDriverType.isCommandLineArgumentsSupported()).thenReturn(Boolean.FALSE); - lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType))) - .thenReturn(null); + lenient().when(propertyParser.getPropertyValue(PROPERTY_FORMAT, CHROME_BROWSER_NAME, BINARY_PATH)).thenReturn( + null); when(webDriverStartContext.get(WebDriverStartParameters.COMMAND_LINE_ARGUMENTS)).thenReturn(ARG_1); - DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); + DesiredCapabilities desiredCapabilities = mock(); UnsupportedOperationException exception = assertThrows(UnsupportedOperationException.class, () -> webDriverFactory.getWebDriver(desiredCapabilities)); assertEquals(CLI_ARGS_NOT_SUPPORTED + webDriverType, exception.getMessage()); @@ -256,14 +263,14 @@ void testGetWebDriverWithCommandLineArgumentsOverrideNotSupported() void testGetWebDriverWithWebDriverTypeAndExperimentalOptionsConfiguration() { mockCapabilities((HasCapabilities) driver); - WebDriverType webDriverType = mock(WebDriverType.class); + WebDriverType webDriverType = mock(); + when(webDriverType.toString()).thenReturn(WebDriverType.CHROME.toString()); webDriverFactory.setWebDriverType(webDriverType); - lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType))) - .thenReturn(null); - lenient().when( - propertyParser.getPropertyValue(String.format(EXPERIMENTAL_OPTIONS_PROPERTY_FORMAT, webDriverType))) + lenient().when(propertyParser.getPropertyValue(PROPERTY_FORMAT, CHROME_BROWSER_NAME, BINARY_PATH)).thenReturn( + null); + lenient().when(propertyParser.getPropertyValue(PROPERTY_FORMAT, CHROME_BROWSER_NAME, EXPERIMENTAL_OPTIONS)) .thenReturn("{\"mobileEmulation\": {\"deviceName\": \"iPhone 8\"}}"); - DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); + DesiredCapabilities desiredCapabilities = mock(); when(webDriverType.getWebDriver(eq(new DesiredCapabilities()), argThat(config -> Map.of("mobileEmulation", Map.of("deviceName", "iPhone 8")) .equals(config.getExperimentalOptions())))).thenReturn(driver); @@ -277,12 +284,12 @@ void testGetWebDriverWithWebDriverTypeAndExperimentalOptionsConfiguration() @Test void testGetWebDriverWithWebDriverTypeAndInvalidBinaryPathConfiguration() { - WebDriverType webDriverType = mock(WebDriverType.class); + WebDriverType webDriverType = mock(); + when(webDriverType.toString()).thenReturn(WebDriverType.OPERA.toString()); webDriverFactory.setWebDriverType(webDriverType); when(webDriverType.isBinaryPathSupported()).thenReturn(Boolean.FALSE); - when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType))).thenReturn( - PATH); - DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); + when(propertyParser.getPropertyValue(PROPERTY_FORMAT, "opera", BINARY_PATH)).thenReturn(PATH); + DesiredCapabilities desiredCapabilities = mock(); UnsupportedOperationException exception = assertThrows(UnsupportedOperationException.class, () -> webDriverFactory.getWebDriver(desiredCapabilities)); assertEquals("Configuring of binary-path is not supported for " + webDriverType, exception.getMessage()); @@ -291,22 +298,22 @@ void testGetWebDriverWithWebDriverTypeAndInvalidBinaryPathConfiguration() @Test void testGetWebDriverWithWebDriverTypeAndInvalidCommandLineArgumentsConfiguration() { - WebDriverType webDriverType = mock(WebDriverType.class); + WebDriverType webDriverType = mock(); + when(webDriverType.toString()).thenReturn(WebDriverType.CHROME.toString()); webDriverFactory.setWebDriverType(webDriverType); when(webDriverType.isCommandLineArgumentsSupported()).thenReturn(Boolean.FALSE); - lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType))) - .thenReturn(null); - lenient().when( - propertyParser.getPropertyValue(String.format(COMMAND_LINE_ARGUMENTS_PROPERTY_FORMAT, webDriverType))) + lenient().when(propertyParser.getPropertyValue(PROPERTY_FORMAT, CHROME_BROWSER_NAME, BINARY_PATH)).thenReturn( + null); + lenient().when(propertyParser.getPropertyValue(PROPERTY_FORMAT, CHROME_BROWSER_NAME, COMMAND_LINE_ARGUMENTS)) .thenReturn(ARG_1); - DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); + DesiredCapabilities desiredCapabilities = mock(); UnsupportedOperationException exception = assertThrows(UnsupportedOperationException.class, () -> webDriverFactory.getWebDriver(desiredCapabilities)); assertEquals(CLI_ARGS_NOT_SUPPORTED + webDriverType, exception.getMessage()); } @Test - void testGetRemoteWebDriver() throws Exception + void testGetRemoteWebDriver() { mockCapabilities(remoteWebDriver); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); @@ -321,7 +328,6 @@ void testGetRemoteWebDriver() throws Exception @ParameterizedTest @CsvSource({"chrome, true", "internet explorer,", "SAFARI,"}) void shouldSetAcceptInsecureCertsForSupportingBrowsers(String type, Boolean acceptsInsecureCerts) - throws MalformedURLException { mockCapabilities(remoteWebDriver); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); @@ -341,7 +347,7 @@ void shouldSetAcceptInsecureCertsForSupportingBrowsers(String type, Boolean acce @Test @SuppressWarnings("unchecked") - void testGetRemoteWebDriverFirefoxDriver() throws MalformedURLException + void testGetRemoteWebDriverFirefoxDriver() { mockCapabilities(remoteWebDriver); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(new FirefoxOptions()); @@ -350,7 +356,7 @@ void testGetRemoteWebDriverFirefoxDriver() throws MalformedURLException Map options = (Map) caps.getCapability(FirefoxOptions.FIREFOX_OPTIONS); Map prefs = (Map) options.get("prefs"); return "about:blank".equals(prefs.get("startup.homepage_welcome_url.additional")) - && "firefox".equals(caps.getBrowserName()); + && FIREFOX_BROWSER_NAME.equals(caps.getBrowserName()); }))).thenReturn(remoteWebDriver); Timeouts timeouts = mockTimeouts(remoteWebDriver); assertEquals(remoteWebDriver, @@ -366,7 +372,7 @@ void testGetRemoteWebDriverFirefoxDriver() throws MalformedURLException } @Test - void testGetRemoteWebDriverMarionetteDriver() throws Exception + void testGetRemoteWebDriverMarionetteDriver() { mockCapabilities(remoteWebDriver); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); @@ -381,7 +387,7 @@ void testGetRemoteWebDriverMarionetteDriver() throws Exception } @Test - void testGetRemoteWebDriverIEDriver() throws MalformedURLException + void testGetRemoteWebDriverIEDriver() { mockCapabilities(remoteWebDriver); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); @@ -397,26 +403,26 @@ void testGetRemoteWebDriverIEDriver() throws MalformedURLException } @Test - void testGetRemoteWebDriverIsChromeWithAdditionalOptions() throws Exception + void testGetRemoteWebDriverIsChromeWithAdditionalOptions() { String args = "disable-blink-features=BlockCredentialedSubresources"; ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments(args); chromeOptions.setExperimentalOption("w3c", Boolean.TRUE); - lenient().doReturn(args).when(propertyParser).getPropertyValue( - String.format(COMMAND_LINE_ARGUMENTS_PROPERTY_FORMAT, WebDriverType.CHROME)); - lenient().doReturn("{\"w3c\":true}").when(propertyParser).getPropertyValue( - String.format(EXPERIMENTAL_OPTIONS_PROPERTY_FORMAT, WebDriverType.CHROME)); + lenient().doReturn(args).when(propertyParser).getPropertyValue(PROPERTY_FORMAT, CHROME_BROWSER_NAME, + COMMAND_LINE_ARGUMENTS); + lenient().doReturn("{\"w3c\":true}").when(propertyParser).getPropertyValue(PROPERTY_FORMAT, CHROME_BROWSER_NAME, + EXPERIMENTAL_OPTIONS); testGetRemoteWebDriverIsChrome(chromeOptions); } @Test - void testGetRemoteWebDriverIsChromeWithoutAdditionalOptions() throws Exception + void testGetRemoteWebDriverIsChromeWithoutAdditionalOptions() { testGetRemoteWebDriverIsChrome(new ChromeOptions()); } - private void testGetRemoteWebDriverIsChrome(ChromeOptions chromeOptions) throws MalformedURLException + private void testGetRemoteWebDriverIsChrome(ChromeOptions chromeOptions) { mockCapabilities(remoteWebDriver); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); @@ -432,7 +438,7 @@ private void testGetRemoteWebDriverIsChrome(ChromeOptions chromeOptions) throws private static void mockCapabilities(HasCapabilities hasCapabilities) { - Capabilities capabilities = mock(Capabilities.class); + Capabilities capabilities = mock(); when(hasCapabilities.getCapabilities()).thenReturn(capabilities); when(capabilities.asMap()).thenReturn(CAPS); } @@ -451,9 +457,9 @@ private void assertLogger(String sessionCaps) private static Timeouts mockTimeouts(WebDriver webDriver) { - Options options = mock(Options.class); + Options options = mock(); when(webDriver.manage()).thenReturn(options); - Timeouts timeouts = mock(Timeouts.class); + Timeouts timeouts = mock(); when(options.timeouts()).thenReturn(timeouts); return timeouts; }