【问题标题】:How to run different methods in different browsers using Selenium Webdriver?如何使用 Selenium Webdriver 在不同的浏览器中运行不同的方法?
【发布时间】:2014-06-15 06:04:24
【问题描述】:

我有一个测试用例,其中有 3 个方法

 Class
 {
   Method1();
   Method2();
   Method3()
 }

现在,我想在 IE 中运行 Method1(),在 FF 中运行 Method2(),在 Chrome 中运行 Method3()。我已经编写了代码,它工作得很好。唯一的问题是它在控制台中出现错误“org.openqa.selenium.remote.SessionNotFoundException: Session ID is null. Using WebDriver after call quit()?”

Method1() 完成后,我退出驱动程序

 driver.quit();
 driver=null;
 driver = new FirefoxDriver();

在 Method2() 完成后,Chrome 也是如此。

有人可以指导我为什么收到此消息以及解决方案是什么?

我不想使用 Selenium 网格。谢谢

【问题讨论】:

  • 如果下面@lost 的建议不起作用,您需要发布更多“不起作用”的内容。看到这个:stackoverflow.com/help/mcve
  • 在这里不工作意味着得到同样的错误“org.openqa.selenium.remote.SessionNotFoundException: Session ID is null. Using WebDriver after call quit()?”

标签: java selenium


【解决方案1】:

根据您的解释,这是我的理解:-

  1. Method1() 适用于 IE
  2. Method2() 是给FF的
  3. Method3() 用于 chrome

为什么要以新的 WebDriver 实例化结束代码?相反,当您创建如下所示的结构时,它会更有意义。

Class {
    WebDriver driver;
    Method1() {
        driver = new InternetExplorerDriver();
        //code for IE goes here
        driver.quit();
    }

    Method2() {
        driver = new FirefoxDriver();
        //code for FF goes here
        driver.quit();
    }

    Method3() {
        driver = new ChromeDriver();
        //code for chrome goes here
        driver.quit();
    }    
}

您的要求似乎不寻常。如果你想在不同的浏览器中测试一些代码,最好使用TestNG/JUnit等框架,或者为不同的浏览器指定不同的测试。

希望对你有所帮助。

【讨论】:

  • 感谢您发表评论,但我也尝试过您的方式,但它不起作用。
猜你喜欢
  • 2013-08-23
  • 1970-01-01
  • 2012-12-04
  • 2018-10-12
  • 2015-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-01
相关资源
最近更新 更多