Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. package SynapseSearchContractEmployeePOM;
  2.  
  3. import java.awt.AWTException;
  4. import java.awt.Robot;
  5. import java.awt.Toolkit;
  6. import java.awt.datatransfer.StringSelection;
  7. import java.awt.event.KeyEvent;
  8. import java.io.File;
  9. import java.io.FileInputStream;
  10. import java.io.FileOutputStream;
  11. import java.io.IOException;
  12.  
  13. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  14. import org.apache.poi.ss.usermodel.RichTextString;
  15. import org.apache.poi.ss.usermodel.Sheet;
  16. import org.apache.poi.ss.usermodel.Workbook;
  17. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  18. import org.openqa.selenium.By;
  19. import org.openqa.selenium.WebDriver;
  20. import ReadProperty.ReadPropertyFiles;
  21. import readWriteExcel.ReadExcel;
  22.  
  23. public class SearchEmployeePOM {
  24.  
  25. static WebDriver driver;
  26.  
  27. public SearchEmployeePOM(WebDriver driver) {
  28. SearchEmployeePOM.driver = driver;
  29.  
  30. }
  31. public void searchEmployeeCheck() throws IOException, AWTException, InterruptedException{
  32.  
  33. Thread.sleep(6000);
  34. String filePath = System.getProperty("user.dir")+"\src\";
  35. String fileName = "data.xlsx";
  36. String sheetName = "Demo";
  37. File file = new File(filePath+"\"+fileName);
  38. FileInputStream inputStream = new FileInputStream(file);
  39. Workbook Workbook = new XSSFWorkbook(inputStream);
  40. Sheet Sheet = Workbook.getSheet(sheetName);
  41. int rowCount = Sheet.getLastRowNum()-Sheet.getFirstRowNum();
  42. System.out.println("Total no now -"+rowCount);
  43. for (int i = 1; i < rowCount+1; i++) {
  44. String serchBoxXpath = ReadPropertyFiles.readProperty("serchBoxXpath");
  45. String searchButtonXPath = ReadPropertyFiles.readProperty("searchButtonXPath");
  46. String employeeTableXpath = ReadPropertyFiles.readProperty("employeeTableXpath");
  47. String strValuPrint = Sheet.getRow(i).getCell(0).getStringCellValue().toLowerCase();
  48. System.out.println("Getting value from Excel: "+strValuPrint);
  49. Thread.sleep(3000);
  50. driver.findElement(By.xpath(serchBoxXpath)).clear();
  51. Thread.sleep(3000);
  52. if(strValuPrint.contains(" ")){
  53. String strValuPrintTrimmed= strValuPrint.substring(0, strValuPrint.indexOf(" ")).toLowerCase();;
  54. driver.findElement(By.xpath(serchBoxXpath)).sendKeys(strValuPrintTrimmed);
  55. }
  56. Thread.sleep(2000);
  57. driver.findElement(By.xpath(searchButtonXPath)).click();
  58. Thread.sleep(2000);
  59. driver.switchTo().frame(0);
  60. Thread.sleep(2000);
  61. int j=2;
  62. int totalNumber=driver.findElements(By.xpath(employeeTableXpath)).size();
  63. int totalNumberWOheader = totalNumber - 1;
  64. System.out.println("Total Number of records found: "+ totalNumberWOheader +" on page");
  65. while(j<=totalNumber){
  66. Thread.sleep(500);
  67. String employeeEmail = driver.findElement(By.xpath(".//*[@id='grdvEmployeeLookupResult']/tbody/tr["+j+"]/td[6]")).getText().toLowerCase();
  68. Thread.sleep(500);
  69. String employeeName = driver.findElement(By.xpath(".//*[@id='grdvEmployeeLookupResult']/tbody/tr["+j+"]/td[2]")).getText().toLowerCase();;
  70. Thread.sleep(500);
  71. System.out.println("Getting value from Searched UI:"+employeeName);
  72. Thread.sleep(500);
  73. if (strValuPrint.equals(employeeName)){
  74. Thread.sleep(1000);
  75. System.out.println("Verifying values from UI "+employeeEmail+" and "+employeeName);
  76. int n = 4;
  77. String ifContract = employeeEmail.substring(0,n);
  78. String checkCon = "vsub";
  79. //int k = i-1;
  80. Thread.sleep(1000);
  81. if (ifContract.equals(checkCon)){
  82. Sheet.getRow(i).createCell(1).setCellValue("Record found and this is spcl emp");
  83. FileOutputStream ous = new FileOutputStream(file);
  84. Workbook.write(ous);
  85. }
  86. }
  87.  
  88. j++;
  89.  
  90. }
  91. driver.switchTo().defaultContent();
  92. }
  93. System.out.println();
  94. driver.findElement(By.xpath(".//*[@id='lbLoggin']")).click();
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement