如何在testng并行执行中将行同步到两个方法的行流?

时间:2016-12-14 16:04:49

标签: selenium synchronization testng

我有两种方法,如下所示。 我使用testng.xml执行套件,保留thread-count="2" parallel="methods",以便所有@Test方法将并行执行。

 @Test
 //this method will be executed in firefox 
 public void method1(){
     WebDriver driver=new FirefoxDriver();
     driver.get("https://google.co.in");
     line2;
     line3;
 }

  @Test
 //this method will be executed other window of firefox
 public void method2(){
     WebDriver driver=new FirefoxDriver();
     driver.get("https:gmail.com");  //has to be executed only after the opening of google in method1
     line2;  //has to be executed after the line2 of method1
     line3;  //has to be executed after the line3 of method1
 }

两种方法将并行运行,而不相互依赖。但是根据我的要求(在代码注释中提到),是否可以使method2的执行依赖于method1的执行?

1 个答案:

答案 0 :(得分:0)

在@Test

中添加以下dependsOnMethods
@Test(dependsOnMethods = { "method1" })
public void method2(){
       .....
}