0
我有兩種方法,如下所示。 我使用testng.xml
保持thread-count="2" parallel="methods"
執行套件,以便所有@Test
方法將並行執行。如何在testng並行執行中將線路同步到兩個方法的線路流?
@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的執行?
..here dependsOnMethods只會方法1的完全執行後運行第二個方法。但我想要方法1的line1到方法2的第1行之間的同步,依此類推,即方法2的line1只應在執行方法1的line1之後執行。任何澄清請再評論。 – Toothless
如果是這種情況,則必須在兩種方法中編寫自己的同步邏輯。獲取方法1中的鎖並執行邏輯並釋放鎖。直到你釋放鎖定方法2將等待獲取鎖定。 – CARE