简体   繁体   中英

error“ org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/” with GeckoDriver and Firefox

Hello i can't test my junit this my error when i try to compile if someone can help me thank you

org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:18218 Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:05:20.749Z' System info: host: 'UTILISA-3AHNTLM', ip: '10.2.10.137', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191' Driver info: driver.version: FirefoxDriver

Here is code for your reference: Note : It works fine on mac when i build with Junit

package ca.qc.grasset_420_pa4_ag.lab05.authentification;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import ca.qc.grasset._420_pa4_ag.lab05.commons.AbstractFunctionalTest;

public final class InvalidUsernameLoginTest

    extends AbstractFunctionalTest {

    public InvalidUsernameLoginTest() {

        super();
    }

    @Test
    public void test() {

        getDriver().get("https://the-internet.herokuapp.com/");
        getDriver().findElement(By.linkText("Form Authentication"))
            .click();
        getDriver().findElement(By.id("username"))
            .click();
        getDriver().findElement(By.id("username"))
            .clear();
        getDriver().findElement(By.id("username"))
            .sendKeys("fdjkfgjkgfhkgf");
        getDriver().findElement(By.id("password"))
            .click();
        getDriver().findElement(By.id("password"))
            .clear();
        getDriver().findElement(By.id("password"))
            .sendKeys("SuperSecretPassword!");
        getDriver().findElement(
            By.xpath(
                "(.//*[normalize-space(text()) and normalize-space(.)='Password'])[1]/following::button[1]"))
            .click();
        validate();
    }

    @Override
    protected void validate() {

        WebElement element = getDriver().findElement(By.xpath("//*[@id=\"flash\"]"));

        String actualMessage = element.getText();
        Assert.assertTrue("Your username is invalid!\n×".equals(actualMessage));
    }
}

This error message...

org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:18218

...implies that the ConnectException was raised while initializing the WebDriver session.


Solution

Some more information regarding the binaries you are using might have been helpful to debug this issue which are as follows:

  • Your GeckoDriver version.
  • Your Firefox version.

Some of the potential solutions to your issue are:

  • Ensure that /etc/hosts on your system contains the following entry:

     127.0.0.1 localhost.localdomain localhost #or 127.0.0.1 localhost loopback
  • Ensure the GeckoDriver-Firefox Mapping

Geckodriver 发布

  • Upgrade GeckoDriver to GeckoDriver v0.23.0 level.
  • Ensure GeckoDriver is present in the specified location.
  • Ensure GeckoDriver is having executable permission for non-root users.
  • Upgrade Firefox version to Firefox v62.0 levels.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client .
  • Take a System Reboot .
  • Execute your Test as a non-root user.

The answer of Wojciech-Kopec helps me solve this issue, that maybe u not install Microsoft Visual Studio redistributable yet

Try to download and install the appropriate .exe file here

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0 using GeckoDriver Firefox and Selenium org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1941 with GeckoDriver and Selenium org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost error with IEDriverServer org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost with Gecko driver org.openqa.selenium.WebDriverException: java.net.ConnectException , HOW CAN i RESOLVE WebDriverException: java.net.ConnectException: Failed to connect to localhost error with Selenium 3 and chromedriver on MacOS org.openqa.selenium.WebDriverException: [Exception… “Component not initialized” error using GeckoDriver and Tor browser with Selenium Java org.openqa.selenium.WebDriverException: unknown error: chrome failed to start using Selenium ChromeDriver and Chrome through Java Raspberry pi 2 B + Selenium Java = WebDriverException: java.net.ConnectException: Failed to connect Exception in thread “main” org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start after geckodriver upgradation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM