Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example;
- import static org.junit.Assert.*;
- import java.util.concurrent.TimeUnit;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import org.openqa.selenium.By;
- import org.openqa.selenium.Keys;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- public class ValidLogin {
- /* 1. Create new instance of browser
- * 2. Navigate to the URL
- * Verify if page is correct
- * 3. Provide UserName and Password
- * 4. Submit
- * Verify result
- * 5. Logout
- * Verify correct logout
- * 6. Close the browser
- */
- private WebDriver driver;
- private String userName = "sweta";
- private String password = "november!";
- @Before
- public void setUp() throws Exception {
- // step 1
- System.setProperty("webdriver.chrome.driver", "C:\\SeleniumIDE\\WedDriver\\drivers\\chromedriver.exe");
- driver = new ChromeDriver();
- driver.manage().window().maximize();
- driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
- }
- @After
- public void tearDown() throws Exception {
- //step 6
- driver.quit();
- }
- @Test
- public void test() throws InterruptedException {
- // step 2
- //driver.get("http://192.168.2.32/symfony/web/index.php/auth/login"); // in school
- driver.get("http://local.school.portnov.com:4515/symfony/web/index.php/auth/login"); // at home
- assertEquals("OrangeHRM", driver.getTitle());
- // step 3
- WebElement uName = driver.findElement(By.xpath("//*[@id='txtUsername']"));
- uName.clear();
- uName.sendKeys(userName);
- WebElement pssw = driver.findElement(By.xpath("//*[@name='txtPassword']"));
- pssw.clear();
- pssw.sendKeys(password);
- // step 4
- WebElement submit = driver.findElement(By.xpath("//*[@value='LOGIN']"));
- submit.sendKeys(Keys.ENTER);
- assertEquals("Welcome sweta", driver.findElement(By.id("welcome")).getText());
- // step 5
- WebElement userMenu = driver.findElement(By.id("welcome"));
- userMenu.click();
- Thread.sleep(2000);
- WebElement logOut = driver.findElement(By.linkText("Logout"));
- logOut.click();
- //assertEquals("http://192.168.2.32/symfony/web/index.php/auth/login", driver.getCurrentUrl()); // in school
- assertEquals("http://local.school.portnov.com:4515/symfony/web/index.php/auth/login", driver.getCurrentUrl()); // at home
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement