Advertisement
Guest User

Untitled

a guest
Nov 6th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. import org.openqa.selenium.By;
  2. import org.openqa.selenium.WebDriver;
  3. import org.openqa.selenium.WebElement;
  4. import org.openqa.selenium.chrome.ChromeDriver;
  5. import org.testng.Assert;
  6. import org.testng.annotations.AfterTest;
  7. import org.testng.annotations.BeforeTest;
  8. import org.testng.annotations.Test;
  9. import java.util.concurrent.TimeUnit;
  10.  
  11. public class LoginTests {
  12. WebDriver driver;
  13.  
  14.  
  15. @BeforeTest
  16. public void beforeTest() {
  17. System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
  18. driver = new ChromeDriver();
  19. driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
  20. driver.manage().deleteAllCookies();
  21. driver.get("http://automationpractice.com/index.php");
  22. driver.manage().window().maximize();
  23. }
  24.  
  25. @AfterTest
  26. public void afterTest() {
  27. driver.manage().deleteAllCookies();
  28. driver.quit();
  29. }
  30.  
  31. @Test(priority = 0)
  32. public void goodLogin() throws InterruptedException {
  33.  
  34. driver.findElement(By.xpath("//a[@title='Log in to your customer account']")).click();
  35. driver.findElement(By.id("email")).sendKeys("kasikaaakaakupiecka.1994@gmail.com");
  36. driver.findElement(By.id("passwd")).sendKeys("Jakieshaslo2019");
  37. driver.findElement(By.xpath("//button[@id='SubmitLogin']//span")).click();
  38. Thread.sleep(4000);
  39.  
  40. WebElement logout = (driver.findElement(By.xpath("//a[@title='Log me out']")));
  41. boolean bool = logout.isDisplayed();
  42. Assert.assertEquals(true, bool);
  43.  
  44. }
  45.  
  46. @Test(priority = 1)
  47. public void badPass() throws InterruptedException {
  48. Thread.sleep(4000);
  49. driver.findElement(By.xpath("//a[@title='Log me out']")).click();
  50. driver.findElement(By.id("email")).sendKeys("kasikaaakaakupiecka.1994@gmail.com");
  51. driver.findElement(By.id("passwd")).sendKeys("akieshaslo2019");
  52. driver.findElement(By.xpath("//button[@id='SubmitLogin']//span")).click();
  53.  
  54. WebElement badPass = (driver.findElement(By.xpath("//p[contains(text(),'There is 1 error')]")));
  55. boolean bool = badPass.isDisplayed();
  56. Assert.assertEquals(true, bool);
  57.  
  58. }
  59.  
  60. @Test(priority = 2)
  61. public void badlogin() throws InterruptedException {
  62. Thread.sleep(4000);
  63. driver.findElement(By.id("email")).clear();
  64. driver.findElement(By.id("passwd")).clear();
  65. driver.findElement(By.id("email")).sendKeys("asikaaakaakupiecka.1994@gmail.com");
  66. driver.findElement(By.id("passwd")).sendKeys("Jakieshaslo2019");
  67. driver.findElement(By.xpath("//button[@id='SubmitLogin']//span")).click();
  68.  
  69. WebElement badPass = (driver.findElement(By.xpath("//p[contains(text(),'There is 1 error')]")));
  70. boolean bool = badPass.isDisplayed();
  71. Assert.assertEquals(true, bool);
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement