Short example for WebDriver construction for Firefox using both FirefoxBinary and DesiredCapabilities. Needed for example if you are going to specify path to firefox binary and some preferences like proxy settings, javascript support and so on.
First of all, let's create FirefoxProfile with desired settings. Let's assume that have to be proxy settings:
ffp.setPreference("general.useragent.override", userAgent);//Useragent set
ffp.setPreference("network.proxy.socks", proxyIp);//host
ffp.setPreference("network.proxy.socks_port", proxyPort);//port
ffp.setPreference("network.proxy.type", proxyType);// 0 - disable proxy; 1 - manual proxy configuration
Next step: creating capabilities and registering our profile there:
DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setCapability(FirefoxDriver.PROFILE, ffp);
Now set firefox binary path and set some environment variables (lets assume that we need to run some tests on headless selenium and so set DISPLAY variable):
FirefoxBinary ffb = new FirefoxBinary("/usr/local/firefox");
ffb.setEnvironmentProperty("DISPLAY", ":20");
Finally, construct WebDriver instance:
driver = (new FirefoxDriver(ffb, null, caps));
//null parameter is firefox profile here
PS
Probably, you should also use selenium-maven-plugin just to run xvfb for desired DISPLAY like following:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>xvfb</id>
<phase>test-compile</phase>
<goals>
<goal>xvfb</goal>
</goals>
<configuration>
<display>:20</display>
</configuration>
</execution>
</executions>
</plugin>
0 коментарі:
Дописати коментар