【问题标题】:Selenium grid: org.openqa.selenium.WebDriverException: Session [null] not available and is not among the last 1000 terminated sessionsSelenium 网格:org.openqa.selenium.WebDriverException:会话 [null] 不可用并且不在最后 1000 个终止会话中
【发布时间】:2019-07-02 13:53:11
【问题描述】:

我在执行 selenium 网格和 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

代码示例

浏览器.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();
    }
}

}

测试类

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>

【问题讨论】:

    标签: selenium selenium-grid


    【解决方案1】:

    您是否使用了设置系统属性?见下文。

    System.setProperty("webdriver.gecko.driver", "path to driver\\geckodriver.exe");
    

    【讨论】:

    • 硒集线器已启动并正在运行。节点连接到集线器。测试正在通过 chrome。但是在firefox上测试配置失败。我刚刚添加了 System.setProperty("webdriver.gecko.driver", "path to driver\geckodriver.exe"); ,但没有帮助。
    • 你的firefox驱动和浏览器版本兼容吗?
    • 在 selenium 节点控制台中,我看到它正在使用木偶。 1525245135316 mozrunner::runner INFO 运行命令:"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\thundiyi\\AppData\ \Local\\Temp\\rust_mozprofile.GpJGACwjHakG"
    • 我使用的是 Firefox 扩展版:52.7.4(64 位)
    • 尝试按照此处的步骤操作:guru99.com/gecko-marionette-driver-selenium.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 2023-03-04
    • 2012-09-12
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多