问题描述
有没有办法在一个testng套件中运行多个测试/类时使用相同的webdriver对象?我的意思是启动一个类的WebDriver实例,但继续在随后的类/测试套件中使用它?我遇到的问题是10个不同的类有这样的说法:
$ b WebDriver driver = new FirefoxDriver );
即使在将TestNG的并行模式设置为false之后,它也会打开10个不同的实例。它真的吸了我的系统内存。
我使用相同的WebDriver并运行不同的类的解决方案,而不必使用多个浏览器和Webdriver instent。
@BeforeTest中初始化驱动
您存储在基类中的方法,以便您的所有测试方法都可以访问它。 is there a way to use the same webdriver object for multiple tests/classes when run within a testng suite? What I mean is to start the WebDriver instance with one class, but continue using it over subsequent classes/tests in the suite?
The problem I am facing is that 10 differect classes have this statement:
WebDriver driver = new FirefoxDriver();
and it open 10 different instances even after I restrict TestNG with parallel mode set a s false. It really sucks up my system memory.
I wat a solution to use same WebDriver and run different classes over without having to multiple browser and Webdriver insntances.
Put all your classes in a <test>
tag and initialize the driver in a @BeforeTest
method which you store in the base class so that all your test methods can access it.
这篇关于在testng套件中运行时,是否有一种方法可以将多个java类使用相同的webdriver对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!