[英]Order of Execution of @BeforeTest method in testNG
I am trying to execute testcases using testng.xml. 我正在尝试使用testng.xml执行测试用例。 I have placed all the test running classes inside one test.
我将所有测试运行类都放在一个测试中。 While executing i am noticing that the @BeforeTest method of 2nd class (dashboard class) is executing first.
在执行时,我注意到第二个类(仪表板类)的@BeforeTest方法首先执行。 I want to execute the @BeforeTest methods of all classes to execute in same executing order as classes in testng.xml file.
我想执行所有类的@BeforeTest方法,以与testng.xml文件中的类相同的执行顺序执行。 Please find below image.
请找到下图。
As per image, i want to execute @BeforeTest methods of LoginPage class, then DashboardPage class and so on..
按照图像,我要执行LoginPage类的@BeforeTest方法,然后执行DashboardPage类,等等。
I have used alwaysRun=True for all @BeforeTest and @BeforeClass i have used for mentioned classes 我对所有用于@BeforeTest和@BeforeClass的类都使用alwaysRun = True
You can use the attribute dependOnMethods
form the annotation. 您可以使用属性
dependOnMethods
形成批注。
This little test: 这个小测试:
public class StackOFTest {
@BeforeTest
public void first() {
System.out.println("First");
}
@BeforeTest(dependsOnMethods = {"first"})
public void second() {
System.out.println("Second");
}
public static class SubTest extends StackOFTest {
@BeforeTest(dependsOnMethods = "second")
public void subFirst() {
System.out.println("- First");
}
@Test
public void test() {
System.out.println("Test");
}
}
}
Output: 输出:
First
Second
- First
Test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.