开发者

Re-using login functionality in Selenium page object model tests

I am exploring the use of Selenium 2 on a web application which requires authentication before a user can use any of the application. I am planning on either JUnit 4 or TestNG (Still investigating which one to use with Grid 2). I may plan to use jbehave as well.

Does anyone have any suggestions on how I can improve the following test so I can use successful login functionality across all my tests? I want to avoid duplicating login in the tests itself.

public class LoginPageTest {

    private LoginPage page;

    @Before
    public void openTheBrowser() {
        page = PageFactory.initElements(new FirefoxDriver(), LoginPage.class);
        page.open(开发者_如何学编程"http://www.site.com/Login");
    }

    @After
    public void closeTheBrowser() {
        page.close();
    }

    @Test
    public void whenTheUserEntersValidCredentialsTheUserIsLoggedIn() {
        assertThat(page.getTitle(), containsString("Login") );
    }   
}

The test is simplified but it will return a page object of a successful login.

thanks


check case study @ http://blog.infostretch.com/?p=806 for better idea. If you are at initial level of development i would suggest you to try using QAF (formerly ISFW).


Your best option might be to use the LoginPageTest class as a parent class and extend each of your test classes from LoginPageTest.

That way, each test can login to the system using the parent's setup and tear down methods and do its own additional testing as well.


Create Libraries and call the sequence of test cases to execute one test case/scenario.
Eg:

lib.login();
lib.whenTheUserEntersValidCredentialsTheUserIsLoggedIn();
lib.logout();

for doing this take care of object creations. solution for object is use of super eg: super.login()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜