QAF-每次测试都想打开和关闭浏览器

时间:2019-01-04 13:24:28

标签: selenium ui-automation qaf

我在UI自动化框架中使用QAF开源Java库,并希望在每次测试时打开和关闭浏览器。但是,下面的代码无法做到这一点,因此由testSuccessfulLogin()打开的浏览器一直保持打开状态,因此testFailedLogin()失败。

public class LoginTestCase extends WebDriverTestCase {
    @Test(testName="SuccessfulLogin", description="Successful Login with valid username and password",  groups={"SMOKE"})
    public void testSuccessfulLogin() {
        LoginPage loginPage = new LoginPage();

        loginPage.openPage();
        verifyLinkWithTextPresent("Or Sign Up");

        loginPage.enterUsername("asdf.asdf");
        loginPage.enterPassword("Asdf@1234");
        loginPage.clickLogInButton();

        verifyLinkWithTextPresent("Dashboard");
        verifyLinkWithTextPresent("Logout");
    }

    @Test(testName="FailedLogin", description="Login with blank username and password", groups={"SMOKE"})
    public void testFailedLogin() {
        LoginPage loginPage = new LoginPage();      

        loginPage.openPage();
        verifyLinkWithTextPresent("Or Sign Up");

        loginPage.enterUsername("");
        loginPage.enterPassword("");
        loginPage.submitLoginForm();

        verifyLinkWithTextPresent("Dashboard");
        verifyLinkWithTextPresent("Logout");
    }
}

1 个答案:

答案 0 :(得分:0)

您可以通过设置selenium.singletone=method来实现。在应用程序属性或xml配置文件中指定它。请参阅list of propertieshow to set properties