Advertisement
Guest User

Untitled

a guest
Sep 11th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. import java.util.concurrent.TimeUnit;
  8. import org.junit.After;
  9. import org.junit.AfterClass;
  10. import org.junit.Before;
  11. import org.junit.BeforeClass;
  12. import org.junit.Test;
  13. import static org.junit.Assert.*;
  14. import static org.openqa.grid.common.SeleniumProtocol.WebDriver;
  15. import org.openqa.selenium.By;
  16. import org.openqa.selenium.WebDriver;
  17. import org.openqa.selenium.WebElement;
  18. import org.openqa.selenium.chrome.ChromeDriver;
  19. import static javaapplication4.Util.*;
  20. import org.openqa.selenium.Alert;
  21. import org.openqa.selenium.support.ui.ExpectedConditions;
  22. import org.openqa.selenium.support.ui.Select;
  23. import org.openqa.selenium.support.ui.WebDriverWait;
  24. /**
  25. *
  26. * @author ResulKerimov
  27. */
  28. public class AuthJUnitTest {
  29.  
  30.  
  31.  
  32. public AuthJUnitTest() {
  33. }
  34.  
  35. @BeforeClass
  36. public static void setUpClass() {
  37. }
  38.  
  39. @AfterClass
  40. public static void tearDownClass() {
  41. }
  42.  
  43. @Before
  44. public void setUp() {
  45. System.setProperty("webdriver.chrome.driver",
  46. "C:\\Users\\ResulKerimov\\Desktop\\chromedriver.exe");
  47.  
  48. DRIVER.get(BASE_URL);
  49. DRIVER.manage().timeouts().implicitlyWait(WAIT_TIME, TimeUnit.SECONDS);
  50. //WebDriverWait wait = new WebDriverWait(DRIVER, 5000);
  51.  
  52. //WebElement user = DRIVER.findElement(By.id("username"));
  53. //WebElement pass = DRIVER.findElement(By.id("password"));
  54.  
  55. //DRIVER.findElement(By.cssSelector("button[type='submit']")).click();
  56. }
  57.  
  58. @After
  59. public void tearDown() {
  60. }
  61.  
  62. @Test
  63. public void test() throws Exception {
  64.  
  65. String URL = DRIVER.getCurrentUrl();
  66. String[][] testData = getDataFromExcel(FILE_PATH,
  67. SHEET_NAME, TABLE_NAME);
  68. System.out.println(testData.length);
  69. for (int i = testData.length - 1; i >= 0; i--) {
  70.  
  71. String username = testData[i][0]; // get username
  72. String password = testData[i][1]; // get password
  73.  
  74. DRIVER.findElement(By.cssSelector("input[placeholder='Network username']")).clear();
  75. DRIVER.findElement(By.cssSelector("input[placeholder='Network username']")).sendKeys(username);
  76.  
  77. // Enter Password
  78. DRIVER.findElement(By.cssSelector("input[placeholder='Password']")).clear();
  79. DRIVER.findElement(By.cssSelector("input[placeholder='Password']")).sendKeys(password);
  80.  
  81. // FOR .ORG DOMAINS
  82. Select sc = new Select(DRIVER.findElement(By.tagName("select")));
  83. sc.selectByIndex(1);
  84.  
  85. DRIVER.findElement(By.cssSelector("button[type='submit']")).click();
  86.  
  87. System.out.println(i);
  88.  
  89. if(i > 0) {
  90. assertEquals(ERROR_AUTH_WRONG_DATA, DRIVER.getCurrentUrl(), URL);
  91. } else {
  92. assertNotEquals(ERROR_AUTH_CORRECT_DATA, DRIVER.findElements(By.cssSelector("div[class='media-body']")).size(), 0);
  93. }
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement