我已经浏览了本网站上存在的问题,但无法解决 以下问题
工具:Junit,IntelliJ,Java语言
// SetUp Class
public class SetUpTest {
public static WebDriver driver;
@BeforeClass
public static void setUpTest() throws InterruptedException
{
driver=new FirefoxDriver();
driver.get("http://www.ABC.co.uk");
Thread.sleep(5000);
}
//Test1
public class HomePageTest extends SetUpTest {
@Test
public void titleTest()
{
assertTrue(driver.getTitle().startsWith("ABC"));
//Test2
public void merchandisingTest() throws InterruptedException {
@Test
public void merchandisingTest()
{
driver.navigate().to("http://ABC.co.uk/deals");
assertThat(driver.getPageSource(),containsString("deals"));
我尝试使用@TestBefore运行测试,但仍然打开了两个浏览器窗口 一个用于Test1,另一个用于Test2.I也使用了@ Suite.SuiteClasses 但问题仍然存在。
答案 0 :(得分:0)
你能试试这段代码吗?
public class BaseTest{
public WebDriver driver;
@BeforeSuite
public void startDriver(){
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(5l, TimeUnit.SECONDS);
driver.get("http://www.ABC.co.uk");
}
}
public class HomePageTest extends BaseTest{
@Test
public void titleTest(){
assetTrue(driver.getTitle().startsWith("ABC"));
}
@Test
public void merchanisingTest(){
driver.navigate().to("http://www.ABC.co.uk/deals");
assertTrue(driver.getTitle().startsWith("deals"));
}
}
另外,你使用TestNG XML运行它我想,只有一次调用@BeforeSuite方法