WebDriver 2.45.0& Firefox esr 31.5.0 :: WebDriverException:无法在45000毫秒内绑定到锁定端口7054

时间:2014-11-24 13:58:09

标签: selenium-webdriver remotewebdriver

我正在使用网格测试selenium远程webdriver,我遇到了错误:

org.openqa.selenium.WebDriverException: Unable to bind to locking port 7054 within 45000 ms
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'XXXXX', ip: 'XXXXX', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'
Driver info: driver.version: FirefoxDriver
Command duration or timeout: 47.71 seconds
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'XXXXX', ip: 'XXXXX', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'
Driver info: org.openqa.selenium.remote.RemoteWebDriver

有关我的配置的信息:

  • 硒 - 服务器 - 独立-2.45.0
  • 浏览器:Firefox esr 31.5.0
  • 我使用eclipe和testNG进行测试
  • 集线器配置: { "host": null, "port": 4444, "newSessionWaitTimeout": -1, "servlets" : [], "prioritizer": null, "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher", "throwOnCapabilityNotPresent": true, "nodePolling": 5000, "cleanUpCycle": 5000, "timeout": 300000, "browserTimeout": 0, "maxSession": 100, "jettyMaxThreads":-1 }

  • 我有三个节点,配置如下:

    { "capabilities": [ { "browserName": "firefox", "maxInstances": 5, "seleniumProtocol": "WebDriver" }, { "browserName": "chrome", "maxInstances": 5, "seleniumProtocol": "WebDriver" }, { "browserName": "iexplorer", "maxInstances": 1, "seleniumProtocol": "WebDriver" } ], "configuration": { "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy", "maxSession": 10, "port": 5555, "host": ip, "register": true, "registerCycle": 5000, "hubPort": 4444, "hubHost": ip } }

我的问题是:这个错误可能是什么原因? 目前我甚至不理解为什么即使我的集线器和节点配置端口不同也存在锁定端口7054。

感谢您的时间和答案。

更新

@BeforeMethod和@AfterMethod函数

@BeforeMethod
public void setUp(){

    StringBuilder text = customAppender.createInstance();
    customAppender.setBuilder(text);    

    WebDriver driver = LocalDriverFactory.createInstance("firefox");
    LocalDriverManager.setWebDriver(driver);
    customAppender.append("Opened webDriver instance = " + driver.hashCode());
}

@AfterMethod
public void shutDown(){
    WebDriver driver = LocalDriverManager.getDriver();
    if (driver != null) {
        mainFunctions.log("Closed webDriver instance = " + driver.hashCode(), 2);
        driver.quit();
    }
}

@Test方法:

@Test(dataProvider = "getData")
public static void test(String browserName, String link) throws MalformedURLException, InterruptedException {
        WebDriver driver = LocalDriverManager.getDriver();
        customAppender.append("Thread id = " + Thread.currentThread().getId());
        customAppender.append("Hashcode of webDriver instance = " + driver.hashCode());
        driver.get(link);
        customAppender.append(driver.getTitle());
        Thread.sleep(20000); // for testing purposes
        customAppender.append("Test 1, time: " + new SimpleDateFormat("HHmmss").format(Calendar.getInstance().getTime()));
        mainFunctions.log(customAppender.printOutString(), 0);
    }

@Test(dataProvider = "getData")
public static void test2(String browserName, String link) throws MalformedURLException, InterruptedException {
        WebDriver driver = LocalDriverManager.getDriver();
        customAppender.append("Thread id = " + Thread.currentThread().getId());
        customAppender.append("Hashcode of webDriver instance = " + driver.hashCode());
        driver.get(link);
        customAppender.append(driver.getTitle());
        Thread.sleep(20000); // for testing purposes
        customAppender.append("Test 2, time: " + new SimpleDateFormat("HHmmss").format(Calendar.getInstance().getTime()));
        mainFunctions.log(customAppender.printOutString(), 0);
    }

@DataProvider

@DataProvider(parallel=true)
    public Object[][] getData(){
        Object[][] d = new Object[4][2];
        // dummy data

        d[0][0] = "firefox";
        d[0][1] = "http://www.google.com";

        d[1][0] = "firefox";
        d[1][1] = "http://www.google.com";

        d[2][0] = "firefox";
        d[2][1] = "http://www.google.com";

        d[3][0] = "firefox";
        d[3][1] = http://www.google.com";

        return d;
    }

testNG.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="methods" thread-count="20"> 
    <test name="Test">
        <classes>
            <class name="ts.testWebdriver" />
        </classes>
    </test> <!-- Test -->
</suite> <!-- Suite -->

2 个答案:

答案 0 :(得分:1)

原因可能是您的firefox实例通过webdriver在远程计算机上的特定端口上运行。杀死ff实例并执行测试。在测试用例结束时提供driver.quit()以避免这些失败。

答案 1 :(得分:0)

好的,所以我在WebDriver上遇到过这个问题,但是无法修复它。 找到了解决方法。 我创建了一个新的Windows用户,并运行该用户的测试。现在好了。祝你好运。