问题
I am using Ubuntu 11.04 and selenium 2.9.0 Here is how it is configured in my root pom:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
When attemting to run a test, I get an exception:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
*** LOG addons.xpi: startup
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: > /tmp/anonymous3804893394247066972webdriver-profile/extensions/webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi: No changes found
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:95)
....
As far as I have googled it, the issue is that the firefox driver that selenium uses is incompatible with the version of the browser. Having in mind the frequent updates firefox releases, it will be difficult to maintain my local test environment.
Therefore, I have decided to install a static firefox with the latest known to me compatible version and to use selenium with it, while preserving my default firefox (I must not remove it).
So, I am not sure how to setup my selenium configuration in order to make it work with the static firefox. Probably I must configure my app to receive the path to the firefox binary for the driver to use? I'd like to know if anything else is also needed.
** Edit
I am using configuration properties to initialize the proper webdriver:
public abstract class SeleniumTestBase {
...
public final void setUp() throws Exception {
String driverClass = getConfigurationProperty("selenium.webDriverClass");
driver = (WebDriver) Class.forName(driverClass).newInstance();
...
doSetUp();
}
public void doSetUp() {
}
...
}
The "selenium.webDriverClass"
property is manageable by the pom.xml therefore different profiles can have different value. Currently it is the FQN of the driver class to be instantiated.
回答1:
As long as I know that the java command
WebDriver driver = new FirefoxDriver();
will run the installed Firefox browser on your computer.
but reading the JavaDoc at http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html I realised that there can be way how to override it:
FirefoxBinary binary = new FirefoxBinary(new File("path/to/binary"));
FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(binary, profile);
来源:https://stackoverflow.com/questions/9261133/how-can-i-configure-selenium-webdriver-to-use-custom-firefox-setup-for-tests