![](/img/trans.png)
[英]org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0 using GeckoDriver Firefox and Selenium
[英]error“ org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/” with GeckoDriver and Firefox
你好,我无法测试我的 junit 这是我尝试编译时的错误,如果有人可以帮助我,谢谢
org.openqa.selenium.WebDriverException:java.net.ConnectException:无法连接到 localhost/0:0:0:0:0:0:0:1:18218 构建信息:版本:'3.14.0',修订: 'aacccce0',时间:'2018-08-02T20:05:20.749Z' 系统信息:主机:'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.version: FirefoxDriver
这是供您参考的代码:注意:当我使用 Junit 构建时,它在 mac 上运行良好
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));
}
}
这个错误信息...
org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:18218
...暗示在初始化WebDriver会话时引发了ConnectException 。
有关您正在使用的二进制文件的更多信息可能有助于调试此问题,如下所示:
您的问题的一些潜在解决方案是:
确保系统上的/etc/hosts
包含以下条目:
127.0.0.1 localhost.localdomain localhost #or 127.0.0.1 localhost loopback
确保 GeckoDriver-Firefox 映射
Test
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.