Best Cerberus-source code snippet using org.cerberus.service.webdriver.impl.WebDriverService.validXpathToErratumXpath
Source:WebDriverService.java
...371 private String getNewXPathFromErratum(Session session, Identifier identifier) {372373 LOG.debug("Entering ERRATUM Method ============================================================");374 String[] result = identifier.getLocator().split(ERRATUM_SEPARATOR);375 String oldXpath = validXpathToErratumXpath(result[0]);376 LOG.debug("OLD XPATH = " + oldXpath);377 String oldHtml = identifier.getLocator().replace(oldXpath + ERRATUM_SEPARATOR, "");378 LOG.debug("OLD HTML = " + oldHtml);379 String newHtml = "";380 String newXpath = "";381382 long start = new Date().getTime();383384 // Erratum loop with 30 attempts max385 int i = 0;386 long elapsedSinceStart = new Date().getTime() - start;387 while ((elapsedSinceStart < session.getCerberus_selenium_wait_element()) && (i < 100)) {388389 elapsedSinceStart = new Date().getTime() - start;390 i++;391 LOG.debug("ERRATUM ATTEMPT #" + i + " / Elapsed time from begining : " + elapsedSinceStart + " (timeout : " + session.getCerberus_selenium_wait_element() + ")");392393 try {394 Thread.sleep(1000);395 } catch (InterruptedException ex) {396 LOG.error(ex);397 }398399 newHtml = this.getPageSource(session);400401 LOG.debug("NEW HTML = " + newHtml.replace("\n", ""));402403 LOG.debug("Getting Erratum TreeMatcherResponse.");404 TreeMatcherResponse treeMatcherResponse = TreeMatcher.matchWebpages(oldHtml, newHtml);405406 // Filtering on non null edges and new map with old xpath as key407 Map<String, String> edges = treeMatcherResponse.getEdges()408 .stream()409 .filter(edge -> !(edge.getSource() == null || edge.getTarget() == null))410 .collect(Collectors.toMap(411 edge -> edge.getSource().getXPath(),412 edge -> edge.getTarget().getXPath()413 ));414 LOG.debug("Erratum TreeMatcherResponse Mapping result :");415 LOG.debug(edges);416417 // Verifying if errratum has found the new xpath418 if (edges.containsKey(oldXpath)) {419 newXpath = erratumXpathToValidXpath(edges.get(oldXpath));420 LOG.debug("Old XPath " + oldXpath + " found and converted to : " + newXpath);421 break;422 }423 }424425 return newXpath;426 }427428 private String erratumXpathToValidXpath(String erratumXpath) {429 return erratumXpath;430 }431432 private String validXpathToErratumXpath(String validXpath) {433 return validXpath;434 }435436 @Override437 public String getValueFromHTMLVisible(Session session, Identifier identifier) {438 String result = null;439 AnswerItem answer = this.getSeleniumElement(session, identifier, true, false);440 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {441 WebElement webElement = (WebElement) answer.getItem();442 if (webElement != null) {443 if (webElement.getTagName().equalsIgnoreCase("select")) {444 Select select = (Select) webElement;445 result = select.getFirstSelectedOption().getText();446 } else if (webElement.getTagName().equalsIgnoreCase("option") || webElement.getTagName().equalsIgnoreCase("input")) {
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!