Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. package goo.stqa.sgmail;
  2.  
  3. import org.apache.poi.xssf.usermodel.XSSFSheet;
  4. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.NoAlertPresentException;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.firefox.FirefoxDriver;
  9. import org.testng.annotations.AfterMethod;
  10. import org.testng.annotations.BeforeMethod;
  11. import org.testng.annotations.Test;
  12.  
  13. import java.io.File;
  14. import java.io.FileInputStream;
  15. import java.io.IOException;
  16. import java.util.concurrent.TimeUnit;
  17.  
  18.  
  19. public class RegistratFormTest {
  20. FirefoxDriver wd;
  21.  
  22. public static boolean isAlertPresent(FirefoxDriver wd) {
  23. try {
  24. wd.switchTo().alert();
  25. return true;
  26. } catch (NoAlertPresentException e) {
  27. return false;
  28. }
  29. }
  30.  
  31. @BeforeMethod
  32. public void setUp() throws Exception {
  33. wd = new FirefoxDriver();
  34. wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
  35. }
  36.  
  37.  
  38. @Test
  39. public void logTest() throws Exception {
  40. wd.get("https://gmail.com/");
  41. wd.findElement(By.linkText("Create account")).click();
  42.  
  43. try {
  44. File file = new File("C:\\Reposit\\gettingtest\\UserData.xlsx");
  45. FileInputStream iFile = new FileInputStream(file);
  46.  
  47. XSSFWorkbook wb = new XSSFWorkbook(iFile);
  48. XSSFSheet sheet = wb.getSheet("Sheet1");
  49.  
  50. int rowCount = sheet.getLastRowNum();
  51. //System.out.println("the no of rows are : " + rowCount);
  52. for (int row = 1; row <= rowCount; row++) {
  53.  
  54. String Username = sheet.getRow(row).getCell(0).getStringCellValue();
  55. String LastName = sheet.getRow(row).getCell(1).getStringCellValue();
  56. String GmailAddress = sheet.getRow(row).getCell(2).getStringCellValue();
  57. String Password = sheet.getRow(row).getCell(3).getStringCellValue();
  58.  
  59. wd.findElement(By.id("FirstName")).sendKeys(Username);
  60. wd.findElement(By.id("LastName")).sendKeys(LastName);
  61. wd.findElement(By.id("GmailAddress")).sendKeys(GmailAddress);
  62. wd.findElement(By.id("Passwd")).sendKeys(Password);
  63. wd.findElement(By.id("PasswdAgain")).sendKeys(Password);
  64.  
  65. wd.findElement(By.id("birthday-placeholder")).click();
  66. wd.findElement(By.id("BirthDay")).clear();
  67. wd.findElement(By.id("BirthDay")).sendKeys("12");
  68. /*wd.findElement(By.xpath("//label [@id='day-label']/span")).click();
  69.  
  70. wd.findElement(By.id("BirthDay")).sendKeys("20");*/
  71. wd.findElement(By.xpath(".//*[@id='BirthYear']")).click();
  72. wd.findElement(By.xpath(".//*[@id='BirthYear']")).sendKeys("2010");
  73.  
  74.  
  75. }
  76.  
  77. iFile.close();
  78. //wd.findElement(By.xpath("//label[@id='month-label']/span/div/div")).click();
  79. //wd.findElement(By.xpath("//label[@id='month-label']/span/div/div[@aria-posinset='5']")).click();
  80. //WebElement monthSelect = wd.findElement(By.id("BirthMonth"));
  81.  
  82. //wd.findElement(By.xpath(".//*[@id=':0']")).sendKeys("September");
  83. //wd.findElement(By.id(".//*[@id='BirthMonth']/div[1]")).click();
  84. // WebElement divElement = wd.findElement(By.xpath("//span [@id='BirthMonth']/div"));
  85. //divElement.findElement(By.xpath("div[1]")).click();
  86. wd.findElement(By.xpath("//*[@id=\"BirthMonth\"]/div")).click();
  87. wd.findElement(By.xpath("//*[@id=\":6\"]/div")).click();
  88.  
  89. wd.findElement(By.xpath("./*//*[@id='Gender']/div")).click();
  90. wd.findElement(By.xpath("//div[@id=':f']//div[.='Male']")).click();
  91.  
  92. wd.findElement(By.id("submitbutton")).click();
  93. wd.findElement(By.id("iagreebutton")).click();
  94.  
  95. } catch (IOException e) {
  96. e.printStackTrace();
  97. }
  98.  
  99.  
  100. }
  101.  
  102. @AfterMethod
  103. public void tearDown() {
  104. wd.quit();
  105. }
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement