Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit b89664d

Browse files
committed
added ability to configure other driver locations in WebTester configuration as well
1 parent dae96e2 commit b89664d

File tree

15 files changed

+83
-97
lines changed

15 files changed

+83
-97
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
<!-- dependency versions -->
6363

64-
<version.testutils>0.1.beta1</version.testutils>
64+
<version.testutils>0.2</version.testutils>
6565
<version.junit4>4.12</version.junit4>
6666
<version.junit5.jupiter>5.0.0-M3</version.junit5.jupiter>
6767
<version.junit5.vintage>4.12.0-M3</version.junit5.vintage>

webtester-core/src/main/java/info/novatec/testit/webtester/browser/BrowserFactory.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
* <p>
1313
* The most important method of a browser factory is {@link #createBrowser()}.
1414
* It is used by all kinds of reflection based operations to initialize a
15-
* browser using all the implemented defaults of the actual factory
16-
* implementation. For more flexibility the
17-
* {@link #createBrowser(DesiredCapabilities)} and
18-
* {@link #createBrowser(WebDriver)} methods can be used to create instances
19-
* based on pre-initialized objects while still setting some common properties
20-
* with a default implementation.
15+
* browser using all the defaults of the actual factory implementation.
16+
* For more flexibility the {@link #createBrowser(DesiredCapabilities)} method
17+
* can be used to create instances based on your desired capabilities while still setting
18+
* some common properties with a default implementation.
2119
* <p>
2220
* The difference between a browser factory and a {@link BrowserBuilder browser
2321
* builder} is in how they are used. Factories are used to initialize a
@@ -77,17 +75,6 @@ public interface BrowserFactory {
7775
*/
7876
Browser createBrowser(DesiredCapabilities capabilities);
7977

80-
/**
81-
* Creates a {@link Browser browser} using the given pre-initialized
82-
* {@link WebDriver web driver} and the {@link BrowserFactory factory's}
83-
* defaults.
84-
*
85-
* @param webDriver the web driver to use
86-
* @return the created browser
87-
* @since 2.0
88-
*/
89-
Browser createBrowser(WebDriver webDriver);
90-
9178
/**
9279
* Defines a {@link ProxyConfiguration proxy configuration} to use when
9380
* creating a {@link Browser browser} with this {@link BrowserFactory

webtester-core/src/main/java/info/novatec/testit/webtester/browser/factories/BaseBrowserFactory.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ public Browser createBrowser(DesiredCapabilities capabilities) {
6060
return WebDriverBrowser.forWebDriver(webDriverProducer.apply(capabilities)).withConfiguration(configuration).build();
6161
}
6262

63-
@Override
64-
public Browser createBrowser(WebDriver webDriver) {
65-
Configuration configuration = new DefaultConfigurationBuilder().build();
66-
postProcessConfiguration(configuration);
67-
return WebDriverBrowser.forWebDriver(webDriver).withConfiguration(configuration).build();
68-
}
69-
7063
protected void setOptionalProxyConfiguration(DesiredCapabilities capabilities) {
7164
if (proxyConfiguration != null && !(proxyConfiguration instanceof NoProxyConfiguration)) {
7265
Proxy proxy = new Proxy();

webtester-core/src/main/java/info/novatec/testit/webtester/browser/factories/ChromeFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
*/
2626
public class ChromeFactory extends BaseBrowserFactory<ChromeFactory> {
2727

28-
private static final String CHROME_DRIVER_LOCATION = "webdriver.chrome.driver";
28+
private static final String DRIVER_LOCATION = "webdriver.chrome.driver";
2929

3030
public ChromeFactory() {
3131
super(ChromeDriver::new);
3232
}
3333

3434
@Override
3535
protected void postProcessConfiguration(Configuration configuration) {
36-
configuration.getStringProperty(CHROME_DRIVER_LOCATION).ifPresent(driverLocation -> {
37-
System.setProperty(CHROME_DRIVER_LOCATION, driverLocation);
36+
configuration.getStringProperty(DRIVER_LOCATION).ifPresent(driverLocation -> {
37+
System.setProperty(DRIVER_LOCATION, driverLocation);
3838
});
3939
}
4040

webtester-core/src/main/java/info/novatec/testit/webtester/browser/factories/EdgeFactory.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package info.novatec.testit.webtester.browser.factories;
22

3-
import info.novatec.testit.webtester.browser.Browser;
43
import org.openqa.selenium.edge.EdgeDriver;
5-
import org.openqa.selenium.edge.EdgeDriverService;
6-
import org.openqa.selenium.remote.DesiredCapabilities;
4+
5+
import info.novatec.testit.webtester.browser.Browser;
6+
import info.novatec.testit.webtester.config.Configuration;
7+
78

89
/**
910
* Factory class for creating Microsoft Edge {@link Browser} instances.
@@ -21,14 +22,17 @@
2122
*/
2223
public class EdgeFactory extends BaseBrowserFactory<EdgeFactory> {
2324

25+
private static final String DRIVER_LOCATION = "webdriver.edge.driver";
26+
2427
public EdgeFactory() {
2528
super(EdgeDriver::new);
2629
}
2730

28-
public Browser createBrowser() {
29-
EdgeDriverService service = EdgeDriverService.createDefaultService();
30-
DesiredCapabilities capabilities = getDefaultCapabilities();
31-
return createBrowser(new EdgeDriver(service, capabilities));
31+
@Override
32+
protected void postProcessConfiguration(Configuration configuration) {
33+
configuration.getStringProperty(DRIVER_LOCATION).ifPresent(driverLocation -> {
34+
System.setProperty(DRIVER_LOCATION, driverLocation);
35+
});
3236
}
3337

3438
}

webtester-core/src/main/java/info/novatec/testit/webtester/browser/factories/InternetExplorerFactory.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package info.novatec.testit.webtester.browser.factories;
22

33
import org.openqa.selenium.ie.InternetExplorerDriver;
4-
import org.openqa.selenium.ie.InternetExplorerDriverService;
5-
import org.openqa.selenium.remote.DesiredCapabilities;
64

75
import info.novatec.testit.webtester.browser.Browser;
6+
import info.novatec.testit.webtester.config.Configuration;
87

98

109
/**
@@ -26,14 +25,17 @@
2625
*/
2726
public class InternetExplorerFactory extends BaseBrowserFactory<InternetExplorerFactory> {
2827

28+
private static final String DRIVER_LOCATION = "webdriver.ie.driver";
29+
2930
public InternetExplorerFactory() {
3031
super(InternetExplorerDriver::new);
3132
}
3233

33-
public Browser createBrowser(int port) {
34-
InternetExplorerDriverService service = InternetExplorerDriverService.createDefaultService();
35-
DesiredCapabilities capabilities = getDefaultCapabilities();
36-
return createBrowser(new InternetExplorerDriver(service, capabilities, port));
34+
@Override
35+
protected void postProcessConfiguration(Configuration configuration) {
36+
configuration.getStringProperty(DRIVER_LOCATION).ifPresent(driverLocation -> {
37+
System.setProperty(DRIVER_LOCATION, driverLocation);
38+
});
3739
}
3840

3941
}

webtester-core/src/main/java/info/novatec/testit/webtester/browser/factories/MarionetteFactory.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import org.openqa.selenium.firefox.FirefoxDriver;
44

55
import info.novatec.testit.webtester.browser.Browser;
6+
import info.novatec.testit.webtester.config.Configuration;
67

78

89
/**
910
* Factory class for creating Firefox {@link Browser} instances.
11+
* Needs the {@code webdriver.gecko.driver} system property pointing to the driver proxy server executable.
1012
* This will only work for Firefox browsers version 47 and above!
1113
* All older versions should be initialized using the {@link FirefoxFactory}.
1214
* <p>
@@ -16,8 +18,10 @@
1618
* <li>Unsigned certificates are accepted</li>
1719
* </ul>
1820
* <b>Additional information on using the {@link FirefoxDriver}:</b>
19-
* <p>
20-
* https://github.com/SeleniumHQ/selenium/wiki/FirefoxDriver
21+
* <ul>
22+
* <li>https://github.com/SeleniumHQ/selenium/wiki/FirefoxDriver</li>
23+
* <li>https://github.com/mozilla/geckodriver</li>
24+
* </ul>
2125
*
2226
* @see Browser
2327
* @see FirefoxDriver
@@ -26,11 +30,20 @@
2630
*/
2731
public class MarionetteFactory extends BaseBrowserFactory<MarionetteFactory> {
2832

33+
private static final String DRIVER_LOCATION = "webdriver.gecko.driver";
34+
2935
public MarionetteFactory() {
3036
super((capabilities) -> {
3137
capabilities.setCapability("marionette", true);
3238
return new FirefoxDriver(capabilities);
3339
});
3440
}
3541

42+
@Override
43+
protected void postProcessConfiguration(Configuration configuration) {
44+
configuration.getStringProperty(DRIVER_LOCATION).ifPresent(driverLocation -> {
45+
System.setProperty(DRIVER_LOCATION, driverLocation);
46+
});
47+
}
48+
3649
}

webtester-core/src/main/java/info/novatec/testit/webtester/browser/factories/RemoteFactory.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public Browser createBrowser(DesiredCapabilities capabilities) {
8888
String url = "http://" + host + ":" + port + "/wd/hub";
8989
try {
9090
log.debug("creating remote driver instance for {} with capabilities: {}", url, capabilities);
91-
return createBrowser(webDriverProducer.apply(new URL(url), capabilities));
91+
WebDriver webDriver = webDriverProducer.apply(new URL(url), capabilities);
92+
return WebDriverBrowser.forWebDriver(webDriver).withConfiguration(configuration).build();
9293
} catch (MalformedURLException e) {
9394
throw new MalformedRemoteFactoryUrlException(url, e);
9495
}
@@ -102,11 +103,6 @@ private void setOptionalProxyConfiguration(DesiredCapabilities capabilities) {
102103
}
103104
}
104105

105-
@Override
106-
public Browser createBrowser(WebDriver webDriver) {
107-
return WebDriverBrowser.forWebDriver(webDriver).withConfiguration(configuration).build();
108-
}
109-
110106
@Override
111107
public RemoteFactory withProxyConfiguration(ProxyConfiguration configuration) {
112108
proxyConfiguration = configuration;

webtester-core/src/test/java/utils/integration/TestBrowserFactory.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package utils.integration;
22

3-
import org.openqa.selenium.WebDriver;
43
import org.openqa.selenium.remote.DesiredCapabilities;
54

65
import info.novatec.testit.webtester.browser.Browser;
@@ -35,11 +34,6 @@ public Browser createBrowser(DesiredCapabilities capabilities) {
3534
throw new UnsupportedOperationException("createBrowser(DesiredCapabilities capabilities) not supported in test browser!");
3635
}
3736

38-
@Override
39-
public Browser createBrowser(WebDriver webDriver) {
40-
throw new UnsupportedOperationException("createBrowser(WebDriver webDriver) not supported in test browser!");
41-
}
42-
4337
@Override
4438
public BrowserFactory withProxyConfiguration(ProxyConfiguration configuration) {
4539
throw new UnsupportedOperationException("proxy not supported in test browser!");

webtester-documentation/src/main/asciidoc/chapters/browser-factories.asciidoc

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ to their specific environment. In case you just want to get started, we provide
1010
factories for the most common browsers:
1111

1212
* `ChromeFactory`
13+
* `EdgeFactory`
1314
* `FirefoxFactory`
1415
* `MarionetteFactory` (new Firefox driver)
1516
* `InternetExplorerFactory`
@@ -56,17 +57,46 @@ link:https://sites.google.com/a/chromium.org/chromedriver/downloads[here]. The
5657
path to the executable must be declared as a system or environment property
5758
named: `webdriver.chrome.driver`
5859

60+
You can also declare this property within your WebTester configuration file(s).
61+
This will trigger the framework to expose this property for you.
62+
5963
Additional Information:
6064

6165
* https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver
6266

67+
==== EdgeFactory
68+
69+
This `BrowserFactory` uses the `selenium-edge-driver` to create new Edge
70+
`Browser` instances.
71+
72+
===== Default Driver Configuration
73+
74+
In order to optimize testing the following properties are set when creating a
75+
`WebDriver` using the `EdgeFactory`:
76+
77+
* Native events are disabled -> Selenium does not simulate human typing.
78+
* Untrusted certificates are always accepted.
79+
80+
===== Additional Service Executable
81+
82+
The `EdgeDriver` needs an additional executable to communicate with an Edge
83+
browser. It can be downloaded
84+
link:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/[here].
85+
Please make sure to choose the release version equal to your Windows 10 build.
86+
The path to the executable must be declared as a system or environment property
87+
named: `webdriver.edge.driver`
88+
89+
You can also declare this property within your WebTester configuration file(s).
90+
This will trigger the framework to expose this property for you.
91+
6392
==== FirefoxFactory and MarionetteFactory
6493

6594
These `BrowserFactory` implementations use the `selenium-firefox-driver` to
6695
create new Firefox `Browser` instances. To drive Firefox browsers up to version
6796
46, the `FirefoxFactory` _can_ be used. In order to drive newer versions (47++),
6897
the `MarionetteFactory` _must_ be used. The only real difference between these
69-
two factories is the activation of the `marionnette` capability.
98+
two factories is the activation of the `marionnette` capability, but sadly in doing so
99+
you will need to provide the location of a `GeckoDriver` installation.
70100

71101
===== Default Driver Configuration
72102

@@ -85,6 +115,9 @@ link:https://github.com/mozilla/geckodriver/releases[here] The path to the
85115
executable must be declared as a system or environment property named:
86116
`webdriver.gecko.driver`
87117

118+
You can also declare this property within your WebTester configuration file(s).
119+
This will trigger the framework to expose this property for you.
120+
88121
Additional Information:
89122

90123
* https://github.com/SeleniumHQ/selenium/wiki/FirefoxDriver
@@ -112,32 +145,13 @@ link:http://selenium-release.storage.googleapis.com/index.html[here]. The path
112145
to the executable must be declared as a system or environment property named:
113146
`webdriver.ie.driver`
114147

148+
You can also declare this property within your WebTester configuration file(s).
149+
This will trigger the framework to expose this property for you.
150+
115151
Additional Information:
116152

117153
* https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
118154

119-
==== EdgeFactory
120-
121-
This `BrowserFactory` uses the `selenium-edge-driver` to create new Edge
122-
`Browser` instances.
123-
124-
===== Default Driver Configuration
125-
126-
In order to optimize testing the following properties are set when creating a
127-
`WebDriver` using the `EdgeFactory`:
128-
129-
* Native events are disabled -> Selenium does not simulate human typing.
130-
* Untrusted certificates are always accepted.
131-
132-
===== Additional Service Executable
133-
134-
The `EdgeDriver` needs an additional executable to communicate with an Edge
135-
browser. It can be downloaded
136-
link:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/[here].
137-
Please make sure to choose the release version equal to your Windows 10 build.
138-
The path to the executable must be declared as a system or environment property
139-
named: `webdriver.edge.driver`
140-
141155
==== RemoteFactory
142156

143157
This `BrowserFactory` uses the `RemoteWebDriver` to connect to a

0 commit comments

Comments
 (0)