【发布时间】:2017-12-20 19:34:14
【问题描述】:
我的 testng.xml 下有几个测试用例。我的 testng.xml 如下所示。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="AutomationPractice" parallel="none">
<test name="Logins">
<classes>
<class name="newMavenProject.Gmail_Login_Firefox"/>
<class name="newMavenProject.Facebook_Login_Chrome"/>
</classes>
</test> <!-- Logins -->
</suite> <!-- AutomationPractice -->
在我的两个测试中,我都有@BeforeTest、@Test 和@AfterTest 注释。当我将 testng.xml 作为 testNGSuite 运行时。我看到浏览器同时为两个测试(@BeforeTest)打开,然后 Gmail_Login 测试将运行 @Test 注释。然后 Facebook_Login_Chrome 将运行其 @Test 注释。然后我的 Gmail_Login 测试将运行 @AfterTest 注释(关闭浏览器),然后我的 Facebook_Login_Chrome 测试将运行 @AfterTest 注释(关闭浏览器)。
如何才能让我的 Gmail_Login 测试完全运行(@BeforeTest、@Test、@AfterTest),然后我的 Facebook_Login_Chrome 测试完全运行(@BeforeTest、@Test、@AfterTest)。
非常感谢!!
【问题讨论】:
-
你能告诉我们你用来模拟这个问题的代码吗?此外,当您打印出线程 ID 时,您会看到什么? TestNG 不应该并行运行任何东西,除非并且直到它被明确配置。因此,您可能想要添加打印线程 ID 逻辑并共享输出。还请包括您正在使用的 TestNG 版本。今天最新发布的版本是
6.13.1 -
您应该使用在测试方法周围立即运行的 beforemethod 和 aftermethod。为测试标签运行前测和后测。
标签: selenium-webdriver automation testng