firefox.NotConnectedException 45000之后无法在端口7055上连接

当我尝试使用Xvfb运行selenium测试时,我得到以下错误

org.openqa.selenium.firefox.NotConnectedException:无法在45000 ms后连接到端口7055上的主机localhost.localdomain . Firefox控制台输出:错误:无法打开显示:1

at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:113)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:128)
at com.gtech.automation.uk.webdriver.WebDriverFactory.getWebDriver(WebDriverFactory.java:41)
at com.gtech.automation.uk.dashboard.DashboardImpl.getWebDriver(DashboardImpl.java:53)
at com.gtech.automation.uk.dashboard.DashboardImpl.goHome(DashboardImpl.java:91)
at com.gtech.automation.uk.dashboard.steps.footer.ConnectionInfoSteps.isConnectionClosed(ConnectionInfoSteps.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at cucumber.runtime.Utils$1.call(Utils.java:34)
at cucumber.runtime.Timeout.timeout(Timeout.java:13)
at cucumber.runtime.Utils.invoke(Utils.java:30)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:35)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
at cucumber.runtime.Runtime.runStep(Runtime.java:298)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:48)
at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

这些是我使用过的配置

Selenium版本:2.53.0 Firefox版本46

我检查了端口7055它不活动的netstat -ntlp | grep 7055

但是Xvfb正在linux服务器上运行netstat -ntlp | grep Xvfb tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 31384 / Xvfb

我尝试运行Xvfb服务器端口号不能正常工作Xvfb:1 -screen 0 1024x768x16 -nolisten inet6 -port 7055 -from localhost.localdomain

请帮忙

public static WebDriver getWebDriver(WebDriverImplementation implementation) {
    switch (implementation) {
        case FIREFOX:

            return new FirefoxDriver(getFirefoxCapabilities());
        case FIREBUG: {
            FirefoxProfile firefoxProfile = new FirefoxProfile();
            String seleniumPath = System.getProperty("selenuim.webdriver.path");
            try {
                firefoxProfile.addExtension(new File(seleniumPath + "/" + FIREBUG_FILENAME));
            }catch (NullPointerException e)
            {
                logger.log(Level.SEVERE, null, e);
            } catch(Exception e) {
               System.out.println("Unexcepted Exception");
                logger.log(Level.SEVERE, null, e);
            }
            firefoxProfile.setPreference("extensions.firebug.currentVersion", FIREBUG_VERSION);
            firefoxProfile.setPreference(seleniumPath, seleniumPath);

            DesiredCapabilities capabilities = getFirefoxCapabilities();
            capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);

            return new FirefoxDriver(capabilities);
        }
        case SHARED_FIREFOX:
            return new SharedFireFoxDriver();
        case MARIONETTE:
            return new MarionetteDriver(getFirefoxCapabilities());
        case INTERNET_EXPLORER:
            return new InternetExplorerDriver();
        default:
            String message = "Unable to find a web driver implemention for : " + implementation.name();
            logger.log(Level.SEVERE, message);
            throw new UnsupportedOperationException(message);
    }
}

回答(0)