【发布时间】:2019-05-23 16:15:54
【问题描述】:
我正在使用 testNG 为 Page 对象模型运行我的 selenium 代码,@BeforeTest 每次测试只会运行一次,@BeforeMethod 每次测试都会运行一次。那么哪个注解更适合用于页面对象模型呢?
@BeforeMethod
public void setUp() throws IOException
{
initialisation();
loginPage = new Login();
loginPage.login(prop.getProperty("username"), prop.getProperty("password"));
ot = new OpenTasks();
active = new ActiveProjects();
}
@Test(priority=1)
public void validateTitle() throws IOException, InterruptedException
{
String custTitle = ot.verifyTitle();
Assert.assertEquals(custTitle, "actiTIME - Open Tasks", "Title not matched");
}
@Test(priority=2)
public void verifyProjectLink() throws IOException, InterruptedException
{
active = ot.clickOnProjectLink();
}
@AfterMethod
public void tearDown()
{
driver.quit();
}
(或)
public static WebDriver driver;
@BeforeTest
public void preConfig()
{
if(browser.equals("firefox"))
{
System.setProperty("webdriver.gecko.driver","C:\\Program Files\\FireFox\\geckodriver-v0.24.0-win64\\geckodriver.exe");
driver=new FirefoxDriver();
}
if(browser.equals("chrome"))
{
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Chrome\\chromedriver_win32\\chromedriver.exe");
driver=new ChromeDriver();
}
driver.get("http://desktop-g53h9ip:81/login.do");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@AfterTest
public void postConfig()
{
driver.close();
}
【问题讨论】: