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

Commit b0e0a30

Browse files
authored
Merge pull request #15 from Drakojin/master
Added Support for MarionetteDriver
2 parents 8f6e645 + 2cb3947 commit b0e0a30

File tree

6 files changed

+210
-1
lines changed

6 files changed

+210
-1
lines changed

documentation/chapters/browser.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ processes.
2323

2424
- [`ChromeFactory`](support-chrome.md)
2525
- [`FirefoxFactory`](support-firefox.md)
26+
- [`MarionetteFactory`](support-marionette.md)
2627
- [`InternetExplorerFactory`](support-ie.md)
2728

2829
Each of them comes in their own support module. The Firefox's and Internet Explorer's factory implementations are optimized
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[Home](../README.md)
2+
3+
# Firefox Marionette Browser Factory
4+
The module `webtester-support-marionette` provides a default `BrowserFactory` implementation called `MarionetteFactory`.
5+
Marionette can drive Firefox Browser from version 47 onward but is only fully supported starting with version 48.
6+
7+
## Default Driver Configuration
8+
In order to optimize testing the following properties are set when creating a `WebDriver` using the `MarionetteFactory`:
9+
10+
- "Native Events" are disabled -> Selenium does not simulate human typing.
11+
- Untrusted certificates are always trusted.
12+
13+
## Additional Service Executable
14+
The 'MarionetteDriver' needs an additional executable to communicate with a Firefox browser.
15+
It can be downloaded [here](https://github.com/mozilla/geckodriver/releases).
16+
Until further development you may have to rename the `geckodriver.exe` to `wires.exe` after unzipping.
17+
18+
The path to the executable must be declared as a system or environment property named: `webdriver.gecko.driver`
19+
20+
**For more details take a look at these links:**
21+
22+
- https://github.com/mozilla/geckodriver
23+
- https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette
24+
25+
26+
# Linked Documentation
27+
28+
- [Browser](browser.md)

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<module>webtester-support-ie</module>
5050
<module>webtester-support-junit4</module>
5151
<module>webtester-support-spring4</module>
52+
<module>webtester-support-marionette</module>
5253

5354
</modules>
5455

@@ -69,7 +70,7 @@
6970

7071
<version.jetty-server>9.4.0.M0</version.jetty-server>
7172

72-
<version.selenium>2.53.0</version.selenium>
73+
<version.selenium>2.53.1</version.selenium>
7374

7475
<version.slf4j>1.7.12</version.slf4j>
7576
<version.logback>1.1.3</version.logback>

webtester-support-marionette/pom.xml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project 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">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>info.novatec.testit</groupId>
9+
<artifactId>webtester</artifactId>
10+
<version>2.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>webtester-support-marionette</artifactId>
14+
<name>testIT | WebTester - Support - Firefox Marionette</name>
15+
16+
<dependencies>
17+
18+
<dependency>
19+
<!-- Required dependency on webtester-core. This is needed in order to
20+
have access to the frameworks base features. The dependency should be inherited
21+
by projects using this module. -->
22+
<groupId>info.novatec.testit</groupId>
23+
<artifactId>webtester-core</artifactId>
24+
<version>${project.version}</version>
25+
</dependency>
26+
27+
<dependency>
28+
<!-- Provided Selenium dependency used to have access to the Selenium API. -->
29+
<groupId>org.seleniumhq.selenium</groupId>
30+
<artifactId>selenium-support</artifactId>
31+
<scope>provided</scope>
32+
</dependency>
33+
<dependency>
34+
<!-- Provided dependency on selenium-firefox-driver used to interact with
35+
a Firefox browser. The dependency should be inherited by projects using this
36+
module. If another version of this dependency is needed / wanted it should
37+
be overridden by the project. -->
38+
<groupId>org.seleniumhq.selenium</groupId>
39+
<artifactId>selenium-firefox-driver</artifactId>
40+
<scope>provided</scope>
41+
</dependency>
42+
43+
</dependencies>
44+
45+
46+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
2+
#-------------------------------------------------------------------------------
3+
# Already used licenses in project :
4+
# - ASL, version 2
5+
# - Apache License, Version 2.0
6+
# - LGPL, version 2.1
7+
# - MIT License
8+
# - The Apache License, Version 2.0
9+
# - The Apache Software License, Version 2.0
10+
#-------------------------------------------------------------------------------
11+
# Please fill the missing licenses for dependencies :
12+
#
13+
#
14+
#Fri Jul 01 15:58:26 CEST 2016
15+
cglib--cglib-nodep--2.1_3=The Apache Software License, Version 2.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package info.novatec.testit.webtester.browser.proxy;
2+
3+
import org.openqa.selenium.Proxy;
4+
import org.openqa.selenium.WebDriver;
5+
import org.openqa.selenium.firefox.GeckoDriverService;
6+
import org.openqa.selenium.firefox.MarionetteDriver;
7+
import org.openqa.selenium.remote.CapabilityType;
8+
import org.openqa.selenium.remote.DesiredCapabilities;
9+
10+
import info.novatec.testit.webtester.browser.Browser;
11+
import info.novatec.testit.webtester.browser.BrowserFactory;
12+
import info.novatec.testit.webtester.browser.WebDriverBrowser;
13+
14+
15+
/**
16+
* Factory class for creating Firefox {@link Browser} objects using the Marionette driver.
17+
*
18+
* @see Browser
19+
* @see MarionetteDriver
20+
* @see GeckoDriverService
21+
* @since 2.0
22+
*/
23+
public class MarionetteFactory implements BrowserFactory {
24+
25+
private ProxyConfiguration proxyConfiguration;
26+
27+
/**
28+
* Creates a new {@link Browser} object for a Firefox Marionette web browser with a
29+
* default {@link GeckoDriverService}. Any desired capabilities will be
30+
* initialized as well.
31+
* <p>
32+
* Currently the following capabilities are configurable:
33+
* <ul>
34+
* <li>proxy setting using a {@link ProxyConfiguration}</li>
35+
* </ul>
36+
* The default profile includes the deactivation of native events for more
37+
* performance as well as the acceptance of untrusted certificates.
38+
*
39+
* @return the created {@link Browser}.
40+
* @see Browser
41+
* @see BrowserFactory
42+
* @since 2.0
43+
*/
44+
@Override
45+
public Browser createBrowser() {
46+
47+
GeckoDriverService service = GeckoDriverService.createDefaultService();
48+
49+
DesiredCapabilities capabilities = new DesiredCapabilities();
50+
capabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS, false);
51+
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
52+
setOptionalProxyConfiguration(capabilities);
53+
54+
return createBrowser(new MarionetteDriver(service, capabilities));
55+
}
56+
57+
/**
58+
* Creates a new {@link Browser} object for a Firefox Marionette web browser
59+
* using the given port for the driver server. Any desired capabilities will
60+
* be initialized as well.
61+
* <p>
62+
* Currently the following capabilities are configurable:
63+
* <ul>
64+
* <li>proxy setting using a {@link ProxyConfiguration}</li>
65+
* </ul>
66+
* The default profile includes the deactivation of native events for more
67+
* performance as well as the acceptance of untrusted certificates.
68+
*
69+
* @param port port on which the driver server should listen for commands
70+
* @return the created {@link Browser}.
71+
* @see Browser
72+
* @see BrowserFactory
73+
* @since 2.0
74+
*/
75+
public Browser createBrowser(int port) {
76+
77+
GeckoDriverService service = GeckoDriverService.createDefaultService();
78+
79+
DesiredCapabilities capabilities = new DesiredCapabilities();
80+
capabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS, false);
81+
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
82+
setOptionalProxyConfiguration(capabilities);
83+
84+
return createBrowser(new MarionetteDriver(service, capabilities, port));
85+
86+
}
87+
88+
@Override
89+
public Browser createBrowser(DesiredCapabilities capabilities) {
90+
return createBrowser(new MarionetteDriver(capabilities));
91+
}
92+
93+
@Override
94+
public Browser createBrowser(WebDriver webDriver) {
95+
96+
if (!(webDriver instanceof MarionetteDriver)) {
97+
throw new IllegalArgumentException("Wrong WebDriver class: " + webDriver + " only MarionetteDriver is allowed!");
98+
}
99+
100+
return WebDriverBrowser.buildForWebDriver(webDriver);
101+
102+
}
103+
104+
private void setOptionalProxyConfiguration(DesiredCapabilities capabilities) {
105+
if (proxyConfiguration != null) {
106+
Proxy proxy = new Proxy();
107+
proxyConfiguration.configureProxy(proxy);
108+
capabilities.setCapability(CapabilityType.PROXY, proxy);
109+
}
110+
}
111+
112+
@Override
113+
public MarionetteFactory withProxyConfiguration(ProxyConfiguration configuration) {
114+
proxyConfiguration = configuration;
115+
return this;
116+
}
117+
118+
}

0 commit comments

Comments
 (0)