Skip to content

Commit

Permalink
Merge branch 'master' into futher_implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Davis committed Sep 4, 2023
2 parents d5c1ac3 + 7acc2f1 commit f7b132e
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.github.bordertech.common</groupId>
<artifactId>qa-parent</artifactId>
<version>1.0.19</version>
<version>1.0.20</version>
<relativePath />
</parent>

Expand Down
6 changes: 3 additions & 3 deletions webfriends-selenium-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>4.7.1</version>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.7.1</version>
<version>4.12.0</version>
</dependency>
<!-- Web Driver Manager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.3.1</version>
<version>5.5.2</version>
</dependency>

<!-- LDE API -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.github.bordertech.webfriends.selenium.util.driver.type.WebDriverType;
import io.github.bonigarcia.wdm.WebDriverManager;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.ArrayUtils;
Expand All @@ -24,6 +26,11 @@ public final class ConfigUtilProperties {
*/
private static final String SELENIUM_DRIVER_CAPABILITIES = DRIVER_PREFIX + "{0}.capabilities";

/**
* The arguments of each web driver.
*/
private static final String SELENIUM_DRIVER_ARGUMENTS = DRIVER_PREFIX + "{0}.arguments";

/**
* The list of driver type short names to use for the MultiBrowserRunner.
*/
Expand Down Expand Up @@ -104,13 +111,25 @@ private ConfigUtilProperties() {
* The WebDriver capabilities for the given driver type.
*
* @param driverType the driver type.
* @return the parameter value if set, or empty properties if not set.
* @return the capabilities set as property values, or empty properties if not set.
*/
public static Properties getDriverCapabilities(final String driverType) {
String paramName = MessageFormat.format(SELENIUM_DRIVER_CAPABILITIES, driverType);
return get().getProperties(paramName);
}

/**
* The WebDriver arguments for the given driver type.
*
* @param driverType the driver type.
* @return the list of arguments or empty list if not set
*/
public static List<String> getDriverArguments(final String driverType) {
String paramName = MessageFormat.format(SELENIUM_DRIVER_ARGUMENTS, driverType);
String values[] = get().getStringArray(paramName);
return Arrays.asList(values);
}

/**
* @param driver the driver short name
* @return the driver implementation parameter key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,35 @@ public interface WebDriverType<T extends WebDriver, M extends MutableCapabilitie
M getDefaultOptions();

/**
* @return the DesiredCapabilities configured from parameters.
* @return the options with the desired capabilities and arguments configured from parameters.
*/
default M getOptions() {
// Get default options
M capabilities = getDefaultOptions();
// Merge any ocerride options
Properties props = getOverrideOptions();
M options = getDefaultOptions();
handleOverrideCapabilities(options);
handleOverrideArguments(options);
return options;
}

/**
* Handle overriding capabilities from parameters.
*
* @param options the options to update
*/
default void handleOverrideCapabilities(M options) {
// Check for capability overrides from Parameters
Properties props = ConfigUtilProperties.getDriverCapabilities(getDriverTypeName());
for (Map.Entry<Object, Object> property : props.entrySet()) {
capabilities.setCapability((String) property.getKey(), property.getValue());
options.setCapability((String) property.getKey(), property.getValue());
}
return capabilities;
}

/**
* @return the default driver properties from properties file
* Handle overriding arguments from parameters.
*
* @param options the options to update
*/
default Properties getOverrideOptions() {
return ConfigUtilProperties.getDriverCapabilities(getDriverTypeName());
}
void handleOverrideArguments(M options);

/**
* @return the driver service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.bordertech.webfriends.selenium.util.driver.type;

import com.github.bordertech.webfriends.selenium.util.driver.ConfigUtilProperties;
import java.util.List;
import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.chromium.ChromiumOptions;
import org.openqa.selenium.remote.service.DriverService;

/**
* WebDriverType for Chromium based drivers.
*
* @param <T> the type of WebDriver returned
* @param <M> the options for the driver
* @param <D> the driver service
*/
public interface WebDriverTypeChromium<T extends ChromiumDriver, M extends ChromiumOptions, D extends DriverService> extends WebDriverType<T, M, D> {

@Override
default void handleOverrideArguments(M options) {
// Check for argument overrides from Parameters
List<String> arguments = ConfigUtilProperties.getDriverArguments(getDriverTypeName());
if (!arguments.isEmpty()) {
options.addArguments(arguments);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.bordertech.webfriends.selenium.util.driver.type.impl;

import com.github.bordertech.config.Config;
import com.github.bordertech.webfriends.selenium.util.driver.type.WebDriverType;
import com.github.bordertech.webfriends.selenium.util.driver.type.WebDriverTypeChromium;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
Expand All @@ -13,7 +13,7 @@
* Subclasses can override to alter the configuration or change the implementation.
* </p>
*/
public class ChromeWebDriverType implements WebDriverType<ChromeDriver, ChromeOptions, ChromeDriverService> {
public class ChromeWebDriverType implements WebDriverTypeChromium<ChromeDriver, ChromeOptions, ChromeDriverService> {

@Override
public String getDriverTypeName() {
Expand All @@ -30,12 +30,7 @@ public ChromeDriver getDriverInstance() {

@Override
public ChromeOptions getDefaultOptions() {
return new ChromeOptions();
}

@Override
public ChromeOptions getOptions() {
ChromeOptions options = WebDriverType.super.getOptions();
ChromeOptions options = new ChromeOptions();
if (Config.getInstance().getBoolean("bordertech.webfriends.chrome.headless", Boolean.FALSE)) {
options.addArguments("--headless");
options.addArguments("--no-sandbox");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.bordertech.webfriends.selenium.util.driver.type.impl;

import com.github.bordertech.webfriends.selenium.util.driver.type.WebDriverType;
import com.github.bordertech.webfriends.selenium.util.driver.type.WebDriverTypeChromium;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeDriverService;
Expand All @@ -12,7 +12,7 @@
* Subclasses can override to alter the configuration or change the implementation.
* </p>
*/
public class EdgeWebDriverType implements WebDriverType<EdgeDriver, EdgeOptions, EdgeDriverService> {
public class EdgeWebDriverType implements WebDriverTypeChromium<EdgeDriver, EdgeOptions, EdgeDriverService> {

@Override
public String getDriverTypeName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.bordertech.webfriends.selenium.util.driver.type.impl;

import com.github.bordertech.webfriends.selenium.util.driver.ConfigUtilProperties;
import com.github.bordertech.webfriends.selenium.util.driver.type.WebDriverType;
import io.github.bonigarcia.wdm.WebDriverManager;
import java.util.List;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.GeckoDriverService;
Expand Down Expand Up @@ -36,6 +38,15 @@ public FirefoxOptions getDefaultOptions() {
return opt;
}

@Override
public void handleOverrideArguments(final FirefoxOptions options) {
// Check for argument overrides from Parameters
List<String> arguments = ConfigUtilProperties.getDriverArguments(getDriverTypeName());
if (!arguments.isEmpty()) {
options.addArguments(arguments);
}
}

@Override
public GeckoDriverService getDriverService() {
return GeckoDriverService.createDefaultService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public InternetExplorerOptions getDefaultOptions() {
return options;
}

@Override
public void handleOverrideArguments(final InternetExplorerOptions options) {
// Do nothing
}

@Override
public InternetExplorerDriverService getDriverService() {
return InternetExplorerDriverService.createDefaultService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public SafariOptions getDefaultOptions() {
return new SafariOptions();
}

@Override
public void handleOverrideArguments(final SafariOptions options) {
// Do nothing
}

@Override
public SafariDriverService getDriverService() {
return SafariDriverService.createDefaultService();
Expand Down

0 comments on commit f7b132e

Please sign in to comment.