简体   繁体   English

Serenity / WebDriver:无法访问本地主机

[英]Serenity/WebDriver: cannot access localhost

I have problems with Serenity/WebDriver. 我在Serenity / WebDriver中遇到问题。 Suddenly one day, my code doesn't work and I got the error "Unknown host localhost". 突然有一天,我的代码无法正常工作,并且出现错误“未知主机本地主机”。

I can reproduced with the code from http://thucydides.info/docs/serenity-staging/#_serenity_with_cucumber : 我可以使用http://thucydides.info/docs/serenity-staging/#_serenity_with_cucumber中的代码进行复制:

@RunWith(SerenityRunner.class)
public class WhenSearchingOnGoogle {

    @Managed                                                                
    WebDriver driver;

    @Test
    public void shouldInstantiateAWebDriverInstanceForAWebTest() {
        driver.get("http://www.google.com");                                

        driver.findElement(By.name("q")).sendKeys("firefly", Keys.ENTER);

        new WebDriverWait(driver,5).until(titleContains("Google Search"));

        assertThat(driver.getTitle()).isEqualTo("firefly - Google Search");
    }
}

I got this error: 我收到此错误:

TEST STARTED: shouldInstantiateAWebDriverInstanceForAWebTest 测试开始:shouldInstantiateAWebDriverInstanceForAWebTest

18:06:11.599 [main] INFO net.serenitybdd.core.Serenity - TEST NUMBER: 1 sept. 18:06:11.599 [main] INFO net.serenitybdd.core.Serenity-测试号:9月1日。 22, 2018 6:06:11 PM org.openqa.selenium.remote.DesiredCapabilities chrome INFOS: Using new ChromeOptions() is preferred to DesiredCapabilities.chrome() 22,2018 6:06:11 PM org.openqa.selenium.remote.DesiredCapabilities chrome信息: DesiredCapabilities.chrome()首选使用new ChromeOptions() DesiredCapabilities.chrome()

net.serenitybdd.core.exceptions.SerenityManagedException: localhost could not be reached net.serenitybdd.core.exceptions.SerenityManagedException:无法访问本地主机

at net.serenitybdd.core.webdriver.driverproviders.RemoteDriverBuilder.newRemoteDriver(RemoteDriverBuilder.java:66)
at net.serenitybdd.core.webdriver.driverproviders.DefaultRemoteDriver.buildWithOptions(DefaultRemoteDriver.java:24)
at net.serenitybdd.core.webdriver.driverproviders.RemoteDriverProvider.newInstance(RemoteDriverProvider.java:53)
at net.thucydides.core.webdriver.WebDriverFactory.newWebdriverInstance(WebDriverFactory.java:127)
at net.thucydides.core.webdriver.WebDriverFacade.newDriverInstance(WebDriverFacade.java:149)

I do not understand the "localhost could not be reached" when I give another URL ?! 当我输入另一个URL时,我不理解“无法访问本地主机”?

I tried others drivers with no success. 我尝试了其他驱动程序,但均未成功。 How can I make it work ? 我该如何运作?

Thks, Cédric 塞克斯(ThéricCédric)

It seems that a remote webdriver was used, with localhost:4444, certainly by this parameter in serenity.properties: webdriver.remote.url= http://localhost:4444/wd/hub 看来,肯定是通过serenity.properties中的此参数使用的远程Webdriver与localhost:4444一起使用:webdriver.remote.url = http:// localhost:4444 / wd / hub

i solved this with https://github.com/SeleniumHQ/docker-selenium/blob/master/README.md#selenium-grid-hub-and-nodes : creating a docker-compose.yml, then starting with docker compose up -d stopping with docker-compose down 我用https://github.com/SeleniumHQ/docker-selenium/blob/master/README.md#selenium-grid-hub-and-nodes解决了这个问题:创建docker-compose.yml,然后从docker开始-d使用docker-compose down停止

If you run the selenium server locally its simple 如果您在本地运行Selenium服务器,那么它很简单

1. Please download the binary from 

Selenium downloads page 硒下载页面

Now navigate to the folder contains the jar and open command prompt there and run the commands in step 2 and 3 现在导航到包含jar和打开命令提示符的文件夹,并在步骤2和3中运行命令

2 . 2。 Start hub : 启动中心:

    java -jar selenium-server-standalone-3.14.0.jar -port 4444 -role hub

3. Register: 3.注册:

java -jar selenium-server-standalone-3.14.0.jar -role node -hub http://localhost:4444/grid/register 

After that you have to find the matching drivers for the version of chrome. 之后,您必须找到与chrome版本匹配的驱动程序。 for example v69 using chromdriver version 2.42. 例如使用chromdriver版本2.42的v69。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM