Best Selenium code snippet using org.openqa.selenium.ScriptKey
Source:SoloIncomeEntry.java
1package pageobjects.GPP.Pensions.Solo;2import java.io.IOException;3import java.text.ParseException;4import java.util.ArrayList;5import java.util.List;6import java.util.concurrent.TimeUnit;7import org.openqa.selenium.By;8import org.openqa.selenium.JavascriptExecutor;9import org.openqa.selenium.Keys;10import org.openqa.selenium.WebDriver;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.support.FindBy;13import org.openqa.selenium.support.PageFactory;14import org.openqa.selenium.support.ui.ExpectedConditions;15import org.openqa.selenium.support.ui.WebDriverWait;16import helpers.CommonFunctions;17import helpers.GPPHelpers;18import helpers.Screenshot;19import helpers.Support;20import testdata.ConfigurationData;21import utilities.ExcelUtilities;22public class SoloIncomeEntry extends Support {23 WebDriver driver;24 WebDriverWait wait;25 26 @FindBy(id="SoloSearchApplicantFilter_GPName")27 WebElement soloSearchTxtField;28 29 @FindBy(id="btnApplicantSearch")30 WebElement applicantSearch;31 32 @FindBy(id="txtSololFromDate")33 WebElement soloStartDate;34 35 @FindBy(id="txtSoloTODate")36 WebElement soloEndDate;37 38 @FindBy(id="SOLODetails_ExcludingNHSPSContributions")39 WebElement payAmount;40 41 @FindBy(id="SOLODetails_ProfessionalNHSExpenses")42 WebElement professionalExp;43 44 @FindBy(id="SOLODetails_NHSPensionablePay")45 WebElement pensionablePay;46 47 @FindBy(id="SOLODetails_NHSPSEmployeeContributionsInAmount")48 WebElement empContributions;49 50 @FindBy(id="SOLODetails_AdditionalContributionsForAdditionalPension")51 WebElement AVCAmount;52 53 @FindBy(id="SOLODetails_AdditionalContributionsForEarlyRetirementReduction")54 WebElement ERRBOAmount;55 56 @FindBy(id="SOLODetails_AdditionalContributionsMPAVCs")57 WebElement MPAVCAmount;58 59 @FindBy(id="SOLODetails_NHSPSEmployerContributionsAndAdministrationLevy")60 WebElement empContriAndAdminLevy;61 62 @FindBy(id="SOLODetails_TotalNHSPSContributions")63 WebElement totalContribution;64 65 @FindBy(id="TickToConfirmSolo")66 WebElement tickToConfirm;67 68 @FindBy(id="btnSubmit")69 WebElement submitBtn;70 71 @FindBy(xpath="//div[@id='divSubmission']//button[@class='btn btn-default']")72 WebElement cancelSubmit;73 74 @FindBy(xpath="//div[@id='divSubmission']//button[@class='btn btn-success']")75 WebElement confirmSubmit;76 77 @FindBy(xpath="//div[@id='dvSoloForm']//td[2]/div[@class='search']")78 WebElement refNo;79 80 public SoloIncomeEntry(WebDriver driver)81 {82 this.driver = driver;83 driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);84 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);85 wait = new WebDriverWait(this.driver, 30);86 //This initElements method will create all WebElements87 PageFactory.initElements(this.driver, this);88 }89 public SoloIncomeEntry enterSoloMonthlyDetails(String colName, String file, String sheet,String environment) throws ParseException, InterruptedException {90 String strGMCCode= ConfigurationData.getRefDataDetails(environment, "PracticeGMCCode");91 //ExcelUtilities.getKeyValueByPosition(file, sheet, "GMCCode", colName);92 String strGPSoloName= ConfigurationData.getRefDataDetails(environment, "PracticeName");93 //ExcelUtilities.getKeyValueByPosition(file, sheet, "GPSoloName", colName);94 String strMonthsToAdd= ExcelUtilities.getKeyValueByPosition(file, sheet, "MonthsToAdd", colName);95 int monthsToAdd= Integer.parseInt(strMonthsToAdd);96 97 String strPayExcludingNHSPS= ExcelUtilities.getKeyValueByPosition(file, sheet, "PayExcludingNHSPS", colName);98 String strProfessionalExpenses= ExcelUtilities.getKeyValueByPosition(file, sheet, "ProfessionalExpenses", colName);99 100 String fromDate= CommonFunctions.getFirstDayOfMonth("dd/MM/yyyy", monthsToAdd);101 String toDate= CommonFunctions.getLastDayOfMonth("dd/MM/yyyy", monthsToAdd);102 103 scrolltoElement(driver, soloSearchTxtField);104 wait.until(ExpectedConditions.elementToBeClickable(soloSearchTxtField)).clear();105 CommonFunctions.setText(soloSearchTxtField, strGMCCode);106 List<WebElement> records= driver.findElements(By.xpath("//ul[@id='ApplicantSearchResult']/li"));107 for(int i=1;i<=records.size();i++){108 WebElement record= driver.findElement(By.xpath("//ul[@id='ApplicantSearchResult']/li["+i+"]/a"));109 String name= record.getText().toString();110 String[]nameArray= name.split("-");111 String GMC_Code= nameArray[0].toString().trim();112 String GPSoloName= nameArray[1].toString().trim();113 if((strGMCCode.equalsIgnoreCase(GMC_Code))&&(strGPSoloName.equalsIgnoreCase(GPSoloName))){114 record.click();115 Thread.sleep(2000);116 break;117 }118 }119 wait.until(ExpectedConditions.elementToBeClickable(applicantSearch)).click();120 Thread.sleep(2000);121 scrolltoElement(driver, soloStartDate);122 enterDataInTextField(soloStartDate, fromDate, wait);123 Thread.sleep(1000);124 enterDataInTextField(soloEndDate, toDate, wait);125 scrolltoElement(driver, payAmount);126 enterDataInTextField(payAmount, strPayExcludingNHSPS, wait);127 Thread.sleep(1000);128 enterDataInTextField(professionalExp, strProfessionalExpenses, wait);129 professionalExp.sendKeys(Keys.TAB);130 CommonFunctions.PageLoadExternalwait_OP(driver);131 Thread.sleep(2000);132 wait.until(ExpectedConditions.elementToBeClickable(tickToConfirm)).click();133 return new SoloIncomeEntry(driver);134 }135 public boolean verifyPensionableAmount(String colName, String file, String sheet) throws InterruptedException{136 boolean matched=false;137 String strPayExcludingNHSPS= ExcelUtilities.getKeyValueByPosition(file, sheet, "PayExcludingNHSPS", colName);138 double payExcludingNHSPS= Double.parseDouble(strPayExcludingNHSPS);139 Thread.sleep(500);140 String strProfessionalExpenses= ExcelUtilities.getKeyValueByPosition(file, sheet, "ProfessionalExpenses", colName);141 double professionalExpenses= Double.parseDouble(strProfessionalExpenses);142 Thread.sleep(500);143 String strPayExcludingNHSPS_Portal= Support.getValueByJavaScript(driver, "SOLODetails_ExcludingNHSPSContributions");144 strPayExcludingNHSPS_Portal= strPayExcludingNHSPS_Portal.replaceAll(",", "");145 double payExcludingNHSPS_Portal= Double.parseDouble(strPayExcludingNHSPS_Portal);146 Thread.sleep(500);147 String strProfessionalExpenses_Portal= Support.getValueByJavaScript(driver, "SOLODetails_ProfessionalNHSExpenses");148 strProfessionalExpenses_Portal= strProfessionalExpenses_Portal.replaceAll(",", "");149 double professionalExpenses_Portal= Double.parseDouble(strProfessionalExpenses_Portal);150 Thread.sleep(500);151 double actualAmt= payExcludingNHSPS-professionalExpenses;152 actualAmt= GPPHelpers.convertValueToDecimals(actualAmt,2);153 double expAmt= payExcludingNHSPS_Portal-professionalExpenses_Portal;154 expAmt= GPPHelpers.convertValueToDecimals(expAmt,2);155 156 if(actualAmt==expAmt){157 matched=true;158 }159 return matched;160 }161 162 public void captureSoloIncomeEntrySnaps(String note) throws InterruptedException, IOException {163 Screenshot.TakeSnap(driver, note+"_1");164 Thread.sleep(1000);165 166 ((JavascriptExecutor) driver).executeScript("window.scrollBy(0,800)", "");167 Screenshot.TakeSnap(driver, note+"_2");168 }169 public boolean verifyEmployeeContribution(String scriptKey, String testDataFileName, String testDataSheet,String amtTierSheet) throws InterruptedException {170 boolean contributionMatched=false;171 List<Double>expActualValues= getCalculatedValues(scriptKey,testDataFileName,testDataSheet,amtTierSheet);172 double contributionAmt= expActualValues.get(0);173 double actualContriAmt= expActualValues.get(1);174 if(contributionAmt==actualContriAmt){175 contributionMatched=true;176 }177 return contributionMatched;178 }179 private List<Double> getCalculatedValues(String scriptKey, String testDataFileName, String testDataSheet,180 String amtTierSheet) throws InterruptedException {181 List<Double> values= new ArrayList<Double>();182 double criteria = 0.00,startRange=0.00,endRange,contributionAmt=0.00;183 String strPensionableAmt= Support.getValueByJavaScript(driver, "SOLODetails_NHSPensionablePay");184 strPensionableAmt= strPensionableAmt.replaceAll(",", "");185 double pensionableAmt= Double.parseDouble(strPensionableAmt);186 Thread.sleep(500);187 pensionableAmt= GPPHelpers.convertValueToDecimals(pensionableAmt,2);188 189 String strAnnualAmt= ExcelUtilities.getKeyValueByPosition(testDataFileName, testDataSheet, "AnnualIncome", scriptKey);190 double annualAmt= Double.parseDouble(strAnnualAmt);191 Thread.sleep(500);192 annualAmt= GPPHelpers.convertValueToDecimals(annualAmt,2);193 194 double finalAmount= pensionableAmt+annualAmt;195 196 List<String>ranges= ExcelUtilities.getCellValuesByPosition(testDataFileName, amtTierSheet, "Range");197 int rangeSize= ranges.size();198 List<String>critria= ExcelUtilities.getCellValuesByPosition(testDataFileName, amtTierSheet, "Criteria");199 200 for(int i=0;i<rangeSize;i++){201 String range= ranges.get(i);202 String[]rangeArray= range.split("-");203 String strStartRange= rangeArray[0].toString();204 startRange= Double.parseDouble(strStartRange);205 Thread.sleep(500);206 startRange= GPPHelpers.convertValueToDecimals(startRange,2);207 String strEndRange= rangeArray[1].toString();208 if(!(strEndRange.equalsIgnoreCase("over"))){209 endRange= Double.parseDouble(strEndRange);210 Thread.sleep(500);211 endRange= GPPHelpers.convertValueToDecimals(endRange,2);212 if((finalAmount>=startRange)&&(finalAmount<=endRange)){213 String strCriteria= critria.get(i);214 criteria= Double.parseDouble(strCriteria);215 Thread.sleep(500);216 criteria= GPPHelpers.convertValueToDecimals(criteria,2);217 break;218 }219 }else{220 Thread.sleep(500);221 if((finalAmount>=startRange)){222 String strCriteria= critria.get(i);223 criteria= Double.parseDouble(strCriteria);224 Thread.sleep(500);225 criteria= GPPHelpers.convertValueToDecimals(criteria,2);226 break;227 }228 }229 }230 contributionAmt= (pensionableAmt*criteria)/100;231 contributionAmt= GPPHelpers.convertValueToDecimals(contributionAmt,2);232 System.out.println("Expected contribution amount is: "+contributionAmt);233 String strActualContriAmt= Support.getValueByJavaScript(driver, "SOLODetails_NHSPSEmployeeContributionsInAmount");234 strActualContriAmt= strActualContriAmt.replaceAll(",", "");235 double actualContriAmt= Double.parseDouble(strActualContriAmt);236 Thread.sleep(500);237 actualContriAmt= GPPHelpers.convertValueToDecimals(actualContriAmt,2);238 System.out.println("Actual contribution amount is: "+actualContriAmt);239 values.add(contributionAmt);240 values.add(actualContriAmt);241 return values;242 }243 public boolean verifyContributionAndLevy(String colName,String file,String sheet) throws InterruptedException {244 boolean contriAndAdminLevy= false;245 String strAdminLevyCharge= ExcelUtilities.getKeyValueByPosition(file, sheet, "AdminLevyCharge", colName);246 double adminLevyCharge= Double.parseDouble(strAdminLevyCharge);247 scrolltoElement(driver, empContriAndAdminLevy);248 249 String strPayExcludingNHSPS= ExcelUtilities.getKeyValueByPosition(file, sheet, "PayExcludingNHSPS", colName);250 double payExcludingNHSPS= Double.parseDouble(strPayExcludingNHSPS);251 Thread.sleep(500);252 String strProfessionalExpenses= ExcelUtilities.getKeyValueByPosition(file, sheet, "ProfessionalExpenses", colName);253 double professionalExpenses= Double.parseDouble(strProfessionalExpenses);254 Thread.sleep(500);255 double expAmt= payExcludingNHSPS-professionalExpenses;256 expAmt= GPPHelpers.convertValueToDecimals(expAmt,2);257 double expValue= (expAmt*adminLevyCharge)/100;258 expValue= GPPHelpers.convertValueToDecimals(expValue,2);259 System.out.println("Expected admin levy amount is: "+expValue);260 261 String strActualAmt= Support.getValueByJavaScript(driver, "SOLODetails_NHSPSEmployerContributionsAndAdministrationLevy");262 strActualAmt= strActualAmt.replaceAll(",", "");263 double actualAmt= Double.parseDouble(strActualAmt);264 Thread.sleep(500);265 actualAmt= GPPHelpers.convertValueToDecimals(actualAmt,2);266 System.out.println("Actual admin levy amount is: "+actualAmt);267 268 if(expValue==actualAmt){269 contriAndAdminLevy= true;270 }271 return contriAndAdminLevy;272 }273 public boolean verifyTotalContribution(String scriptKey, String testDataFileName, String testDataSheet,String amtTierSheet) throws InterruptedException {274 boolean isTotalNHSContribution= false;275 List<Double>expActualValues= getCalculatedValues(scriptKey,testDataFileName,testDataSheet,amtTierSheet);276 double actualContriAmt= expActualValues.get(1);277 scrolltoElement(driver, AVCAmount);278 String strAVCAmt= Support.getValueByJavaScript(driver, "SOLODetails_AdditionalContributionsForAdditionalPension");279 double AVCAmt= Double.parseDouble(strAVCAmt);280 AVCAmt= GPPHelpers.convertValueToDecimals(AVCAmt,2);281 282 scrolltoElement(driver, ERRBOAmount);283 String strERRBOAmt= Support.getValueByJavaScript(driver, "SOLODetails_AdditionalContributionsForEarlyRetirementReduction");284 double ERRBOAmt= Double.parseDouble(strERRBOAmt);285 ERRBOAmt= GPPHelpers.convertValueToDecimals(ERRBOAmt,2);286 287 scrolltoElement(driver, MPAVCAmount);288 String strMPAVCAmt= Support.getValueByJavaScript(driver, "SOLODetails_AdditionalContributionsMPAVCs");289 double MPAVCAmt= Double.parseDouble(strMPAVCAmt);290 MPAVCAmt= GPPHelpers.convertValueToDecimals(MPAVCAmt,2);291 292 //Added by Akshay on 25th Feb 2019293 String strEmployerNLevyAmt= Support.getValueByJavaScript(driver, "SOLODetails_NHSPSEmployerContributionsAndAdministrationLevy");294 strEmployerNLevyAmt= strEmployerNLevyAmt.replaceAll(",", "");295 double employerNLevyAmt= Double.parseDouble(strEmployerNLevyAmt);296 Thread.sleep(500);297 employerNLevyAmt= GPPHelpers.convertValueToDecimals(employerNLevyAmt,2);298 299 double totalContriAmount= actualContriAmt+AVCAmt+ERRBOAmt+MPAVCAmt+employerNLevyAmt;300 301 String strActTotalContriAmt= Support.getValueByJavaScript(driver, "SOLODetails_TotalNHSPSContributions");302 strActTotalContriAmt= strActTotalContriAmt.replaceAll(",", "");303 double actTotalContriAmt= Double.parseDouble(strActTotalContriAmt);304 if(totalContriAmount==actTotalContriAmt){305 isTotalNHSContribution= true;306 }307 return isTotalNHSContribution;308 }309 310 public SoloIncomeEntry clickOnSubmit() throws InterruptedException {311 scrolltoElement(driver, submitBtn);312 wait.until(ExpectedConditions.elementToBeClickable(submitBtn)).click();313 Thread.sleep(2000);314 System.out.println("Clicked on submit button on SOLO income form");315 return new SoloIncomeEntry(driver);316 }317 318 public SoloIncomeEntry clickOnCancelSubmit() throws InterruptedException {319 WebElement modalWindow= driver.findElement(By.xpath("//div[@id='divSubmission']//div[@class='modal-content']"));320 wait.until(ExpectedConditions.visibilityOf(modalWindow));321 if(modalWindow.isDisplayed()){322 scrolltoElement(driver, cancelSubmit);323 wait.until(ExpectedConditions.elementToBeClickable(cancelSubmit)).click();324 Thread.sleep(2000);325 System.out.println("Clicked on cancel submit on SOLO income form");326 }327 return new SoloIncomeEntry(driver);328 }329 330 public SoloIncomeEntry clickOnConfirmSubmit() throws InterruptedException {331 WebElement modalWindow= driver.findElement(By.xpath("//div[@id='divSubmission']//div[@class='modal-content']"));332 wait.until(ExpectedConditions.visibilityOf(modalWindow));333 if(modalWindow.isDisplayed()){334 scrolltoElement(driver, confirmSubmit);335 wait.until(ExpectedConditions.elementToBeClickable(confirmSubmit)).click();336 Thread.sleep(8000);337 System.out.println("Clicked on confirm submit on SOLO income form");338 }339 return new SoloIncomeEntry(driver);340 }341 public String getIncomeRefNo() {342 String refNumber= "";343 wait.until(ExpectedConditions.visibilityOf(refNo));344 refNumber= refNo.getText().toString();345 return refNumber;346 }347}...
Source:SoloIncomeApproval.java
1package pageobjects.GPP.Pensions.Solo;2import java.util.ArrayList;3import java.util.Arrays;4import java.util.List;5import java.util.concurrent.TimeUnit;6import org.openqa.selenium.By;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.support.FindBy;10import org.openqa.selenium.support.PageFactory;11import org.openqa.selenium.support.ui.ExpectedConditions;12import org.openqa.selenium.support.ui.WebDriverWait;13import helpers.CommonFunctions;14import helpers.GPPHelpers;15import helpers.Support;16import helpers.WindowHandleSupport;17import utilities.ExcelUtilities;18public class SoloIncomeApproval extends Support{19 WebDriver driver;20 WebDriverWait wait;21 22 @FindBy(xpath="//*[@id='frmApproveRejectSolo']/div[1]/div[3]/div[1]/strong")23 WebElement refNo;24 25 @FindBy(id="SOLODetails_AdditionalContributionsForAdditionalPension")26 WebElement AVCAmount;27 28 @FindBy(id="SOLODetails_AdditionalContributionsForEarlyRetirementReduction")29 WebElement ERRBOAmount;30 31 @FindBy(id="SOLODetails_AdditionalContributionsMPAVCs")32 WebElement MPAVCAmount;33 @FindBy(css="select#ddlFundProvider")34 WebElement fundProvider;35 36 @FindBy(xpath="//button[@class='btn btn-success btn-xs table-button']")37 WebElement approveButton;38 39 @FindBy(xpath="//div[@id='divConfApprove']//button[@class='btn btn-default']")40 WebElement cancelApprove;41 42 @FindBy(xpath="//div[@id='divConfApprove']//button[@id='submitbtn']")43 WebElement confirmApprove;44 45 @FindBy(css="button[class*='danger']")46 WebElement rejectButton;47 48 @FindBy(css="input#ReasonForRejection")49 WebElement rejectionReason;50 51 public SoloIncomeApproval(WebDriver driver)52 {53 this.driver = driver;54 driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);55 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);56 wait = new WebDriverWait(this.driver, 30);57 //This initElements method will create all WebElements58 PageFactory.initElements(this.driver, this);59 }60 public boolean verifyPresenceOfDocument(String refNumber) throws InterruptedException {61 Thread.sleep(5000);62 WindowHandleSupport.getRequiredWindowDriverWithIndex(driver, 1);63 boolean isApplicationPresent= false;64 String docNo= refNo.getText().toString();65 if(refNumber.equalsIgnoreCase(docNo)){66 isApplicationPresent= true;67 }68 return isApplicationPresent;69 }70 71 public boolean verifyPensionableAmount(String colName, String file, String sheet) throws InterruptedException{72 boolean matched=false;73 String strPayExcludingNHSPS= ExcelUtilities.getKeyValueByPosition(file, sheet, "PayExcludingNHSPS", colName);74 double payExcludingNHSPS= Double.parseDouble(strPayExcludingNHSPS);75 Thread.sleep(500);76 String strProfessionalExpenses= ExcelUtilities.getKeyValueByPosition(file, sheet, "ProfessionalExpenses", colName);77 double professionalExpenses= Double.parseDouble(strProfessionalExpenses);78 Thread.sleep(500);79 String strPayExcludingNHSPS_Portal= Support.getValueByJavaScript(driver, "SOLODetails_ExcludingNHSPSContributions");80 double payExcludingNHSPS_Portal= Double.parseDouble(strPayExcludingNHSPS_Portal);81 Thread.sleep(500);82 String strProfessionalExpenses_Portal= Support.getValueByJavaScript(driver, "SOLODetails_ProfessionalNHSExpenses");83 double professionalExpenses_Portal= Double.parseDouble(strProfessionalExpenses_Portal);84 Thread.sleep(500);85 double actualAmt= payExcludingNHSPS-professionalExpenses;86 actualAmt= GPPHelpers.convertValueToDecimals(actualAmt,2);87 double expAmt= payExcludingNHSPS_Portal-professionalExpenses_Portal;88 expAmt= GPPHelpers.convertValueToDecimals(expAmt,2);89 90 if(actualAmt==expAmt){91 matched=true;92 }93 return matched;94 }95 96 public boolean verifyEmployeeContribution(String scriptKey, String testDataFileName, String testDataSheet,String amtTierSheet) throws InterruptedException {97 boolean contributionMatched=false;98 List<Double>expActualValues= getCalculatedValues(scriptKey,testDataFileName,testDataSheet,amtTierSheet);99 double contributionAmt= expActualValues.get(0);100 double actualContriAmt= expActualValues.get(1);101 if(contributionAmt==actualContriAmt){102 contributionMatched=true;103 }104 return contributionMatched;105 }106 107 private List<Double> getCalculatedValues(String scriptKey, String testDataFileName, String testDataSheet,108 String amtTierSheet) throws InterruptedException {109 List<Double> values= new ArrayList<Double>();110 double criteria = 0.00,startRange=0.00,endRange,contributionAmt=0.00;111 String strPensionableAmt= Support.getValueByJavaScript(driver, "SOLODetails_NHSPensionablePay");112 double pensionableAmt= Double.parseDouble(strPensionableAmt);113 Thread.sleep(500);114 pensionableAmt= GPPHelpers.convertValueToDecimals(pensionableAmt,2);115 116 String strAnnualAmt= ExcelUtilities.getKeyValueByPosition(testDataFileName, testDataSheet, "AnnualIncome", scriptKey);117 double annualAmt= Double.parseDouble(strAnnualAmt);118 Thread.sleep(500);119 annualAmt= GPPHelpers.convertValueToDecimals(annualAmt,2);120 121 double finalAmount= pensionableAmt+annualAmt;122 123 List<String>ranges= ExcelUtilities.getCellValuesByPosition(testDataFileName, amtTierSheet, "Range");124 int rangeSize= ranges.size();125 List<String>critria= ExcelUtilities.getCellValuesByPosition(testDataFileName, amtTierSheet, "Criteria");126 127 for(int i=0;i<rangeSize;i++){128 String range= ranges.get(i);129 String[]rangeArray= range.split("-");130 String strStartRange= rangeArray[0].toString();131 startRange= Double.parseDouble(strStartRange);132 startRange= GPPHelpers.convertValueToDecimals(startRange,2);133 String strEndRange= rangeArray[1].toString();134 if(!(strEndRange.equalsIgnoreCase("over"))){135 endRange= Double.parseDouble(strEndRange);136 Thread.sleep(500);137 endRange= GPPHelpers.convertValueToDecimals(endRange,2);138 if((finalAmount>=startRange)&&(finalAmount<=endRange)){139 String strCriteria= critria.get(i);140 criteria= Double.parseDouble(strCriteria);141 Thread.sleep(500);142 criteria= GPPHelpers.convertValueToDecimals(criteria,2);143 break;144 }145 }else{146 Thread.sleep(500);147 if((finalAmount>=startRange)){148 String strCriteria= critria.get(i);149 criteria= Double.parseDouble(strCriteria);150 Thread.sleep(500);151 criteria= GPPHelpers.convertValueToDecimals(criteria,2);152 break;153 }154 }155 }156 contributionAmt= (finalAmount*criteria)/100;157 contributionAmt= GPPHelpers.convertValueToDecimals(contributionAmt,2);158 System.out.println("Expected contribution amount is: "+contributionAmt);159 String strActualContriAmt= Support.getValueByJavaScript(driver, "SOLODetails_NHSPSEmployeeContributionsInAmount");160 double actualContriAmt= Double.parseDouble(strActualContriAmt);161 actualContriAmt= GPPHelpers.convertValueToDecimals(actualContriAmt,2);162 System.out.println("Actual contribution amount is: "+actualContriAmt);163 values.add(contributionAmt);164 values.add(actualContriAmt);165 return values;166 }167 168 public boolean verifyTotalContribution(String scriptKey, String testDataFileName, String testDataSheet,String amtTierSheet) throws InterruptedException {169 boolean isTotalNHSContribution= false;170 List<Double>expActualValues= getCalculatedValues(scriptKey,testDataFileName,testDataSheet,amtTierSheet);171 double actualContriAmt= expActualValues.get(1);172 scrolltoElement(driver, AVCAmount);173 String strAVCAmt= Support.getValueByJavaScript(driver, "SOLODetails_AdditionalContributionsForAdditionalPension");174 double AVCAmt= Double.parseDouble(strAVCAmt);175 AVCAmt= GPPHelpers.convertValueToDecimals(AVCAmt,2);176 177 scrolltoElement(driver, ERRBOAmount);178 String strERRBOAmt= Support.getValueByJavaScript(driver, "SOLODetails_AdditionalContributionsForEarlyRetirementReduction");179 double ERRBOAmt= Double.parseDouble(strERRBOAmt);180 ERRBOAmt= GPPHelpers.convertValueToDecimals(ERRBOAmt,2);181 182 scrolltoElement(driver, MPAVCAmount);183 String strMPAVCAmt= Support.getValueByJavaScript(driver, "SOLODetails_AdditionalContributionsMPAVCs");184 double MPAVCAmt= Double.parseDouble(strMPAVCAmt);185 MPAVCAmt= GPPHelpers.convertValueToDecimals(MPAVCAmt,2);186 187 double totalContriAmount= actualContriAmt+AVCAmt+ERRBOAmt+MPAVCAmt;188 189 String strActTotalContriAmt= Support.getValueByJavaScript(driver, "SOLODetails_TotalNHSPSContributions");190 double actTotalContriAmt= Double.parseDouble(strActTotalContriAmt);191 if(totalContriAmount==actTotalContriAmt){192 isTotalNHSContribution= true;193 }194 return isTotalNHSContribution;195 }196 197 public SoloIncomeApproval clickOnApprove(String colName,String file,String sheet) throws InterruptedException {198 wait.until(ExpectedConditions.elementToBeClickable(MPAVCAmount)).clear();199 MPAVCAmount.sendKeys("0");200 201 String strFundProvider= ExcelUtilities.getKeyValueByPosition(file, sheet, "FundProvider", colName);202 CommonFunctions.selectOptionFromDropDown(fundProvider, strFundProvider);203 204 scrolltoElement(driver, approveButton);205 wait.until(ExpectedConditions.elementToBeClickable(approveButton)).click();206 Thread.sleep(2000);207 System.out.println("Clicked on approve button on SOLO income approval form");208 return new SoloIncomeApproval(driver);209 }210 211 public SoloIncomeApproval clickOnCancelApprove() throws InterruptedException {212 WebElement modalWindow= driver.findElement(By.xpath("//div[@id='divConfApprove']//div[@class='modal-content']"));213 if(modalWindow.isDisplayed()){214 scrolltoElement(driver, cancelApprove);215 wait.until(ExpectedConditions.elementToBeClickable(cancelApprove)).click();216 Thread.sleep(2000);217 System.out.println("Clicked on cancel approve on SOLO income approval form");218 }219 return new SoloIncomeApproval(driver);220 }221 222 public SoloIncomeApproval clickOnConfirmApprove() throws InterruptedException {223 WebElement modalWindow= driver.findElement(By.xpath("//div[@id='divConfApprove']//div[@class='modal-content']"));224 if(modalWindow.isDisplayed()){225 scrolltoElement(driver, confirmApprove);226 wait.until(ExpectedConditions.elementToBeClickable(confirmApprove)).click();227 Thread.sleep(7000);228 System.out.println("Clicked on confirm approve on SOLO income form");229 }230 return new SoloIncomeApproval(driver);231 }232 233 public SoloIncomeApproval clickOnReject(String colName,String file,String sheet) throws InterruptedException {234 wait.until(ExpectedConditions.elementToBeClickable(MPAVCAmount)).clear();235 MPAVCAmount.sendKeys("0");236 237 String strFundProvider= ExcelUtilities.getKeyValueByPosition(file, sheet, "FundProvider", colName);238 CommonFunctions.selectOptionFromDropDown(fundProvider, strFundProvider);239 240 241 scrolltoElement(driver, rejectButton);242 wait.until(ExpectedConditions.elementToBeClickable(rejectButton)).click();243 Thread.sleep(2000);244 System.out.println("Clicked on reject button on SOLO income approval form");245 return new SoloIncomeApproval(driver);246 }247 248 public SoloIncomeApproval clickOnConfirmReject() throws InterruptedException {249 WebElement modalWindow= driver.findElement(By.xpath("//div[@id='divReasonForRejection']//div[@class='modal-content']"));250 if(modalWindow.isDisplayed()){251 scrolltoElement(driver, rejectionReason);252 wait.until(ExpectedConditions.elementToBeClickable(rejectionReason)).clear();253 rejectionReason.sendKeys("Rejected");254 Thread.sleep(2000);255 System.out.println("Clicked on confirm reject button on SOLO income approval form");256 }257 return new SoloIncomeApproval(driver);258 }259 public boolean verifyButtonState() {260 boolean isButtonDisabled= false;261 int verifiedCount=0;262 List<WebElement> elements= Arrays.asList(approveButton,rejectButton);263 wait.until(ExpectedConditions.visibilityOfAllElements(elements));264 int count= elements.size();265 for(int i=0;i<count;i++){266 WebElement element= elements.get(i);267 if(!element.isEnabled()){268 verifiedCount++;269 }270 }271 if(count==verifiedCount){272 isButtonDisabled= true;273 }274 return isButtonDisabled;275 }276}...
Source:ScriptPinningTest.java
...32 executor = (JavascriptExecutor) driver;33 }34 @Test35 public void shouldAllowAScriptToBePinned() {36 ScriptKey hello = executor.pin("return 'I like cheese'");37 Object value = executor.executeScript(hello);38 assertThat(value).isEqualTo("I like cheese");39 }40 @Test41 public void pinnedScriptsShouldBeAbleToTakeArguments() {42 ScriptKey hello = executor.pin("return arguments[0]");43 Object value = executor.executeScript(hello, "cheese");44 assertThat(value).isEqualTo("cheese");45 }46 @Test47 public void shouldBeAbleToListAllPinnedScripts() {48 Set<ScriptKey> expected = ImmutableSet.of(49 executor.pin("return arguments[0];"),50 executor.pin("return 'cheese';"),51 executor.pin("return 42;"));52 Set<ScriptKey> pinned = executor.getPinnedScripts();53 assertThat(pinned).isEqualTo(expected);54 }55 @Test56 public void shouldAllowAPinnedScriptToBeUnpinned() {57 ScriptKey cheese = executor.pin("return 'brie'");58 executor.unpin(cheese);59 assertThat(executor.getPinnedScripts()).doesNotContain(cheese);60 }61 @Test62 public void callingAnUnpinnedScriptIsAnError() {63 ScriptKey cheese = executor.pin("return 'brie'");64 executor.unpin(cheese);65 assertThatExceptionOfType(JavascriptException.class).isThrownBy(() -> executor.executeScript(cheese));66 }67}...
Source:JSExecutor.java
1package org.example.util;2import org.openqa.selenium.JavascriptExecutor;3import org.openqa.selenium.ScriptKey;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import java.util.Set;7import static org.example.config.WebContext.getJSExecutor;8public class JSExecutor {9 private JavascriptExecutor executor;10 public JSExecutor(WebDriver driver) {11 this.executor = (JavascriptExecutor) driver;12 }13 public void scrollTo(WebElement element) {14 executeScript("arguments[0].scrollIntoView({block: 'center', inline: 'center'});", element);15 }16 public Object executeScript(String script, Object... args) {17 return executor.executeScript(script, args);18 }19 public Object executeAsyncScript(String script, Object... args) {20 return executor.executeAsyncScript(script, args);21 }22 public ScriptKey pin(String script) {23 return executor.pin(script);24 }25 public void unpin(ScriptKey key) {26 executor.unpin(key);27 }28 public Set<ScriptKey> getPinnedScripts() {29 return executor.getPinnedScripts();30 }31 public Object executeScript(ScriptKey key, Object... args) {32 return executor.executeScript(key, args);33 }34 public String getBeforePropertiesString(WebElement element) {35 String script = "return window.getComputedStyle(arguments[0], '::before').getPropertyValue('display');";36 String iconPropertiesString = (String) getJSExecutor().executeScript(script, element);37 return iconPropertiesString;38 }39 public String getAttribute(WebElement element, String name) {40 return getJSExecutor().executeScript("return arguments[0]." + name + ";", element).toString();41 }42}...
Source:WebDriverStub.java
1package net.thucydides.core.webdriver.stubs;2import org.openqa.selenium.By;3import org.openqa.selenium.ScriptKey;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.remote.RemoteWebDriver;6import org.openqa.selenium.remote.Response;7import java.util.ArrayList;8import java.util.HashSet;9import java.util.List;10import java.util.Set;11public class WebDriverStub extends RemoteWebDriver {12 @Override13 public void get(String s) {14 }15 @Override16 public String getCurrentUrl() {17 return "";18 }19 @Override20 public String getTitle() {21 return "";22 }23 @Override24 public List<WebElement> findElements(By by) {25 return new ArrayList<>();26 }27 @Override28 public WebElement findElement(By by) {29 return new WebElementFacadeStub();30 }31 @Override32 public String getPageSource() {33 return "";34 }35 @Override36 public void close() {37 }38 @Override39 public void quit() {40 }41 @Override42 public Set<String> getWindowHandles() {43 return new HashSet<>();44 }45 @Override46 public String getWindowHandle() {47 return "";48 }49 @Override50 public TargetLocator switchTo() {51 return new TargetLocatorStub(this);52 }53 @Override54 public Navigation navigate() {55 return new NavigationStub();56 }57 @Override58 public Options manage() {59 return new ManageStub();60 }61 @Override62 public Object executeScript(ScriptKey key, Object... args) {63 return new Response();64 }65}...
Source:ScriptKey.java
...16// under the License.17package org.openqa.selenium;18import org.openqa.selenium.internal.Require;19import java.util.Objects;20public class ScriptKey {21 private final String identifier;22 public ScriptKey(String identifier) {23 this.identifier = Require.nonNull("Script ID", identifier);24 }25 @Override26 public boolean equals(Object o) {27 if (!(o instanceof ScriptKey)) {28 return false;29 }30 ScriptKey that = (ScriptKey) o;31 return Objects.equals(this.identifier, that.identifier);32 }33 @Override34 public int hashCode() {35 return Objects.hash(identifier);36 }37 private String toJson() {38 return identifier;39 }40 private static ScriptKey fromJson(String identifier) {41 return new ScriptKey(identifier);42 }43}...
Source:Test141.java
1package stevejobspro;2import java.util.ArrayList;3import java.util.Set;4import org.openqa.selenium.ScriptKey;5import org.openqa.selenium.chrome.ChromeDriver;6import io.github.bonigarcia.wdm.WebDriverManager;7public class Test141 8{9 public static void main(String[] args) throws Exception10 {11 //open browser 12 WebDriverManager.chromedriver().setup();13 ChromeDriver driver=new ChromeDriver();14 driver.manage().window().maximize();15 //lanch site and locate an image to test immediatly16 driver.get("https://users.cs.cf.ac.uk/Dave.Marshall/Internet/FRAMES/nested_frame.html");17 Thread.sleep(5000);18 ScriptKey sk1=driver.pin("return(window.frames.length);");19 long n=(long) driver.executeScript(sk1);20 System.out.println(n);21 ScriptKey sk2=driver.pin("var frames=window.frames; ");22 ScriptKey sk3=driver.pin("frames[3].location='https://www.bbc.com';");23 driver.executeScript(sk2);24 driver.executeScript(sk3);25 Set<ScriptKey> l=driver.getPinnedScripts(); //sequential collection26 ArrayList<ScriptKey> al=new ArrayList<ScriptKey>(l); //random collection27 for(ScriptKey a:al)28 {29 driver.unpin(a);30 }31 //close site32 driver.close();33 }34}...
Source:InfiniteScrollPage.java
1package com.example.theinternet.page;2import com.example.theinternet.pageelement.InfiniteScrollElement;3import org.openqa.selenium.JavascriptExecutor;4import org.openqa.selenium.ScriptKey;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.support.PageFactory;7public class InfiniteScrollPage {8 WebDriver driver;9 JavascriptExecutor js;10 InfiniteScrollElement element;11 ScriptKey scroll_script_key;12 public InfiniteScrollPage(WebDriver driver) {13 this.driver = driver;14 element = new InfiniteScrollElement(driver);15 PageFactory.initElements(driver, element);16 js = (JavascriptExecutor) driver;17 scroll_script_key = js.pin("arguments[0].scrollIntoView();");18 }19 public void navigateTo() {20 driver.get("http://localhost:7080/infinite_scroll");21 }22 public int countScrollDivs() {23 return element.countScrollDivs();24 }25 public void waitTillScrollDivsReachAboveCount(int threshold) {...
ScriptKey
Using AI Code Generation
1import org.openqa.selenium.Keys;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.By;6import org.openqa.selenium.JavascriptExecutor;7import org.openqa.selenium.interactions.Actions;8import org.openqa.selenium.TakesScreenshot;9import java.io.File;10import org.openqa.selenium.WebDriverException;11import java.io.IOException;12import java.text.SimpleDateFormat;13import java.util.Date;14import java.util.StringJoiner;15import org.openqa.selenium.Alert;16import org.openqa.selenium.support.ui.ExpectedConditions;17import org.openqa.selenium.support.ui.WebDriverWait;18import org.openqa.selenium.NoSuchElementException;19import org.openqa.selenium.NoSuchFrameException;20import org.openqa.selenium.NoSuchWindowException;21import org.openqa.selenium.NoAlertPresentException;22import org.openqa.selenium.NoSuchAttributeException;23import org.openqa.selenium.NoSuchCookieException;24import org.openqa.selenium.NoSuchWindowException;25import org.openqa.selenium.NoSuchContextException;
ScriptKey
Using AI Code Generation
1import org.openqa.selenium.ScriptKey;2import org.openqa.selenium.interactions.Actions;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import java.util.concurrent.TimeUnit;8import org.openqa.selenium.Keys;9import org.testng.Assert;10import org.testng.annotations.Test;11import org.openqa.selenium.support.ui.ExpectedConditions;12import org.openqa.selenium.support.ui.WebDriverWait;13public class TestClass {14 public void test() {15 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Lenovo\\Desktop\\chromedriver.exe");16 WebDriver driver = new ChromeDriver();17 driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);18 Actions actions = new Actions(driver);19 WebDriverWait wait = new WebDriverWait(driver, 10);20 element.click();21 wait.until(ExpectedConditions.visibilityOf(element));22 actions.sendKeys(element, ScriptKey.chord(ScriptKey.ALT, ScriptKey.SHIFT, "a")).perform();23 actions.sendKeys(element, ScriptKey.chord(ScriptKey.ALT, ScriptKey
ScriptKey
Using AI Code Generation
1public class ScriptKey {2 public static void main(String[] args) {3 WebDriver driver = new FirefoxDriver();4 WebElement searchBox = driver.findElement(By.name("q"));5 searchBox.sendKeys("Selenium");6 searchBox.sendKeys(Keys.RETURN);7 driver.quit();8 }9}10public class Keys {11 public static void main(String[] args) {12 WebDriver driver = new FirefoxDriver();13 WebElement searchBox = driver.findElement(By.name("q"));14 searchBox.sendKeys("Selenium");15 searchBox.sendKeys(org.openqa.selenium.Keys.RETURN);16 driver.quit();17 }18}19import org.openqa.selenium.Keys;20public class Keys {21 public static void main(String[] args) {22 WebDriver driver = new FirefoxDriver();23 WebElement searchBox = driver.findElement(By.name("q"));24 searchBox.sendKeys("Selenium");25 searchBox.sendKeys(Keys.RETURN);26 driver.quit();27 }28}29import org.openqa.selenium.Keys;30public class Keys {31 public static void main(String[] args) {32 WebDriver driver = new FirefoxDriver();33 WebElement searchBox = driver.findElement(By.name("q"));34 searchBox.sendKeys("Selenium");35 searchBox.sendKeys(Keys.RETURN);36 driver.quit();37 }38}39import org.openqa.selenium.Keys;40public class Keys {41 public static void main(String[] args) {42 WebDriver driver = new FirefoxDriver();43 WebElement searchBox = driver.findElement(By.name("q"));44 searchBox.sendKeys("Selenium");45 searchBox.sendKeys(Keys.RETURN);46 driver.quit();47 }48}49import org.openqa.selenium.Keys;50public class Keys {51 public static void main(String[] args) {52 WebDriver driver = new FirefoxDriver();53 WebElement searchBox = driver.findElement(By.name("q"));54 searchBox.sendKeys("Selenium");55 searchBox.sendKeys(Keys.RETURN);56 driver.quit();57 }58}
ScriptKey
Using AI Code Generation
1import org.openqa.selenium.interactions.Action;2import org.openqa.selenium.interactions.Actions;3import org.openqa.selenium.interactions.ScriptKey;4public class KeyboardAction {5 public static void main(String[] args) throws InterruptedException {6 WebDriver driver = new FirefoxDriver();7 WebElement element = driver.findElement(By.name("q"));8 element.sendKeys("Cheese");9 Thread.sleep(5000);10 Actions builder = new Actions(driver);11 builder.sendKeys(element, ScriptKey.chord(ScriptKey.CONTROL, "a"));12 builder.sendKeys(element, ScriptKey.chord(ScriptKey.CONTROL, "c"));13 Action seriesOfActions = builder.build();14 seriesOfActions.perform();15 Thread.sleep(5000);16 driver.quit();17 }18}19keyDown()20keyUp()21sendKeys()22build()23perform()24You can use the keyDown() and keyUp() methods to perform any action like selecting
ScriptKey
Using AI Code Generation
1import org.openqa.selenium.ScriptKey;2import org.openqa.selenium.Keys;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.interactions.Actions;8import org.openqa.selenium.support.ui.WebDriverWait;9import org.openqa.selenium.support.ui.ExpectedConditions;10import java.util.concurrent.TimeUnit;11import java.lang.System;12import java.io.File;13import java.io.IOException;14import java.io.FileInputStream;15import java.util.Properties;16import java.lang.Thread;17import org.openqa.selenium.JavascriptExecutor;18import org.openqa.selenium.Alert;19import org.openqa.selenium.support.ui.Select;
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!