Advertisement
Guest User

Test Automation

a guest
Aug 17th, 2015
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. import org.junit.After;
  2. import org.junit.Before;
  3. import org.junit.Test;
  4. import org.openqa.selenium.By;
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.firefox.FirefoxDriver;
  8.  
  9. import static org.junit.Assert.assertEquals;
  10.  
  11.  
  12.  
  13. public class testautomationclass {
  14.  
  15.     private WebDriver selenium;
  16.  
  17.     @Before
  18.     public void setUp () {
  19.         selenium = new FirefoxDriver();
  20.  
  21.     }
  22.  
  23.     @Test
  24.     public void TestLoginExpectedScenario () {
  25.  
  26.         String validUsername = "testtest";
  27.         String validPassword = "testtest";
  28.  
  29.  
  30.         selenium.get("http://softuni.bg");
  31.         WebElement loginLink = selenium.findElement(By.id("loginLink"));
  32.  
  33.         loginLink.click();
  34.  
  35.         assertEquals("https://softuni.bg/account/authenticate", selenium.getCurrentUrl());
  36.  
  37.         WebElement usernameField = selenium.findElement(By.id("LoginUserName"));
  38.         WebElement passwordField = selenium.findElement(By.id("LoginPassword"));
  39.  
  40.         usernameField.clear();
  41.         usernameField.sendKeys(validUsername);
  42.  
  43.         passwordField.clear();
  44.         passwordField.sendKeys(validPassword);
  45.  
  46.         WebElement loginButton = selenium.findElement(By.xpath("//input[@value='Π’Ρ…ΠΎΠ΄']"));
  47.  
  48.         loginButton.click();
  49.  
  50.  
  51.         assertEquals("https://softuni.bg/users/profile/show", selenium.getCurrentUrl());
  52.  
  53.         WebElement dropDownUserName = selenium.findElement(By.xpath("/html/body/header/div/div/div/div/nav/div/div[2]/form/ul/li[2]/a"));
  54.  
  55.         assertEquals(validUsername.toUpperCase(), dropDownUserName.getText().trim());
  56.  
  57.     }
  58.  
  59.     @After
  60.     public void tearDown () {
  61.         selenium.close();
  62.  
  63.         try
  64.         {
  65.             Thread.sleep(5000);
  66.             selenium.quit();
  67.         }
  68.         catch(Exception e)
  69.         {
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement