public class One {
public WebDriver driver;
@Test
public void test1() {
/*System.setProperty("webdriver.chrome.driver", "Y:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();*/
driver.findElement(By.id("username")).sendKeys("abc@ccp.com");
driver.findElement(By.id("password")).sendKeys("password!1");
System.out.println("im in first test case from demoTwo Class");
}
@BeforeMethod
public void test() {
System.setProperty("webdriver.chrome.driver", "Y:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://app.anywebsite.com");
System.out.println("im in first test case from demoONE Class");
}
@AfterMethod
public void afterMethod() {
// Close the driver
driver.quit();
}
}
如何将驱动程序对象传递给后续测试方法?
网上的testng示例代码显示了这种结构,但没有执行。
答案 0 :(得分:1)
您只需这样设置您的驱动程序:
@BeforeMethod
public void test() {
System.setProperty("webdriver.chrome.driver", "Y:\\chromedriver.exe");
this.driver = new ChromeDriver();
driver.get("https://app.anywebsite.com");
System.out.println("im in first test case from demoONE Class");
}