Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package SynapseSearchContractEmployeePOM;
- import java.awt.AWTException;
- import java.awt.Robot;
- import java.awt.Toolkit;
- import java.awt.datatransfer.StringSelection;
- import java.awt.event.KeyEvent;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.RichTextString;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import ReadProperty.ReadPropertyFiles;
- import readWriteExcel.ReadExcel;
- public class SearchEmployeePOM {
- static WebDriver driver;
- public SearchEmployeePOM(WebDriver driver) {
- SearchEmployeePOM.driver = driver;
- }
- public void searchEmployeeCheck() throws IOException, AWTException, InterruptedException{
- Thread.sleep(6000);
- String filePath = System.getProperty("user.dir")+"\src\";
- String fileName = "data.xlsx";
- String sheetName = "Demo";
- File file = new File(filePath+"\"+fileName);
- FileInputStream inputStream = new FileInputStream(file);
- Workbook Workbook = new XSSFWorkbook(inputStream);
- Sheet Sheet = Workbook.getSheet(sheetName);
- int rowCount = Sheet.getLastRowNum()-Sheet.getFirstRowNum();
- System.out.println("Total no now -"+rowCount);
- for (int i = 1; i < rowCount+1; i++) {
- String serchBoxXpath = ReadPropertyFiles.readProperty("serchBoxXpath");
- String searchButtonXPath = ReadPropertyFiles.readProperty("searchButtonXPath");
- String employeeTableXpath = ReadPropertyFiles.readProperty("employeeTableXpath");
- String strValuPrint = Sheet.getRow(i).getCell(0).getStringCellValue().toLowerCase();
- System.out.println("Getting value from Excel: "+strValuPrint);
- Thread.sleep(3000);
- driver.findElement(By.xpath(serchBoxXpath)).clear();
- Thread.sleep(3000);
- if(strValuPrint.contains(" ")){
- String strValuPrintTrimmed= strValuPrint.substring(0, strValuPrint.indexOf(" ")).toLowerCase();;
- driver.findElement(By.xpath(serchBoxXpath)).sendKeys(strValuPrintTrimmed);
- }
- Thread.sleep(2000);
- driver.findElement(By.xpath(searchButtonXPath)).click();
- Thread.sleep(2000);
- driver.switchTo().frame(0);
- Thread.sleep(2000);
- int j=2;
- int totalNumber=driver.findElements(By.xpath(employeeTableXpath)).size();
- int totalNumberWOheader = totalNumber - 1;
- System.out.println("Total Number of records found: "+ totalNumberWOheader +" on page");
- while(j<=totalNumber){
- Thread.sleep(500);
- String employeeEmail = driver.findElement(By.xpath(".//*[@id='grdvEmployeeLookupResult']/tbody/tr["+j+"]/td[6]")).getText().toLowerCase();
- Thread.sleep(500);
- String employeeName = driver.findElement(By.xpath(".//*[@id='grdvEmployeeLookupResult']/tbody/tr["+j+"]/td[2]")).getText().toLowerCase();;
- Thread.sleep(500);
- System.out.println("Getting value from Searched UI:"+employeeName);
- Thread.sleep(500);
- if (strValuPrint.equals(employeeName)){
- Thread.sleep(1000);
- System.out.println("Verifying values from UI "+employeeEmail+" and "+employeeName);
- int n = 4;
- String ifContract = employeeEmail.substring(0,n);
- String checkCon = "vsub";
- //int k = i-1;
- Thread.sleep(1000);
- if (ifContract.equals(checkCon)){
- Sheet.getRow(i).createCell(1).setCellValue("Record found and this is spcl emp");
- FileOutputStream ous = new FileOutputStream(file);
- Workbook.write(ous);
- }
- }
- j++;
- }
- driver.switchTo().defaultContent();
- }
- System.out.println();
- driver.findElement(By.xpath(".//*[@id='lbLoggin']")).click();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement