Advertisement
DSTRN

LoginTest

Jan 17th, 2022
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. import static org.junit.Assert.assertEquals;
  2. import static org.testng.Assert.assertTrue;
  3.  
  4. import org.junit.After;
  5. import org.junit.Before;
  6. import org.junit.Test;
  7. import org.openqa.selenium.WebDriver;
  8. import org.openqa.selenium.chrome.ChromeDriver;
  9. import org.openqa.selenium.support.PageFactory;
  10.  
  11. import rs.ac.uns.kts.pages.HomePage;
  12. import rs.ac.uns.kts.pages.SingInPage;
  13.  
  14. public class LoginTest {
  15.  
  16.     // Add driver  
  17.     private WebDriver browser;
  18.  
  19.     // Add pages
  20.     private HomePage homePage;
  21.     private SingInPage singInPage;
  22.  
  23.     // Selenium setup
  24.     @Before
  25.     public void setupSelenium() {
  26.         // instantiate browser
  27.         System.setProperty("webdriver.chrome.driver", "chromedriver97.exe");
  28.         browser = new ChromeDriver();
  29.         // maximize window
  30.         browser.manage().window().maximize();
  31.         // navigate
  32.         browser.navigate().to("http://automationpractice.com/index.php");
  33.  
  34.         homePage = PageFactory.initElements(browser, HomePage.class);
  35.         singInPage = PageFactory.initElements(browser, SingInPage.class);
  36.     }
  37.  
  38.     @Test
  39.     public void singInTest() {
  40.         homePage.singInLinkClick();
  41.  
  42.         assertEquals("http://automationpractice.com/index.php?controller=authentication&back=my-account",
  43.                 browser.getCurrentUrl());
  44.  
  45.         // all fields empty
  46.         singInPage.submitBtnClick();
  47.         assertTrue(singInPage.errorMessagePresent("An email address required."));
  48.  
  49.         // set invalid email
  50.         singInPage.setEmailInput("aaa");
  51.         singInPage.submitBtnClick();
  52.         assertTrue(singInPage.errorMessagePresent("Invalid email address."));
  53.  
  54.         // set email
  55.         singInPage.setEmailInput("urkepetric1999@gmail.com");
  56.         singInPage.submitBtnClick();
  57.         assertTrue(singInPage.errorMessagePresent("Password is required."));
  58.  
  59.         // set wrong pass
  60.         singInPage.setPasswordInput("wrong");
  61.         singInPage.submitBtnClick();
  62.         assertTrue(singInPage.errorMessagePresent("Authentication failed."));
  63.  
  64.         // set correct pass
  65.         singInPage.setPasswordInput("uros123");
  66.         singInPage.submitBtnClick();
  67.  
  68.         assertEquals("http://automationpractice.com/index.php?controller=my-account", browser.getCurrentUrl());
  69.  
  70.     }
  71.  
  72.     // Selenium quit
  73.     @After
  74.     public void closeSelenium() {
  75.         // Shutdown the browser
  76.         browser.quit();
  77.     }
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement