Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. package com.example;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import java.util.concurrent.TimeUnit;
  6.  
  7. import org.junit.After;
  8. import org.junit.Before;
  9. import org.junit.Test;
  10. import org.openqa.selenium.By;
  11. import org.openqa.selenium.Keys;
  12. import org.openqa.selenium.WebDriver;
  13. import org.openqa.selenium.WebElement;
  14. import org.openqa.selenium.chrome.ChromeDriver;
  15.  
  16. public class ValidLogin {
  17.     /* 1. Create new instance of browser
  18.      * 2. Navigate to the URL
  19.      * Verify if page is correct
  20.      * 3. Provide UserName and Password
  21.      * 4. Submit
  22.      * Verify result
  23.      * 5. Logout
  24.      * Verify correct logout
  25.      * 6. Close the browser
  26.      */
  27.     private WebDriver driver;
  28.     private String userName = "sweta";
  29.     private String password = "november!";
  30.    
  31.  
  32.     @Before
  33.     public void setUp() throws Exception {
  34.         // step 1
  35.         System.setProperty("webdriver.chrome.driver", "C:\\SeleniumIDE\\WedDriver\\drivers\\chromedriver.exe");
  36.         driver = new ChromeDriver();
  37.         driver.manage().window().maximize();
  38.         driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
  39.     }
  40.  
  41.     @After
  42.     public void tearDown() throws Exception {
  43.         //step 6
  44.         driver.quit();
  45.     }
  46.  
  47.     @Test
  48.     public void test() throws InterruptedException {
  49.         // step 2
  50.         //driver.get("http://192.168.2.32/symfony/web/index.php/auth/login"); // in school
  51.         driver.get("http://local.school.portnov.com:4515/symfony/web/index.php/auth/login"); // at home
  52.         assertEquals("OrangeHRM", driver.getTitle());
  53.         // step 3
  54.         WebElement uName = driver.findElement(By.xpath("//*[@id='txtUsername']"));
  55.         uName.clear();
  56.         uName.sendKeys(userName);
  57.         WebElement pssw = driver.findElement(By.xpath("//*[@name='txtPassword']"));
  58.         pssw.clear();
  59.         pssw.sendKeys(password);
  60.         // step 4
  61.         WebElement submit = driver.findElement(By.xpath("//*[@value='LOGIN']"));
  62.         submit.sendKeys(Keys.ENTER);
  63.         assertEquals("Welcome sweta", driver.findElement(By.id("welcome")).getText());
  64.         // step 5
  65.         WebElement userMenu = driver.findElement(By.id("welcome"));
  66.         userMenu.click();
  67.         Thread.sleep(2000);
  68.         WebElement logOut = driver.findElement(By.linkText("Logout"));
  69.         logOut.click();
  70.         //assertEquals("http://192.168.2.32/symfony/web/index.php/auth/login", driver.getCurrentUrl()); // in school
  71.         assertEquals("http://local.school.portnov.com:4515/symfony/web/index.php/auth/login", driver.getCurrentUrl()); // at home
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement