Selenium grid:org.openqa.selenium.WebDriverException:Session [null]不可用,并且不在最后1000个终止的会话中

时间:2018-04-28 11:33:27

标签: selenium selenium-grid

执行selenium grid和TestNG时出现此错误。我想在浏览器中打开google.com并检查其标题。

是因为超时吗?

错误:

org.openqa.selenium.WebDriverException: Session [null] not available and is not among the last 1000 terminated sessions.
Active sessions are[ext. key c5de26ad-7758-467f-9b5f-be9fe7f1da30, ext. key dd1e9723-f331-4e1f-b86f-27ffa248042f, ext. key 59cbc57a-00a1-47e4-b8ef-8e3d9dab0f6e, ext. key 460c13e4-4503-488c-a1d2-18ee30c25346]
Command duration or timeout: 11 milliseconds

代码示例

browser.java

public class InvokeRemoteWebDriver {

public static RemoteWebDriver getDriver(String browser) throws MalformedURLException {
    return new RemoteWebDriver(new URL("http://192.168.1.7:4444/wd/hub"), getBrowserCapabilities(browser));

    //http://10.223.161.96:4444/wd/hub
}

private static DesiredCapabilities getBrowserCapabilities(String browserType) {
    switch (browserType) {
    case "firefox":
        System.out.println("Opening firefox driver");
        return DesiredCapabilities.firefox();
    case "chrome":
        System.out.println("Opening chrome driver");
        return DesiredCapabilities.chrome();
    case "IE":
        System.out.println("Opening IE driver");
        return DesiredCapabilities.internetExplorer();
    default:
        System.out.println("browser : " + browserType + " is invalid, Launching Firefox as browser of choice..");
        return DesiredCapabilities.firefox();
    }
}

}

识别TestClass

public class TestClass extends InvokeRemoteWebDriver{

//public static RemoteWebDriver driver;
public static RemoteWebDriver driver = null;
public static String appURL = "http://www.google.com";


@BeforeMethod
@Parameters({ "browser" })
public void setUp(String browser) throws MalformedURLException {
    System.out.println("Setting up browser driver");
    driver = InvokeRemoteWebDriver.getDriver(browser);
    //driver.manage().window().maximize();
}

@Test
public void testDIPPageTitle()  {
    try {

    System.out.println("testDIPPageTitle");
    driver.navigate().to(appURL);
    Thread.sleep(5000);
    String strPageTitle = driver.getTitle();

    Assert.assertTrue(strPageTitle.equalsIgnoreCase("yahoo"), "Page title doesn't match");
    }
    catch(Exception e) {
        System.out.println(e);
    }
}

@AfterMethod
public void tearDown() {

    try {
    if(driver!=null) {
        Thread.sleep(7000);
        driver.close();
        System.out.println("Closing browser");
        driver.quit();
    }
    else{
        System.out.println("Driver is null at AfterMethod");
    }
    }
    catch(Exception e) {
        System.out.println(e);
    }
    }

}

的testng.xml

<test name="Test Page title">
<parameter name="browser" value="firefox"/>
    <classes>
        <class name="com.here.dip.test.DIPTestSuite.checkPageTitle">

        <methods>            
            <include name="testDIPPageTitle"></include>
        </methods>

        </class>

    </classes>
</test>

1 个答案:

答案 0 :(得分:0)

您是否使用geckodriver在FF上运行测试?

您是否使用了set system属性?看到吼叫。  System.setProperty(“webdriver.gecko.driver”,“path to driver \ geckodriver.exe”);

您能与我们分享有关集线器和节点控制台的更多信息吗?是连接到集线器的节点吗?