How to use getCerberus_selenium_wait_element method of org.cerberus.engine.entity.Session class

Best Cerberus-source code snippet using org.cerberus.engine.entity.Session.getCerberus_selenium_wait_element

Source:WebDriverService.java Github

copy

Full Screen

...128 MessageEvent msg;129 By locator = this.getBy(identifier);130 LOG.debug("Waiting for Element : " + identifier.getIdentifier() + "=" + identifier.getLocator());131 try {132 WebDriverWait wait = new WebDriverWait(session.getDriver(), TimeUnit.MILLISECONDS.toSeconds(session.getCerberus_selenium_wait_element()));133 WebElement element;134 if (visible) {135 if (clickable) {136 element = wait.until(ExpectedConditions.elementToBeClickable(locator));137 } else {138 element = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));139 }140 } else {141 element = wait.until(ExpectedConditions.presenceOfElementLocated(locator));142 }143 answer.setItem(element);144 msg = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT);145 msg.setDescription(msg.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));146 } catch (TimeoutException exception) {147 LOG.warn("Exception waiting for element :" + exception);148 //throw new NoSuchElementException(identifier.getIdentifier() + "=" + identifier.getLocator());149 msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT);150 msg.setDescription(msg.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));151 }152 answer.setResultMessage(msg);153 return answer;154 }155156 @Override157 public String getValueFromHTMLVisible(Session session, Identifier identifier) {158 String result = null;159 AnswerItem answer = this.getSeleniumElement(session, identifier, true, false);160 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {161 WebElement webElement = (WebElement) answer.getItem();162 if (webElement != null) {163 if (webElement.getTagName().equalsIgnoreCase("select")) {164 Select select = (Select) webElement;165 result = select.getFirstSelectedOption().getText();166 } else if (webElement.getTagName().equalsIgnoreCase("option") || webElement.getTagName().equalsIgnoreCase("input")) {167 result = webElement.getAttribute("value");168 } else {169 result = webElement.getText();170 }171 }172 }173174 return result;175 }176177 @Override178 public String getValueFromHTML(Session session, Identifier identifier) {179 AnswerItem answer = this.getSeleniumElement(session, identifier, false, false);180 String result = null;181 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {182 WebElement webElement = (WebElement) answer.getItem();183 if (webElement != null) {184 if (webElement.getTagName().equalsIgnoreCase("select")) {185 if (webElement.getAttribute("disabled") == null || webElement.getAttribute("disabled").isEmpty()) {186 Select select = new Select(webElement);187 result = select.getFirstSelectedOption().getText();188 } else {189 result = webElement.getText();190 //result = "Unable to retrieve, element disabled ?";191 }192 } else if (webElement.getTagName().equalsIgnoreCase("option") || webElement.getTagName().equalsIgnoreCase("input")) {193 result = webElement.getAttribute("value");194 } else {195 result = webElement.getText();196 }197 /**198 * If return is empty, we search for hidden tags199 */200 if (StringUtil.isNullOrEmpty(result)) {201 String script = "return arguments[0].innerHTML";202 try {203 result = (String) ((JavascriptExecutor) session.getDriver()).executeScript(script, webElement);204 } catch (Exception e) {205 LOG.debug("getValueFromHTML locator : '" + identifier.getIdentifier() + "=" + identifier.getLocator() + "', exception : " + e.getMessage());206 }207 }208 }209 } else if (answer.isCodeEquals(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT.getCode())) {210 throw new NoSuchElementException(identifier.getIdentifier() + "=" + identifier.getLocator());211 }212 return result;213 }214215 @Override216 public String getAlertText(Session session) {217 Alert alert = session.getDriver().switchTo().alert();218 if (alert != null) {219 return alert.getText();220 }221222 return null;223 }224225 @Override226 public String getValueFromJS(Session session, String script) {227 JavascriptExecutor js = (JavascriptExecutor) session.getDriver();228 Object response = js.executeScript(script);229230 if (response == null) {231 return "";232 }233234 if (response instanceof String) {235 return (String) response;236 }237238 return String.valueOf(response);239 }240241 @Override242 public String getAttributeFromHtml(Session session, Identifier identifier, String attribute) {243 String result = null;244 try {245 AnswerItem answer = this.getSeleniumElement(session, identifier, true, false);246 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {247 WebElement webElement = (WebElement) answer.getItem();248 if (webElement != null) {249 result = webElement.getAttribute(attribute);250 }251 }252 } catch (WebDriverException exception) {253 LOG.warn(exception.toString());254 }255 return result;256 }257258 @Override259 public boolean isElementPresent(Session session, Identifier identifier) {260 try {261 AnswerItem answer = this.getSeleniumElement(session, identifier, false, false);262263 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {264 WebElement webElement = (WebElement) answer.getItem();265266 return webElement != null;267 }268 } catch (NoSuchElementException exception) {269 LOG.warn(exception.toString());270 }271 return false;272 }273274 @Override275 public boolean isElementNotPresent(Session session, Identifier identifier) {276 By locator = this.getBy(identifier);277 LOG.debug("Waiting for Element to be not present : " + identifier.getIdentifier() + "=" + identifier.getLocator());278 try {279 WebDriverWait wait = new WebDriverWait(session.getDriver(), TimeUnit.MILLISECONDS.toSeconds(session.getCerberus_selenium_wait_element()));280 return wait.until(ExpectedConditions.not(ExpectedConditions.presenceOfElementLocated(locator)));281 } catch (TimeoutException exception) {282 LOG.warn("Exception waiting for element to be not present :" + exception);283 return false;284 }285 }286287 @Override288 public boolean isElementVisible(Session session, Identifier identifier) {289 try {290 AnswerItem answer = this.getSeleniumElement(session, identifier, true, false);291 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {292 WebElement webElement = (WebElement) answer.getItem();293 return webElement != null && webElement.isDisplayed();294 }295296 } catch (NoSuchElementException exception) {297 LOG.warn(exception.toString());298 }299 return false;300 }301302 @Override303 public boolean isElementNotVisible(Session session, Identifier identifier) {304 By locator = this.getBy(identifier);305 LOG.debug("Waiting for Element to be not visible : " + identifier.getIdentifier() + "=" + identifier.getLocator());306 try {307 WebDriverWait wait = new WebDriverWait(session.getDriver(), TimeUnit.MILLISECONDS.toSeconds(session.getCerberus_selenium_wait_element()));308 return wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));309 } catch (TimeoutException exception) {310 LOG.warn("Exception waiting for element to be not visible :" + exception);311 return false;312 }313 }314315 @Override316 public String getPageSource(Session session) {317 return session.getDriver().getPageSource();318 }319320 @Override321 public String getTitle(Session session) {322 return session.getDriver().getTitle();323 }324325 /**326 * Return the current URL from Selenium.327 *328 * @param session329 * @param applicationUrl330 * @return current URL without HTTP://IP:PORT/CONTEXTROOT/331 * @throws CerberusEventException Cannot find application host (from332 * Database) inside current URL (from Selenium)333 */334 @Override335 public String getCurrentUrl(Session session, String applicationUrl) throws CerberusEventException {336 /*337 * Example: URL (http://cerberus.domain.fr/Cerberus/mypage/page/index.jsp)<br>338 * will return /mypage/page/index.jsp339 * No matter what, the output current relative URl will start by /340 */341 // We start to remove the protocol part of the urls.342 String cleanedCurrentURL = StringUtil.removeProtocolFromHostURL(session.getDriver().getCurrentUrl());343 String cleanedURL = StringUtil.removeProtocolFromHostURL(applicationUrl);344 // We remove from current url the host part of the application.345 String strings[] = cleanedCurrentURL.split(cleanedURL, 2);346 if (strings.length < 2) {347 MessageEvent msg = new MessageEvent(MessageEventEnum.CONTROL_FAILED_URL_NOT_MATCH_APPLICATION);348 msg.setDescription(msg.getDescription().replace("%HOST%", applicationUrl));349 msg.setDescription(msg.getDescription().replace("%CURRENTURL%", session.getDriver().getCurrentUrl()));350 LOG.warn(msg.toString());351 throw new CerberusEventException(msg);352 }353 String result = StringUtil.addPrefixIfNotAlready(strings[1], "/");354 return result;355 }356357 public File takeScreenShotFile(Session session) {358 boolean event = true;359 long timeout = System.currentTimeMillis() + (session.getCerberus_selenium_wait_element());360 //Try to capture picture. Try again until timeout is WebDriverException is raised.361 while (event) {362 try {363 WebDriver augmentedDriver = new Augmenter().augment(session.getDriver());364 File image = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);365366 if (image != null) {367 //logs for debug purposes368 LOG.info("WebDriverService: screen-shot taken with succes: " + image.getName() + "(size" + image.length() + ")");369 } else {370 LOG.warn("WebDriverService: screen-shot returned null: ");371 }372 return image;373 } catch (WebDriverException exception) {374 if (System.currentTimeMillis() >= timeout) {375 LOG.warn(exception.toString());376 }377 event = false;378 }379 }380381 return null;382 }383384 @Override385 public BufferedImage takeScreenShot(Session session) {386 BufferedImage newImage = null;387 boolean event = true;388 long timeout = System.currentTimeMillis() + (session.getCerberus_selenium_wait_element());389 //Try to capture picture. Try again until timeout is WebDriverException is raised.390 while (event) {391 try {392 WebDriver augmentedDriver = new Augmenter().augment(session.getDriver());393 File image = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);394 BufferedImage bufferedImage = ImageIO.read(image);395396 newImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);397 newImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.WHITE, null);398 return newImage;399 } catch (IOException exception) {400 LOG.warn(exception.toString());401 event = false;402 } catch (WebDriverException exception) {403 if (System.currentTimeMillis() >= timeout) {404 LOG.warn(exception.toString());405 event = false;406 }407 }408 }409 return newImage;410 }411412 @Override413 public boolean isElementInElement(Session session, Identifier identifier, Identifier childIdentifier) {414 By elementLocator = this.getBy(identifier);415 By childElementLocator = this.getBy(childIdentifier);416417 return (session.getDriver().findElement(elementLocator) != null418 && session.getDriver().findElement(elementLocator).findElement(childElementLocator) != null);419 }420421 @Override422 public boolean isElementNotClickable(Session session, Identifier identifier) {423 By locator = this.getBy(identifier);424 LOG.debug("Waiting for Element to be not clickable : " + identifier.getIdentifier() + "=" + identifier.getLocator());425 try {426 WebDriverWait wait = new WebDriverWait(session.getDriver(), TimeUnit.MILLISECONDS.toSeconds(session.getCerberus_selenium_wait_element()));427 return wait.until(ExpectedConditions.not(ExpectedConditions.elementToBeClickable(locator)));428 } catch (TimeoutException exception) {429 LOG.warn("Exception waiting for element to be not clickable :" + exception);430 return false;431 }432 }433434 @Override435 public boolean isElementClickable(Session session, Identifier identifier) {436 try {437 AnswerItem answer = this.getSeleniumElement(session, identifier, true, true);438 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {439 WebElement webElement = (WebElement) answer.getItem();440441 return webElement != null;442 }443 } catch (NoSuchElementException exception) {444 LOG.warn(exception.toString());445 }446 return false;447 }448449 @Override450 public MessageEvent doSeleniumActionClick(Session session, final Identifier identifier, boolean waitForVisibility, boolean waitForClickability) {451 MessageEvent message;452 try {453454 AnswerItem answer = this.getSeleniumElement(session, identifier, waitForVisibility, waitForClickability);455 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {456 final WebElement webElement = (WebElement) answer.getItem();457458 if (webElement != null) {459 // We noticed that sometimes, webelement.click never finished whatever the timeout set.460 // Below is an implementation to secure timeout on thread before calling selenium.461 // This is a test that can be extended or clean depending on the result.462 ExecutorService executor = Executors.newCachedThreadPool();463 Callable<MessageEvent> task = new Callable<MessageEvent>() {464 public MessageEvent call() {465 MessageEvent message;466 Actions actions = new Actions(session.getDriver());467 actions.click(webElement);468 actions.build().perform();469 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICK);470 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));471 return message;472 }473 };474 Future<MessageEvent> future = executor.submit(task);475 try {476 MessageEvent result = future.get(session.getCerberus_selenium_action_click_timeout(), TimeUnit.MILLISECONDS);477 return result;478 } catch (java.util.concurrent.TimeoutException ex) {479 // handle the timeout480 LOG.warn("Exception clicking on element :" + ex, ex);481 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);482 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));483 return message;484 } catch (InterruptedException e) {485 // handle the interrupts486 LOG.warn("Exception clicking on element :" + e, e);487 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK);488 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()).replace("%MESS%", e.toString()));489 return message;490 } catch (ExecutionException e) {491 // handle other exceptions492 LOG.warn("Exception clicking on element :" + e, e);493 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT);494 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()).replace("%MESS%", e.toString()));495 return message;496 } finally {497 future.cancel(true);498 }499 }500 }501502 return answer.getResultMessage();503 } catch (NoSuchElementException exception) {504 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CLICK_NO_SUCH_ELEMENT);505 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));506 LOG.debug(exception.toString());507 return message;508// } catch (TimeoutException exception) {509// message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);510// message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));511// MyLogger.log(WebDriverService.class.getName(), Level.WARN, exception.toString());512// return message;513 } catch (WebDriverException exception) {514 LOG.warn(exception.toString());515 return parseWebDriverException(exception);516 }517518 }519520 @Override521 public MessageEvent doSeleniumActionMouseDown(Session session, Identifier identifier) {522 MessageEvent message;523 try {524525 AnswerItem answer = this.getSeleniumElement(session, identifier, true, true);526 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {527 WebElement webElement = (WebElement) answer.getItem();528 if (webElement != null) {529 Actions actions = new Actions(session.getDriver());530 actions.clickAndHold(webElement);531 actions.build().perform();532 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEDOWN);533 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));534 return message;535 }536 }537538 return answer.getResultMessage();539 } catch (NoSuchElementException exception) {540 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEDOWN_NO_SUCH_ELEMENT);541 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));542 LOG.debug(exception.toString());543 return message;544 } catch (TimeoutException exception) {545 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);546 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));547 LOG.warn(exception.toString());548 return message;549 } catch (WebDriverException exception) {550 LOG.warn(exception.toString());551 return parseWebDriverException(exception);552 }553 }554555 @Override556 public MessageEvent doSeleniumActionMouseUp(Session session, Identifier identifier) {557 MessageEvent message;558 try {559 AnswerItem answer = this.getSeleniumElement(session, identifier, true, true);560 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {561 WebElement webElement = (WebElement) answer.getItem();562 if (webElement != null) {563 Actions actions = new Actions(session.getDriver());564 actions.release(webElement);565 actions.build().perform();566 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEUP);567 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));568 return message;569 }570 }571572 return answer.getResultMessage();573 } catch (NoSuchElementException exception) {574 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEUP_NO_SUCH_ELEMENT);575 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));576 LOG.debug(exception.toString());577 return message;578 } catch (TimeoutException exception) {579 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);580 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));581 LOG.warn(exception.toString());582 return message;583 } catch (WebDriverException exception) {584 LOG.warn(exception.toString());585 return parseWebDriverException(exception);586 }587 }588589 @Override590 public MessageEvent doSeleniumActionSwitchToWindow(Session session, Identifier identifier) {591 MessageEvent message;592 String windowTitle = identifier.getLocator();593594 String currentHandle;595 // Current serial handle of the window.596 // Add try catch to handle not exist anymore window (like when popup is closed).597 try {598 currentHandle = session.getDriver().getWindowHandle();599 } catch (NoSuchWindowException exception) {600 currentHandle = null;601 LOG.debug("Window is closed ? " + exception.toString());602 }603604 try {605 // Get serials handles list of all browser windows606 Set<String> handles = session.getDriver().getWindowHandles();607608 // Loop into each of them609 for (String windowHandle : handles) {610 if (!windowHandle.equals(currentHandle)) {611 session.getDriver().switchTo().window(windowHandle);612 if (checkIfExpectedWindow(session, identifier.getIdentifier(), identifier.getLocator())) {613 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SWITCHTOWINDOW);614 message.setDescription(message.getDescription().replace("%WINDOW%", windowTitle));615 return message;616 }617 }618 LOG.debug("windowHandle=" + windowHandle);619 }620 } catch (NoSuchElementException exception) {621 LOG.debug(exception.toString());622 } catch (TimeoutException exception) {623 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);624 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));625 LOG.warn(exception.toString());626 return message;627 } catch (WebDriverException exception) {628 LOG.warn(exception.toString());629 return parseWebDriverException(exception);630 }631 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SWITCHTOWINDOW_NO_SUCH_ELEMENT);632 message.setDescription(message.getDescription().replace("%WINDOW%", windowTitle));633 return message;634 }635636 @Override637 public MessageEvent doSeleniumActionManageDialog(Session session, Identifier identifier) {638 MessageEvent message;639 try {640 if ("ok".equalsIgnoreCase(identifier.getLocator())) {641 // Accept javascript popup dialog.642 session.getDriver().switchTo().alert().accept();643 session.getDriver().switchTo().defaultContent();644 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLOSE_ALERT);645 return message;646 } else if ("cancel".equalsIgnoreCase(identifier.getLocator())) {647 // Dismiss javascript popup dialog.648 session.getDriver().switchTo().alert().dismiss();649 session.getDriver().switchTo().defaultContent();650 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLOSE_ALERT);651 return message;652 }653 } catch (NoSuchWindowException exception) {654 // Add try catch to handle not exist anymore alert popup (like when popup is closed).655 LOG.debug("Alert popup is closed ? " + exception.toString());656 } catch (TimeoutException exception) {657 LOG.warn(exception.toString());658 } catch (WebDriverException exception) {659 LOG.debug("Alert popup is closed ? " + exception.toString());660 return parseWebDriverException(exception);661 }662 return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSE_ALERT);663 }664665 private boolean checkIfExpectedWindow(Session session, String identifier, String value) {666667 boolean result = false;668 WebDriverWait wait = new WebDriverWait(session.getDriver(), TIMEOUT_WEBELEMENT);669 String title;670671 switch (identifier) {672 case Identifier.IDENTIFIER_URL: {673674 wait.until(ExpectedConditions.not(ExpectedConditions.urlToBe("about:blank")));675 return session.getDriver().getCurrentUrl().equals(value);676 }677 case Identifier.IDENTIFIER_REGEXTITLE:678 wait.until(ExpectedConditions.not(ExpectedConditions.titleIs("")));679 title = session.getDriver().getTitle();680 Pattern pattern = Pattern.compile(value);681 Matcher matcher = pattern.matcher(title);682 result = matcher.find();683 default:684 wait.until(ExpectedConditions.not(ExpectedConditions.titleIs("")));685 title = session.getDriver().getTitle();686 if (title.equals(value)) {687 result = true;688 }689 }690 return result;691 }692693 @Override694 public MessageEvent doSeleniumActionDoubleClick(Session session, Identifier identifier, boolean waitForVisibility, boolean waitForClickability) {695 MessageEvent message;696 try {697 AnswerItem answer = this.getSeleniumElement(session, identifier, waitForVisibility, waitForClickability);698 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {699 WebElement webElement = (WebElement) answer.getItem();700 if (webElement != null) {701 Actions actions = new Actions(session.getDriver());702 actions.doubleClick(webElement);703 actions.build().perform();704 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_DOUBLECLICK);705 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));706 return message;707 }708 }709 message = answer.getResultMessage();710 return message;711 } catch (NoSuchElementException exception) {712 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DOUBLECLICK_NO_SUCH_ELEMENT);713 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));714 LOG.debug(exception.toString());715 return message;716 } catch (TimeoutException exception) {717 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);718 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));719 LOG.warn(exception.toString());720 return message;721 } catch (WebDriverException exception) {722 LOG.warn(exception.toString());723 return parseWebDriverException(exception);724 }725 }726727 @Override728 public MessageEvent doSeleniumActionType(Session session, Identifier identifier, String property, String propertyName) {729 MessageEvent message;730 try {731 AnswerItem answer = this.getSeleniumElement(session, identifier, true, true);732 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {733 WebElement webElement = (WebElement) answer.getItem();734 if (webElement != null) {735 webElement.clear();736 if (!StringUtil.isNull(property)) {737 webElement.sendKeys(property);738 }739 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TYPE);740 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));741 if (!StringUtil.isNull(property)) {742 message.setDescription(message.getDescription().replace("%DATA%", ParameterParserUtil.securePassword(property, propertyName)));743 } else {744 message.setDescription(message.getDescription().replace("%DATA%", "No property"));745 }746 return message;747 }748 }749 return answer.getResultMessage();750 } catch (NoSuchElementException exception) {751 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TYPE_NO_SUCH_ELEMENT);752 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));753 LOG.debug(exception.toString());754 return message;755 } catch (TimeoutException exception) {756 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);757 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));758 LOG.warn(exception.toString());759 return message;760 } catch (WebDriverException exception) {761 LOG.warn(exception.toString());762 return parseWebDriverException(exception);763 }764 }765766 @Override767 public MessageEvent doSeleniumActionMouseOver(Session session, Identifier identifier) {768 MessageEvent message;769 try {770 AnswerItem answer = this.getSeleniumElement(session, identifier, true, true);771 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {772 WebElement menuHoverLink = (WebElement) answer.getItem();773 if (menuHoverLink != null) {774 Actions actions = new Actions(session.getDriver());775 actions.moveToElement(menuHoverLink);776 actions.build().perform();777 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_MOUSEOVER);778 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));779 return message;780 }781 }782783 return answer.getResultMessage();784 } catch (NoSuchElementException exception) {785 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVER_NO_SUCH_ELEMENT);786 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));787 LOG.debug(exception.toString());788 return message;789 } catch (TimeoutException exception) {790 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);791 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));792 LOG.warn(exception.toString());793 return message;794 } catch (WebDriverException exception) {795 LOG.warn(exception.toString());796 return parseWebDriverException(exception);797 }798 }799800 @Override801 public MessageEvent doSeleniumActionWait(Session session, Identifier identifier) {802 MessageEvent message;803 try {804 WebDriverWait wait = new WebDriverWait(session.getDriver(), TIMEOUT_WEBELEMENT);805 wait.until(ExpectedConditions.presenceOfElementLocated(this.getBy(identifier)));806 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT);807 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));808 return message;809 } catch (TimeoutException exception) {810 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT);811 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));812 LOG.debug(exception.toString());813 return message;814 }815 }816817 @Override818 public MessageEvent doSeleniumActionWaitVanish(Session session, Identifier identifier) {819 MessageEvent message;820 try {821 WebDriverWait wait = new WebDriverWait(session.getDriver(), TIMEOUT_WEBELEMENT);822 wait.until(ExpectedConditions.invisibilityOfElementLocated(this.getBy(identifier)));823 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAITVANISH_ELEMENT);824 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));825 return message;826 } catch (TimeoutException exception) {827 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT);828 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));829 LOG.debug(exception.toString());830 return message;831 }832 }833834 /**835 * Disable the headless status of the running application preventing Robot836 * to work through a web container837 */838 public void disableHeadlessApplicationControl() {839 System.setProperty("java.awt.headless", "false");840 try {841 Field headlessField = GraphicsEnvironment.class.getDeclaredField("headless");842 headlessField.setAccessible(true);843 headlessField.set(null, Boolean.FALSE);844 } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {845 LOG.warn(ex.toString());846 }847 }848849 /**850 * Interface to Windows instrumentation in order to have control over all851 * the others applications running in the OS852 */853 public interface User32 extends W32APIOptions {854855 User32 instance = (User32) Native.loadLibrary("user32", User32.class, DEFAULT_OPTIONS);856857 boolean ShowWindow(HWND hWnd, int nCmdShow);858859 boolean SetForegroundWindow(HWND hWnd);860861 HWND FindWindow(String winClass, String title);862 int SW_SHOW = 1;863 }864865 /**866 * Tries to focus the browser window thanks to the title given by the867 * webdriver in order to put it in foreground for Robot to work (Only works868 * on Windows so far, another way is to find for Xorg)869 *870 * @param session Webdriver session instance871 * @return True if the window is found, False otherwise872 */873 public boolean focusBrowserWindow(Session session) {874 WebDriver driver = session.getDriver();875 String title = driver.getTitle();876 User32 user32 = User32.instance;877878 // Arbitrary879 String[] browsers = new String[]{880 "",881 "Google Chrome",882 "Mozilla Firefox",883 "Opera",884 "Safari",885 "Internet Explorer",886 "Microsoft Edge",};887888 for (String browser : browsers) {889 HWND window;890 if (browser.isEmpty()) {891 window = user32.FindWindow(null, title);892 } else {893 window = user32.FindWindow(null, title + " - " + browser);894 }895 if (user32.ShowWindow(window, User32.SW_SHOW)) {896 return user32.SetForegroundWindow(window);897 }898 }899 return false;900 }901902 @Override903 public MessageEvent doSeleniumActionKeyPress(Session session, Identifier identifier, String property) {904905 MessageEvent message;906 try {907 if (!StringUtil.isNullOrEmpty(identifier.getLocator())) {908 AnswerItem answer = this.getSeleniumElement(session, identifier, true, true);909 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {910 WebElement webElement = (WebElement) answer.getItem();911 if (webElement != null) {912 webElement.sendKeys(Keys.valueOf(property));913 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS);914 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));915 message.setDescription(message.getDescription().replace("%DATA%", property));916 return message;917 }918919 }920 return answer.getResultMessage();921922 } else {923 try {924 //disable headless application warning for Robot925 this.disableHeadlessApplicationControl();926927 //create wait action928 WebDriverWait wait = new WebDriverWait(session.getDriver(), 01);929930 //focus the browser window for Robot to work931 if (this.focusBrowserWindow(session)) {932 //wait until the browser is focused933 wait.withTimeout(TIMEOUT_FOCUS, TimeUnit.MILLISECONDS);934 }935936 //gets the robot 937 Robot r = new Robot();938 //converts the Key description sent through Cerberus into the AWT key code939 int keyCode = KeyCodeEnum.getAWTKeyCode(property);940941 if (keyCode != KeyCodeEnum.NOT_VALID.getKeyCode()) {942 //if the code is valid then presses the key and releases the key943 r.keyPress(keyCode);944 r.keyRelease(keyCode);945 //wait until the action is performed946 wait.withTimeout(TIMEOUT_WEBELEMENT, TimeUnit.MILLISECONDS);947948 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT);949 } else {950 //the key enterer is not valid951 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NOT_AVAILABLE);952 LOG.debug("Key " + property + "is not available in the current environment");953 }954955 message.setDescription(message.getDescription().replace("%KEY%", property));956957 } catch (AWTException ex) {958 LOG.warn(ex);959 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_ENV_ERROR);960 }961 }962963 } catch (NoSuchElementException exception) {964 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NO_SUCH_ELEMENT);965 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));966 LOG.debug(exception.toString());967968 } catch (TimeoutException exception) {969 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);970 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));971 LOG.warn(exception.toString());972973 } catch (WebDriverException exception) {974 LOG.warn(exception.toString());975 return parseWebDriverException(exception);976977 }978 return message;979 }980981 @Override982 public MessageEvent doSeleniumActionOpenURL(Session session, String host, Identifier identifier, boolean withBase) {983 MessageEvent message;984 String url = "";985 try {986 if (!StringUtil.isNull(identifier.getLocator())) {987 if (withBase) {988 host = StringUtil.cleanHostURL(host);989 url = StringUtil.getURLFromString(host, "", identifier.getLocator(), "");990 } else {991 url = StringUtil.cleanHostURL(identifier.getLocator());992 }993 session.getDriver().get(url);994 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_OPENURL);995 message.setDescription(message.getDescription().replace("%URL%", url));996997 } else {998 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_OPENURL);999 message.setDescription(message.getDescription().replace("%URL%", url));1000 }1001 } catch (TimeoutException exception) {1002 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_OPENURL_TIMEOUT);1003 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_pageLoadTimeout())));1004 message.setDescription(message.getDescription().replace("%URL%", url));1005 LOG.warn(exception.toString());1006 } catch (WebDriverException exception) {1007 LOG.warn(exception.toString());1008 return parseWebDriverException(exception);1009 }10101011 return message;1012 }10131014 @Override1015 public MessageEvent doSeleniumActionSelect(Session session, Identifier object, Identifier property) {1016 MessageEvent message;1017 try {1018 Select select;1019 try {1020 AnswerItem answer = this.getSeleniumElement(session, object, true, true);1021 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {1022 WebElement webElement = (WebElement) answer.getItem();1023 if (webElement != null) {1024 select = new Select(webElement);1025 this.selectRequestedOption(select, property, object.getIdentifier() + "=" + object.getLocator());1026 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SELECT);1027 message.setDescription(message.getDescription().replace("%ELEMENT%", object.getIdentifier() + "=" + object.getLocator()));1028 message.setDescription(message.getDescription().replace("%DATA%", property.getIdentifier() + "=" + property.getLocator()));1029 return message;1030 }1031 }10321033 return answer.getResultMessage();1034 } catch (NoSuchElementException exception) {1035 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT_NO_SUCH_ELEMENT);1036 message.setDescription(message.getDescription().replace("%ELEMENT%", object.getIdentifier() + "=" + object.getLocator()));1037 LOG.debug(exception.toString());1038 return message;1039 } catch (TimeoutException exception) {1040 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);1041 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));1042 LOG.warn(exception.toString());1043 return message;1044 }10451046 } catch (CerberusEventException ex) {1047 LOG.warn(ex);1048 return ex.getMessageError();1049 }1050 }10511052 private void selectRequestedOption(Select select, Identifier property, String element) throws CerberusEventException {1053 MessageEvent message;1054 try {1055 if (property.getIdentifier().equalsIgnoreCase("value")) {1056 select.selectByValue(property.getLocator());1057 } else if (property.getIdentifier().equalsIgnoreCase("label")) {1058 select.selectByVisibleText(property.getLocator());1059 } else if (property.getIdentifier().equalsIgnoreCase("index") && StringUtil.isInteger(property.getLocator())) {1060 select.selectByIndex(Integer.parseInt(property.getLocator()));1061 } else if (property.getIdentifier().equalsIgnoreCase("regexValue")1062 || property.getIdentifier().equalsIgnoreCase("regexIndex")1063 || property.getIdentifier().equalsIgnoreCase("regexLabel")) {1064 java.util.List<WebElement> list = select.getOptions();1065 if (property.getIdentifier().equalsIgnoreCase("regexValue")) {1066 for (WebElement option : list) {1067 String optionValue = option.getAttribute("value");1068 Pattern pattern = Pattern.compile(property.getLocator());1069 Matcher matcher = pattern.matcher(optionValue);1070 if (matcher.find()) {1071 select.selectByValue(optionValue);1072 }1073 }1074 } else if (property.getIdentifier().equalsIgnoreCase("regexLabel")) {1075 for (WebElement option : list) {1076 String optionLabel = option.getText();1077 Pattern pattern = Pattern.compile(property.getLocator());1078 Matcher matcher = pattern.matcher(optionLabel);10791080 if (matcher.find()) {1081 select.selectByVisibleText(optionLabel);1082 }1083 }1084 } else if (property.getIdentifier().equalsIgnoreCase("regexIndex") && StringUtil.isInteger(property.getLocator())) {1085 for (WebElement option : list) {1086 Integer id = 0;1087 Pattern pattern = Pattern.compile(property.getLocator());1088 Matcher matcher = pattern.matcher(id.toString());10891090 if (matcher.find()) {1091 select.selectByIndex(Integer.parseInt(property.getLocator()));1092 }1093 id++;1094 }1095 }1096 } else {1097 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT_NO_IDENTIFIER);1098 message.setDescription(message.getDescription().replace("%IDENTIFIER%", property.getIdentifier()));1099 throw new CerberusEventException(message);1100 }1101 } catch (NoSuchElementException exception) {1102 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT_NO_SUCH_VALUE);1103 message.setDescription(message.getDescription().replace("%ELEMENT%", element));1104 message.setDescription(message.getDescription().replace("%DATA%", property.getIdentifier() + "=" + property.getLocator()));1105 throw new CerberusEventException(message);1106 } catch (WebDriverException exception) {1107 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY);1108 message.setDescription(message.getDescription().replace("%ERROR%", exception.getMessage().split("\n")[0]));1109 LOG.warn(exception.toString());1110 throw new CerberusEventException(message);1111 } catch (PatternSyntaxException e) {1112 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT_REGEX_INVALIDPATERN);1113 message.setDescription(message.getDescription().replace("%PATERN%", property.getLocator()));1114 message.setDescription(message.getDescription().replace("%ERROR%", e.getMessage()));1115 throw new CerberusEventException(message);1116 }1117 }11181119 @Override1120 public MessageEvent doSeleniumActionUrlLogin(Session session, String host, String uri) {1121 MessageEvent message;11221123 host = StringUtil.cleanHostURL(host);1124 String url = StringUtil.getURLFromString(host, "", uri, "");11251126 try {1127 session.getDriver().get(url);1128 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_URLLOGIN);1129 message.setDescription(message.getDescription().replace("%URL%", url));11301131 } catch (TimeoutException exception) {1132 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_URLLOGIN_TIMEOUT);1133 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_pageLoadTimeout())));1134 message.setDescription(message.getDescription().replace("%URL%", url));1135 LOG.warn(exception.toString());1136 } catch (Exception e) {1137 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_URLLOGIN);1138 message.setDescription(message.getDescription().replace("%URL%", url) + " " + e.getMessage());1139 }1140 return message;1141 }11421143 @Override1144 public MessageEvent doSeleniumActionFocusToIframe(Session session, Identifier identifier) {1145 MessageEvent message;1146 try {1147 AnswerItem answer = this.getSeleniumElement(session, identifier, false, false);11481149 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {1150 WebElement webElement = (WebElement) answer.getItem();1151 if (webElement != null) {1152 session.getDriver().switchTo().frame(webElement);1153 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_FOCUSTOIFRAME);1154 message.setDescription(message.getDescription().replace("%IFRAME%", identifier.getIdentifier() + "=" + identifier.getLocator()));1155 return message;1156 }11571158 }1159 return answer.getResultMessage();11601161 } catch (NoSuchElementException exception) {1162 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_FOCUS_NO_SUCH_ELEMENT);1163 message.setDescription(message.getDescription().replace("%IFRAME%", identifier.getIdentifier() + "=" + identifier.getLocator()));1164 LOG.debug(exception.toString());1165 } catch (TimeoutException exception) {1166 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);1167 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));1168 LOG.warn(exception.toString());1169 return message;1170 } catch (WebDriverException exception) {1171 LOG.warn(exception.toString());1172 return parseWebDriverException(exception);1173 }1174 return message;1175 }11761177 @Override1178 public MessageEvent doSeleniumActionFocusDefaultIframe(Session session) {1179 MessageEvent message;11801181 try {1182 session.getDriver().switchTo().defaultContent();1183 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_FOCUSDEFAULTIFRAME);1184 } catch (WebDriverException exception) {1185 LOG.warn(exception.toString());1186 return parseWebDriverException(exception);1187 }11881189 return message;1190 }11911192 @Override1193 public String getFromCookie(Session session, String cookieName, String cookieParameter) {1194 Cookie cookie = session.getDriver().manage().getCookieNamed(cookieName);1195 if (cookie != null) {1196 if (cookieParameter.equals("name")) {1197 return cookie.getName();1198 }1199 if (cookieParameter.equals("expiry")) {1200 return cookie.getExpiry().toString();1201 }1202 if (cookieParameter.equals("value")) {1203 return cookie.getValue();1204 }1205 if (cookieParameter.equals("domain")) {1206 return cookie.getDomain();1207 }1208 if (cookieParameter.equals("path")) {1209 return cookie.getPath();1210 }1211 if (cookieParameter.equals("isHttpOnly")) {1212 return String.valueOf(cookie.isHttpOnly());1213 }1214 if (cookieParameter.equals("isSecure")) {1215 return String.valueOf(cookie.isSecure());1216 }1217 } else {1218 return "cookieNotFound";1219 }1220 return null;1221 }12221223 @Override1224 public List<String> getSeleniumLog(Session session) {1225 List<String> result = new ArrayList();1226 Logs logs = session.getDriver().manage().logs();12271228 for (String logType : logs.getAvailableLogTypes()) {1229 LogEntries logEntries = logs.get(logType);1230 result.add("********************" + logType + "********************\n");1231 for (LogEntry logEntry : logEntries) {1232 result.add(new Date(logEntry.getTimestamp()) + " : " + logEntry.getLevel() + " : " + logEntry.getMessage() + "\n");1233 }1234 }12351236 return result;1237 }12381239 @Override1240 public MessageEvent doSeleniumActionRightClick(Session session, Identifier identifier) {1241 MessageEvent message;1242 try {1243 AnswerItem answer = this.getSeleniumElement(session, identifier, true, true);1244 if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {1245 WebElement webElement = (WebElement) answer.getItem();1246 if (webElement != null) {1247 Actions actions = new Actions(session.getDriver());1248 actions.contextClick(webElement);1249 actions.build().perform();1250 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_RIGHTCLICK);1251 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));1252 return message;1253 }1254 }12551256 return answer.getResultMessage();1257 } catch (NoSuchElementException exception) {1258 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_RIGHTCLICK_NO_SUCH_ELEMENT);1259 message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));1260 LOG.debug(exception.toString());1261 return message;1262 } catch (TimeoutException exception) {1263 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);1264 message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));1265 LOG.warn(exception.toString());1266 return message;1267 } catch (WebDriverException exception) {1268 LOG.warn(exception.toString());1269 return parseWebDriverException(exception);1270 }1271 }12721273 /**1274 * @author vertigo171275 * @param exception the exception need to be parsed by Cerberus1276 * @return A new Event Message with selenium related description1277 */1278 private MessageEvent parseWebDriverException(WebDriverException exception) { ...

Full Screen

Full Screen

getCerberus_selenium_wait_element

Using AI Code Generation

copy

Full Screen

1import org.cerberus.engine.entity.Session;2Session session = cerberusSession.getSession();3session.getCerberus_selenium_wait_element("css", "div#mydiv", 30, 500, "CURRENT", "DOCUMENT", "VISIBLE", "ENABLED", "NOT_STALE");4import org.cerberus.engine.entity.Session;5Session session = cerberusSession.getSession();6session.getCerberus_selenium_wait_element("css", "div#mydiv", 30, 500, "CURRENT", "DOCUMENT", "VISIBLE", "ENABLED", "NOT_STALE");7import org.cerberus.engine.entity.Session;8Session session = cerberusSession.getSession();9session.getCerberus_selenium_wait_element("css", "div#mydiv", 30, 500, "CURRENT", "DOCUMENT",

Full Screen

Full Screen

getCerberus_selenium_wait_element

Using AI Code Generation

copy

Full Screen

1String script = testcase.getScript();2script = script.replaceFirst("waitForElementPresent", "waitForElementPresentWithTimeout");3testcase.setScript(script);4String script = testcase.getScript();5script = script.replaceAll("waitForElementPresent", "waitForElementPresentWithTimeout");6testcase.setScript(script);7String script = testcase.getScript();8script = script.replaceAll("(?m)^waitForElementPresent", "waitForElementPresentWithTimeout");9testcase.setScript(script);10String script = testcase.getScript();11script = script.replaceAll("(?m)^waitForElementPresent", "waitForElementPresentWithTimeout");12testcase.setScript(script);13String script = testcase.getScript();14script = script.replaceAll("(?m)^waitForElementPresent", "waitForElementPresentWithTimeout");15testcase.setScript(script);

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Session

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful