Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static org.junit.Assert.assertEquals;
- import static org.testng.Assert.assertTrue;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.support.PageFactory;
- import rs.ac.uns.kts.pages.HomePage;
- import rs.ac.uns.kts.pages.SingInPage;
- public class LoginTest {
- // Add driver
- private WebDriver browser;
- // Add pages
- private HomePage homePage;
- private SingInPage singInPage;
- // Selenium setup
- @Before
- public void setupSelenium() {
- // instantiate browser
- System.setProperty("webdriver.chrome.driver", "chromedriver97.exe");
- browser = new ChromeDriver();
- // maximize window
- browser.manage().window().maximize();
- // navigate
- browser.navigate().to("http://automationpractice.com/index.php");
- homePage = PageFactory.initElements(browser, HomePage.class);
- singInPage = PageFactory.initElements(browser, SingInPage.class);
- }
- @Test
- public void singInTest() {
- homePage.singInLinkClick();
- assertEquals("http://automationpractice.com/index.php?controller=authentication&back=my-account",
- browser.getCurrentUrl());
- // all fields empty
- singInPage.submitBtnClick();
- assertTrue(singInPage.errorMessagePresent("An email address required."));
- // set invalid email
- singInPage.setEmailInput("aaa");
- singInPage.submitBtnClick();
- assertTrue(singInPage.errorMessagePresent("Invalid email address."));
- // set email
- singInPage.setEmailInput("urkepetric1999@gmail.com");
- singInPage.submitBtnClick();
- assertTrue(singInPage.errorMessagePresent("Password is required."));
- // set wrong pass
- singInPage.setPasswordInput("wrong");
- singInPage.submitBtnClick();
- assertTrue(singInPage.errorMessagePresent("Authentication failed."));
- // set correct pass
- singInPage.setPasswordInput("uros123");
- singInPage.submitBtnClick();
- assertEquals("http://automationpractice.com/index.php?controller=my-account", browser.getCurrentUrl());
- }
- // Selenium quit
- @After
- public void closeSelenium() {
- // Shutdown the browser
- browser.quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement