![](/img/trans.png)
[英]How to call dropdown value from one java class(page) to another TestNG class(test) in selenium webdriver?
[英]How do I make the control flow from one test class to another test class in testNG?
我有 4 个测试用例,我希望第一个测试用例从 Demo1.java 运行,然后从 Demo2.java 运行其他 2 个测试用例,然后返回到 Demo1.java 以执行最终的测试用例。
有什么办法可以实现这一目标吗? 谢谢你的帮助。
priority
参数,但我想这只是检查同一测试类中的优先级这是一个示例代码 -
Demo1.java
class Demo1{
@Test
public void testOne(){ //This case should be executed first
}
@Test
public void testFour(){ //This case should be executed last
}
}
Demo2.java
class Demo2{
@Test
public void testTwo(){ // This case should be executed 2nd in the order
}
@Test
public void testThree(){ // This case should be executed 3rd in the order
}
}
@dependsOnGroups和@dependsOnMethods注释的组合提供了 TestNG 中跨类和方法的测试排序的最具扩展性的方式。
这是使用@dependsOnGroups 和@dependsOnMethods 的工作示例:
设想:
测试程序
public class ATest.java {
@Test(groups = "group-a1")
public void A1() {
System.out.println("Test A1: Runs before B1");
}
@Test(dependsOnGroups = "group-b2")
public void A2() {
System.out.println("Test A2: Runs after B2");
}
}
测试程序
public class BTest {
@Test(dependsOnGroups = "group-a1")
public void B1() {
System.out.println("Test B1: Runs after A1");
}
@Test(dependsOnMethods = "B1", groups = "group-b2")
public void B2() {
System.out.println("Test B2: Runs after B1");
}
}
注意:上述排序可以仅通过使用@dependsOnMethods注释来实现。
但是,不建议跨类使用@dependsOnMethods ,因为它会强制要求整个套件中的每个测试用例方法都具有唯一的名称。
使用@dependsOnGroups将允许测试命名的灵活性,并可以轻松实现跨类的排序,没有麻烦。
更多信息:
是的,您可以在以下人员的帮助下订购 Junit 测试用例
@FixMethodOrder(MethodSorters.JVM)
@TestMethodOrder(Alphanumeric.class)
@TestMethodOrder(OrderAnnotation.class)
@TestMethodOrder(TestCaseLengthOrder.class)
有关详细信息,您可以点击此链接单击以获取更多详细信息教程
您可以通过以下方法实现。
TEST1 类扩展了 TEST2 类:
public class TEST1 extends TEST2{
@Test(priority = 1)
public void testOne() {
System.out.println("Test method one");
}
@Test(priority = 4)
public void testTwo() {
System.out.println("Test method two");
}
}
类 TEST2 :
@Test(priority = 2)
public void testThree() {
System.out.println("Test three method in Inherited test");
}
@Test(priority = 3)
public void testFour() {
System.out.println("Test four method in Inherited test");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.