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

Commit 7585480

Browse files
committed
moved all browser factories to the core module and removed corresponding support modules
1 parent 3285087 commit 7585480

File tree

20 files changed

+322
-672
lines changed

20 files changed

+322
-672
lines changed

pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,9 @@
4343
<module>webtester-core</module>
4444

4545
<module>webtester-support-assertj</module>
46-
<module>webtester-support-chrome</module>
47-
<module>webtester-support-firefox</module>
4846
<module>webtester-support-hamcrest</module>
49-
<module>webtester-support-ie</module>
5047
<module>webtester-support-junit</module>
5148
<module>webtester-support-spring4</module>
52-
<module>webtester-support-marionette</module>
5349
<module>webtester-support-testng</module>
5450

5551
</modules>
@@ -194,6 +190,11 @@
194190
<artifactId>selenium-ie-driver</artifactId>
195191
<version>${version.selenium}</version>
196192
</dependency>
193+
<dependency>
194+
<groupId>org.seleniumhq.selenium</groupId>
195+
<artifactId>selenium-edge-driver</artifactId>
196+
<version>${version.selenium}</version>
197+
</dependency>
197198
<dependency>
198199
<groupId>org.seleniumhq.selenium</groupId>
199200
<artifactId>selenium-chrome-driver</artifactId>

webtester-core/pom.xml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<project
2-
xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

77
<parent>
@@ -35,22 +35,32 @@
3535
<artifactId>commons-io</artifactId>
3636
</dependency>
3737

38+
<!-- Selenium dependencies - to make use of certain features,
39+
these have to be provided by the project. -->
3840
<dependency>
39-
<!-- Selenium dependency used to have access to the Selenium API. -->
4041
<groupId>org.seleniumhq.selenium</groupId>
4142
<artifactId>selenium-support</artifactId>
4243
<scope>provided</scope>
4344
</dependency>
44-
45-
<!-- test -->
46-
4745
<dependency>
48-
<!-- Firefox driver used in tests. Is scoped as a test dependency in order
49-
to not be a transitive dependency for the actual project using the WebTester
50-
framework. -->
5146
<groupId>org.seleniumhq.selenium</groupId>
5247
<artifactId>selenium-firefox-driver</artifactId>
53-
<scope>test</scope>
48+
<scope>provided</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.seleniumhq.selenium</groupId>
52+
<artifactId>selenium-chrome-driver</artifactId>
53+
<scope>provided</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.seleniumhq.selenium</groupId>
57+
<artifactId>selenium-ie-driver</artifactId>
58+
<scope>provided</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.seleniumhq.selenium</groupId>
62+
<artifactId>selenium-edge-driver</artifactId>
63+
<scope>provided</scope>
5464
</dependency>
5565

5666
</dependencies>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package info.novatec.testit.webtester.browser.factories;
2+
3+
import org.openqa.selenium.Proxy;
4+
import org.openqa.selenium.WebDriver;
5+
import org.openqa.selenium.remote.CapabilityType;
6+
import org.openqa.selenium.remote.DesiredCapabilities;
7+
8+
import com.google.common.base.Function;
9+
10+
import info.novatec.testit.webtester.api.browser.Browser;
11+
import info.novatec.testit.webtester.api.browser.BrowserFactory;
12+
import info.novatec.testit.webtester.api.browser.ProxyConfiguration;
13+
import info.novatec.testit.webtester.browser.NoProxyConfiguration;
14+
import info.novatec.testit.webtester.browser.WebDriverBrowser;
15+
16+
17+
/**
18+
* Base class for all the default {@link BrowserFactory} implementations shipped with WebTester.
19+
* <p>
20+
* This class provides default behaviour for any {@link Browser} initialized with it.
21+
* <p>
22+
* <b>The following capabilities are set by default:</b>
23+
* <ul>
24+
* <li>Native Events are disabled</li>
25+
* <li>Unsigned certificates are accepted</li>
26+
* </ul>
27+
*
28+
* @param <T> the type of the extending factory implementation - used for fluent API for certain methods
29+
* @since 1.2
30+
*/
31+
public class BaseBrowserFactory<T extends BrowserFactory> implements BrowserFactory {
32+
33+
private final Function<DesiredCapabilities, WebDriver> webDriverProducer;
34+
private ProxyConfiguration proxyConfiguration;
35+
36+
protected BaseBrowserFactory(Function<DesiredCapabilities, WebDriver> webDriverProducer) {
37+
this.webDriverProducer = webDriverProducer;
38+
}
39+
40+
@Override
41+
public Browser createBrowser() {
42+
DesiredCapabilities capabilities = getDefaultCapabilities();
43+
return createBrowser(capabilities);
44+
}
45+
46+
protected DesiredCapabilities getDefaultCapabilities() {
47+
DesiredCapabilities capabilities = new DesiredCapabilities();
48+
capabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS, false);
49+
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
50+
setOptionalProxyConfiguration(capabilities);
51+
return capabilities;
52+
}
53+
54+
@Override
55+
public Browser createBrowser(DesiredCapabilities capabilities) {
56+
return createBrowser(webDriverProducer.apply(capabilities));
57+
}
58+
59+
@Override
60+
public Browser createBrowser(WebDriver webDriver) {
61+
return WebDriverBrowser.buildForWebDriver(webDriver);
62+
}
63+
64+
protected void setOptionalProxyConfiguration(DesiredCapabilities capabilities) {
65+
if (proxyConfiguration != null && !(proxyConfiguration instanceof NoProxyConfiguration)) {
66+
Proxy proxy = new Proxy();
67+
proxyConfiguration.configureProxy(proxy);
68+
capabilities.setCapability(CapabilityType.PROXY, proxy);
69+
}
70+
}
71+
72+
@Override
73+
@SuppressWarnings("unchecked")
74+
public T withProxyConfiguration(ProxyConfiguration configuration) {
75+
proxyConfiguration = configuration;
76+
return ( T ) this;
77+
}
78+
79+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package info.novatec.testit.webtester.browser.factories;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.openqa.selenium.chrome.ChromeDriver;
5+
import org.openqa.selenium.remote.DesiredCapabilities;
6+
7+
import com.google.common.base.Function;
8+
9+
import info.novatec.testit.webtester.api.browser.Browser;
10+
11+
12+
/**
13+
* Factory class for creating Chrome {@link Browser} instances.
14+
* Needs the {@code webdriver.chrome.driver} system property pointing to the driver proxy server executable.
15+
* <p>
16+
* <b>The following capabilities are set by default:</b>
17+
* <ul>
18+
* <li>Native Events are disabled</li>
19+
* <li>Unsigned certificates are accepted</li>
20+
* </ul>
21+
* <b>Additional information on using the {@link ChromeDriver}:</b>
22+
* <p>
23+
* https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver
24+
*
25+
* @see Browser
26+
* @see ChromeDriver
27+
* @since 1.2
28+
*/
29+
public class ChromeFactory extends BaseBrowserFactory<ChromeFactory> {
30+
31+
public ChromeFactory() {
32+
super(new Function<DesiredCapabilities, WebDriver>() {
33+
@Override
34+
public WebDriver apply(DesiredCapabilities capabilities) {
35+
return new ChromeDriver(capabilities);
36+
}
37+
});
38+
}
39+
40+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package info.novatec.testit.webtester.browser.factories;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.openqa.selenium.edge.EdgeDriver;
5+
import org.openqa.selenium.edge.EdgeDriverService;
6+
import org.openqa.selenium.remote.DesiredCapabilities;
7+
8+
import com.google.common.base.Function;
9+
10+
import info.novatec.testit.webtester.api.browser.Browser;
11+
12+
13+
/**
14+
* Factory class for creating Microsoft Edge {@link Browser} instances.
15+
* Needs the {@code webdriver.edge.driver} system property pointing to the driver proxy server executable.
16+
* <p>
17+
* <b>The following capabilities are set by default:</b>
18+
* <ul>
19+
* <li>Native Events are disabled</li>
20+
* <li>Unsigned certificates are accepted</li>
21+
* </ul>
22+
*
23+
* @see Browser
24+
* @see EdgeDriver
25+
* @since 1.2
26+
*/
27+
public class EdgeFactory extends BaseBrowserFactory<EdgeFactory> {
28+
29+
public EdgeFactory() {
30+
super(new Function<DesiredCapabilities, WebDriver>() {
31+
@Override
32+
public WebDriver apply(DesiredCapabilities capabilities) {
33+
return new EdgeDriver(capabilities);
34+
}
35+
});
36+
}
37+
38+
public Browser createBrowser() {
39+
EdgeDriverService service = EdgeDriverService.createDefaultService();
40+
DesiredCapabilities capabilities = getDefaultCapabilities();
41+
return createBrowser(new EdgeDriver(service, capabilities));
42+
}
43+
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package info.novatec.testit.webtester.browser.factories;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.openqa.selenium.firefox.FirefoxDriver;
5+
import org.openqa.selenium.remote.DesiredCapabilities;
6+
7+
import com.google.common.base.Function;
8+
9+
import info.novatec.testit.webtester.api.browser.Browser;
10+
11+
12+
/**
13+
* Factory class for creating Firefox {@link Browser} instances.
14+
* This will only work for Firefox browsers up to version 46.
15+
* All newer versions need to be initialized using the {@link MarionetteFactory}.
16+
* <p>
17+
* <b>The following capabilities are set by default:</b>
18+
* <ul>
19+
* <li>Native Events are disabled</li>
20+
* <li>Unsigned certificates are accepted</li>
21+
* </ul>
22+
* <b>Additional information on using the {@link FirefoxDriver}:</b>
23+
* <p>
24+
* https://github.com/SeleniumHQ/selenium/wiki/FirefoxDriver
25+
*
26+
* @see Browser
27+
* @see FirefoxDriver
28+
* @see MarionetteFactory
29+
* @since 1.2
30+
*/
31+
public class FirefoxFactory extends BaseBrowserFactory<FirefoxFactory> {
32+
33+
public FirefoxFactory() {
34+
super(new Function<DesiredCapabilities, WebDriver>() {
35+
@Override
36+
public WebDriver apply(DesiredCapabilities capabilities) {
37+
capabilities.setCapability("marionette", false);
38+
return new FirefoxDriver(capabilities);
39+
}
40+
});
41+
}
42+
43+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package info.novatec.testit.webtester.browser.factories;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.openqa.selenium.ie.InternetExplorerDriver;
5+
import org.openqa.selenium.ie.InternetExplorerDriverService;
6+
import org.openqa.selenium.remote.DesiredCapabilities;
7+
8+
import com.google.common.base.Function;
9+
10+
import info.novatec.testit.webtester.api.browser.Browser;
11+
12+
13+
/**
14+
* Factory class for creating Internet Explorer {@link Browser} instances.
15+
* Needs the {@code webdriver.ie.driver} system property pointing to the driver proxy server executable.
16+
* <p>
17+
* <b>The following capabilities are set by default:</b>
18+
* <ul>
19+
* <li>Native Events are disabled</li>
20+
* <li>Unsigned certificates are accepted</li>
21+
* </ul>
22+
* <b>Additional information on using the {@link InternetExplorerDriver}:</b>
23+
* <p>
24+
* https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
25+
*
26+
* @see Browser
27+
* @see InternetExplorerDriver
28+
* @since 1.2
29+
*/
30+
public class InternetExplorerFactory extends BaseBrowserFactory<InternetExplorerFactory> {
31+
32+
public InternetExplorerFactory() {
33+
super(new Function<DesiredCapabilities, WebDriver>() {
34+
@Override
35+
public WebDriver apply(DesiredCapabilities capabilities) {
36+
return new InternetExplorerDriver(capabilities);
37+
}
38+
});
39+
}
40+
41+
public Browser createBrowser(int port) {
42+
InternetExplorerDriverService service = InternetExplorerDriverService.createDefaultService();
43+
DesiredCapabilities capabilities = getDefaultCapabilities();
44+
return createBrowser(new InternetExplorerDriver(service, capabilities, port));
45+
}
46+
47+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package info.novatec.testit.webtester.browser.factories;
2+
3+
import org.openqa.selenium.WebDriver;
4+
import org.openqa.selenium.firefox.FirefoxDriver;
5+
import org.openqa.selenium.remote.DesiredCapabilities;
6+
7+
import com.google.common.base.Function;
8+
9+
import info.novatec.testit.webtester.api.browser.Browser;
10+
11+
12+
/**
13+
* Factory class for creating Firefox {@link Browser} instances.
14+
* This will only work for Firefox browsers version 47 and above!
15+
* All older versions should be initialized using the {@link FirefoxFactory}.
16+
* <p>
17+
* <b>The following capabilities are set by default:</b>
18+
* <ul>
19+
* <li>Native Events are disabled</li>
20+
* <li>Unsigned certificates are accepted</li>
21+
* </ul>
22+
* <b>Additional information on using the {@link FirefoxDriver}:</b>
23+
* <p>
24+
* https://github.com/SeleniumHQ/selenium/wiki/FirefoxDriver
25+
*
26+
* @see Browser
27+
* @see FirefoxDriver
28+
* @see FirefoxFactory
29+
* @since 1.2
30+
*/
31+
public class MarionetteFactory extends BaseBrowserFactory<MarionetteFactory> {
32+
33+
public MarionetteFactory() {
34+
super(new Function<DesiredCapabilities, WebDriver>() {
35+
@Override
36+
public WebDriver apply(DesiredCapabilities capabilities) {
37+
capabilities.setCapability("marionette", true);
38+
return new FirefoxDriver(capabilities);
39+
}
40+
});
41+
}
42+
43+
}

0 commit comments

Comments
 (0)