I am getting error while using Firefox with WebDriver.
org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms.
Is anyone getting a similar issue or any idea what is the solution for this? It's working fine with Chrome but with Firefox none of the URLs are getting loaded.
Unfortunately Selenium WebDriver 2.53.0 is not compatible with Firefox 47.0. The WebDriver component which handles Firefox browsers (FirefoxDriver
) will be discontinued. As of version 3.0, Selenium WebDriver will need the geckodriver
binary to manage Firefox browsers. More info here and here.
Therefore, in order to use Firefox 47.0 as browser with Selenium WebDriver 2.53.0, you need to download the Firefox driver (which is a binary file called geckodriver
as of version 0.8.0, and formerly wires
) and export its absolute path to the variable webdriver.gecko.driver
as a system property in your Java code:
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
Luckily, the library WebDriverManager can do this work for you, i.e. download the proper Marionette binary for your machine (Linux, Mac, or Windows) and export the value of the proper system property. To use this library, you need to include this dependency into your project:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.2.2</version>
</dependency>
... and then execute this line in your program before using WebDriver:
WebDriverManager.firefoxdriver().setup();
A complete running example of a JUnit 4 test case using WebDriver could be as follows:
public class FirefoxTest {
protected WebDriver driver;
@BeforeClass
public static void setupClass() {
WebDriverManager.firefoxdriver().setup();
}
@Before
public void setupTest() {
driver = new FirefoxDriver();
}
@After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
@Test
public void test() {
// Your test code here
}
}
Take into account that Marionette will be the only option for future (for WebDriver 3+ and Firefox 48+), but currently (version 0.9.0 at writing time) is not very stable. Take a look to the Marionette roadmap for further details.
UPDATE
Selenium WebDriver 2.53.1 has been released on 30th June 2016. FirefoxDriver
is working again with Firefox 47.0.1 as browser.