Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium webdriver 如何在使用testng selenium与java并行运行时关闭所有驱动程序_Selenium Webdriver_Testng - Fatal编程技术网

Selenium webdriver 如何在使用testng selenium与java并行运行时关闭所有驱动程序

Selenium webdriver 如何在使用testng selenium与java并行运行时关闭所有驱动程序,selenium-webdriver,testng,Selenium Webdriver,Testng,我不熟悉Selenium(Java)并使用TestNG框架。我在代码中使用带数据提供程序的factory。但是在并行执行的情况下,无法关闭所有驱动程序。请在下面找到我的测试代码。请提供建议 public class FactoryDataProvider { private String param; WebDriver driver =null; @Factory(dataProvider = "dataMethod") public FactoryData

我不熟悉Selenium(Java)并使用TestNG框架。我在代码中使用带数据提供程序的factory。但是在并行执行的情况下,无法关闭所有驱动程序。请在下面找到我的测试代码。请提供建议

public class FactoryDataProvider {

    private String param;
    WebDriver driver =null;

    @Factory(dataProvider = "dataMethod")
    public FactoryDataProvider(String param) {
        this.param = param;


    }

    @DataProvider(parallel = true)
    public static Object[][] dataMethod() {
        return  new Object[][] {
                new Object[] { "http://www.yahoo.com" }, 
               new Object[] { "http://www.google.com" } } ;
    }


    @BeforeClass
    public void beforeTest(){
        System.out.println("Before Test executed : ");
        driver = new FirefoxDriver();
    }


  @Test
    public void testMethodOne() {
        System.out.println("Thread ID :"+Thread.currentThread().getId());
        System.out.println("Test method one output: " + param);
        driver.get(param);
    }

    @Test
    public void testMethodTwo() {
        System.out.println("Thread ID :"+Thread.currentThread().getId());
        System.out.println("Test method two output: " + param);
        driver.get(param);
    }


    @AfterTest
    public void tearDown() {

        driver.quit();
    }
}

您可能希望使用AfterMethodAfterClass(取决于您的实际需要)

有了以上任何一项,最终都不会有驾驶员车窗被悬挂


使用AfterTest,窗口不会关闭。

您可能需要使用AfterMethodAfterClass(取决于您的实际需要)

有了以上任何一项,最终都不会有驾驶员车窗被悬挂


使用后测试,窗口未关闭。

到底发生了什么?如果并行运行测试,则只有一个驱动程序实例关闭。我想要的是在所有测试方法运行后关闭所有驱动程序实例。到底发生了什么?如果我们并行运行测试,只有一个驱动程序实例被关闭。我想要的是在所有测试方法运行后关闭所有驱动程序实例。我不想使用@AfterMethod,因为我正在同一个驱动程序中执行一个套件的所有测试方法。使用@AfterTest和AfterClass,它只关闭一个驱动程序实例。我的坏..使用@AfterClass,它刚刚得到解决。谢谢。我不想使用@AfterMethod,因为我正在同一个驱动程序中执行一个套件的所有测试方法。使用@AfterTest和AfterClass,它只关闭了一个驱动程序实例。我的错..使用@AfterClass,它刚刚得到解决。谢谢。