budabum

Test examples

Jan 29th, 2012
271
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Which variant of tests is better? The example for login form.
  2. Note: 'loginPage' variable is set automatically to the deafult login page.
  3. ============= Variant 1 =========================
  4. 1a)
  5. public void loginWithCorrectUser(){
  6.   IndexPage indexPage = loginPage.open().login(new CorrectUser1());
  7.   assertEquals("Check that we are on correct page",
  8.     loginPage.getTitle(), driver.getTitle());
  9.   assertTrue("Check we are actually loged in", indexPage.isLoggedIn());
  10. }
  11. 1b)
  12. public void testLogout(){
  13.   LoggedInPage inPage = ((LoginPage)loginPage.open()).login();
  14.   LoginPage loginPage2 = inPage.logout();
  15.   assertEquals("Check that we are on the correct page",
  16.     loginPage.getUrl(), loginPage2.getUrl());
  17.   assertTrue("Check that login button exists",
  18.     loginPage.isNotLoggedIn());
  19. }
  20. ============= Variant 2 =========================
  21. 2a)
  22. public void loginWithCorrectUser(){
  23.   User.newUser(UserTypes.EXISTENT)
  24.     .doLogin()
  25.       .checkLoggedIn(true);
  26. }
  27. 2b)
  28. public void testLogout(){
  29.   User.newUser(UserTypes.EXISTENT)
  30.     .doLogin()
  31.       .checkLoggedIn(true)
  32.     .doLogout()
  33.       .checkLoggedIn(false)
  34.       .checkLoggedOut(true);
  35. }
  36. ============= Variant 3 =========================
  37. 3a)
  38. public void loginWithCorrectUser(){
  39.   User user1 = User.createNewUser();
  40.   loginPage.type("username", user1.getName());
  41.   loginPage.type("password", user1.getPass());
  42.   loginPage.click("loginButton");
  43.   IndexPage indexPage = PageFactory.initElements(driver, IndexPage.class);
  44.   assertTrue("Check we are actually loged in", indexPage.isElementPresent(indexPage.linkLogout));
  45. }
  46. 3b)
  47. public void testLogout(){
  48.   User user1 = User.createNewUser();
  49.   loginPage.type("username", user1.getName());
  50.   loginPage.type("password", user1.getPass());
  51.   IndexPage indexPage = loginPage.click("loginButton").click("logoutLink");
  52.   LoginPage loginPage2 = PageFactory.initElements(driver, LoginPage.class);
  53.   assertEquals("Check that we are on the correct page",
  54.     loginPage.getUrl(), loginPage2.getUrl());
  55.   assertTrue("Check that login button exists",
  56.     loginPage.isElementPresent("loginButton"));
  57. }
RAW Paste Data