0
如何在Selenium中的每個測試用例執行後打開和關閉瀏覽器?在Java中執行測試用例後打開/關閉瀏覽器Selenium
方案:讓我們假設有一個主類文件,說「TestCases.JAVA」,包含一些測試用例的方法,我想在每個測試用例的開始,打開瀏覽器,並執行後,然後關閉瀏覽器。
目前,我收到以下錯誤:
org.openqa.selenium.SessionNotCreatedException: Tried to run command without establishing a connection
演示測試用例的設計是這樣的...
public class TC_Login {
@Test(priority=1)
public static void TC_VerifyPageTitle_1() {
TestBaseSetup.OpenBrowser();
String actual=TestBaseSetup.driver.getTitle();
String expected= "Google";
Assert.assertEquals(actual, expected);
test.log(LogStatus.INFO, "Starting verify Title test");
test.log(LogStatus.INFO, "Ending verify Title test");
test.log(LogStatus.PASS, "Title verified");
TestBaseSetup.closeBrowser();
}
@Test(priority=2)
public static void TC_Login_2() {
TestBaseSetup.OpenBrowser();
String actual=TestBaseSetup.driver.getTitle();
String expected= "Google";
Assert.assertEquals(actual, expected);
test.log(LogStatus.INFO, "Starting verify Title test");
test.log(LogStatus.INFO, "Ending verify Title test");
test.log(LogStatus.PASS, "Title verified");
Action.Wait(3);
Re_Login.signIn();
TestBaseSetup.closeBrowser();
// test.log(LogStatus.INFO, "Browser closed");
}
}
我已搜查谷歌,但我還沒有發現任何有用的信息。