对于testNG中的所有测试,@ Test注释首先运行?

时间:2017-12-19 19:54:57

标签: selenium-webdriver automation testng

我的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)。

非常感谢!!

1 个答案:

答案 0 :(得分:0)

执行<test>标记时,它会运行所有方法,并从所有包含的类中注释@BeforeTest

看起来您需要使用@BeforeClass@AfterClass注释来注释设置和拆除方法。

根据TestNG documentation

  

@BeforeTest:带注释的方法将在任何测试方法之前运行   属于<test>标记内的类的运行。

     

@AfterTest:注释后的方法将在所有测试后运行   属于<test>标记内的类的方法已经运行。

     

@BeforeClass:带注释的方法将在第一次测试之前运行   调用当前类中的方法。

     

@AfterClass:注释后的方法将在所有测试后运行   已经运行了当前类中的方法。

相关问题