在使用TestNG时,如果我们定义WebDriver驱动程序;那么如何在全局范围内而不创建该类的对象,我们如何在一种方法下使用驱动程序?

时间:2019-01-06 10:49:35

标签: java unit-testing testing automated-tests integration-testing

代码运行正常,但是为什么呢?而不创建类Testing123的对象?我们如何访问该驱动程序?

public class Testing123 {
    WebDriver driver ;

    @Test
    public void test1() {
        driver = new ChromeDriver();
        driver.get("http://google.com");
    }
}

1 个答案:

答案 0 :(得分:0)

TestNG框架负责在后台创建您的测试类的实例。基本上,通过使用'@Test'注释方法,注释处理器将类与测试运行程序相关联。有关更多信息,请查看:http://makeseleniumeasy.com/2018/06/08/testng-tutorials-21-why-dont-we-require-a-main-method-in-testng-class-for-execution-of-methods/