use of org.openqa.selenium.TimeoutException in project cerberus-source by cerberustesting.
the class WebDriverService method doSeleniumActionUrlLogin.
@Override
public MessageEvent doSeleniumActionUrlLogin(Session session, String host, String uri) {
MessageEvent message;
host = StringUtil.cleanHostURL(host);
String url = StringUtil.getURLFromString(host, "", uri, "");
try {
session.getDriver().get(url);
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_URLLOGIN);
message.setDescription(message.getDescription().replace("%URL%", url));
} catch (TimeoutException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_URLLOGIN_TIMEOUT);
message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_pageLoadTimeout())));
message.setDescription(message.getDescription().replace("%URL%", url));
LOG.warn(exception.toString());
} catch (Exception e) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_URLLOGIN);
message.setDescription(message.getDescription().replace("%URL%", url) + " " + e.getMessage());
}
return message;
}
use of org.openqa.selenium.TimeoutException in project cerberus-source by cerberustesting.
the class WebDriverService method doSeleniumActionDoubleClick.
@Override
public MessageEvent doSeleniumActionDoubleClick(Session session, Identifier identifier, boolean waitForVisibility, boolean waitForClickability) {
MessageEvent message;
try {
AnswerItem answer = this.getSeleniumElement(session, identifier, waitForVisibility, waitForClickability);
if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
WebElement webElement = (WebElement) answer.getItem();
if (webElement != null) {
Actions actions = new Actions(session.getDriver());
actions.doubleClick(webElement);
actions.build().perform();
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_DOUBLECLICK);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
return message;
}
}
message = answer.getResultMessage();
return message;
} catch (NoSuchElementException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_DOUBLECLICK_NO_SUCH_ELEMENT);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
LOG.debug(exception.toString());
return message;
} catch (TimeoutException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);
message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));
LOG.warn(exception.toString());
return message;
} catch (WebDriverException exception) {
LOG.warn(exception.toString());
return parseWebDriverException(exception);
}
}
use of org.openqa.selenium.TimeoutException in project cerberus-source by cerberustesting.
the class WebDriverService method doSeleniumActionManageDialog.
@Override
public MessageEvent doSeleniumActionManageDialog(Session session, Identifier identifier) {
MessageEvent message;
try {
if ("ok".equalsIgnoreCase(identifier.getLocator())) {
// Accept javascript popup dialog.
session.getDriver().switchTo().alert().accept();
session.getDriver().switchTo().defaultContent();
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLOSE_ALERT);
return message;
} else if ("cancel".equalsIgnoreCase(identifier.getLocator())) {
// Dismiss javascript popup dialog.
session.getDriver().switchTo().alert().dismiss();
session.getDriver().switchTo().defaultContent();
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLOSE_ALERT);
return message;
}
} catch (NoSuchWindowException exception) {
// Add try catch to handle not exist anymore alert popup (like when popup is closed).
LOG.debug("Alert popup is closed ? " + exception.toString());
} catch (TimeoutException exception) {
LOG.warn(exception.toString());
} catch (WebDriverException exception) {
LOG.debug("Alert popup is closed ? " + exception.toString());
return parseWebDriverException(exception);
}
return new MessageEvent(MessageEventEnum.ACTION_FAILED_CLOSE_ALERT);
}
use of org.openqa.selenium.TimeoutException in project cerberus-source by cerberustesting.
the class WebDriverService method doSeleniumActionKeyPress.
@Override
public MessageEvent doSeleniumActionKeyPress(Session session, Identifier identifier, String property) {
MessageEvent message;
try {
if (!StringUtil.isNullOrEmpty(identifier.getLocator())) {
AnswerItem answer = this.getSeleniumElement(session, identifier, true, true);
if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
WebElement webElement = (WebElement) answer.getItem();
if (webElement != null) {
webElement.sendKeys(Keys.valueOf(property));
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
message.setDescription(message.getDescription().replace("%DATA%", property));
return message;
}
}
return answer.getResultMessage();
} else {
try {
// disable headless application warning for Robot
this.disableHeadlessApplicationControl();
// create wait action
WebDriverWait wait = new WebDriverWait(session.getDriver(), 01);
// focus the browser window for Robot to work
if (this.focusBrowserWindow(session)) {
// wait until the browser is focused
wait.withTimeout(TIMEOUT_FOCUS, TimeUnit.MILLISECONDS);
}
// gets the robot
Robot r = new Robot();
// converts the Key description sent through Cerberus into the AWT key code
int keyCode = KeyCodeEnum.getAWTKeyCode(property);
if (keyCode != KeyCodeEnum.NOT_VALID.getKeyCode()) {
// if the code is valid then presses the key and releases the key
r.keyPress(keyCode);
r.keyRelease(keyCode);
// wait until the action is performed
wait.withTimeout(TIMEOUT_WEBELEMENT, TimeUnit.MILLISECONDS);
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT);
} else {
// the key enterer is not valid
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NOT_AVAILABLE);
LOG.debug("Key " + property + "is not available in the current environment");
}
message.setDescription(message.getDescription().replace("%KEY%", property));
} catch (AWTException ex) {
LOG.warn(ex);
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_ENV_ERROR);
}
}
} catch (NoSuchElementException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_NO_SUCH_ELEMENT);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
LOG.debug(exception.toString());
} catch (TimeoutException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_TIMEOUT);
message.setDescription(message.getDescription().replace("%TIMEOUT%", String.valueOf(session.getCerberus_selenium_wait_element())));
LOG.warn(exception.toString());
} catch (WebDriverException exception) {
LOG.warn(exception.toString());
return parseWebDriverException(exception);
}
return message;
}
use of org.openqa.selenium.TimeoutException in project cerberus-source by cerberustesting.
the class WebDriverService method doSeleniumActionWait.
@Override
public MessageEvent doSeleniumActionWait(Session session, Identifier identifier) {
MessageEvent message;
try {
WebDriverWait wait = new WebDriverWait(session.getDriver(), TIMEOUT_WEBELEMENT);
wait.until(ExpectedConditions.presenceOfElementLocated(this.getBy(identifier)));
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
return message;
} catch (TimeoutException exception) {
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT);
message.setDescription(message.getDescription().replace("%ELEMENT%", identifier.getIdentifier() + "=" + identifier.getLocator()));
LOG.debug(exception.toString());
return message;
}
}
Aggregations