use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.
the class WebDriverService method getCurrentUrl.
/**
* Return the current URL from Selenium.
*
* @param session
* @param applicationUrl
* @return current URL without HTTP://IP:PORT/CONTEXTROOT/
* @throws CerberusEventException Cannot find application host (from
* Database) inside current URL (from Selenium)
*/
@Override
public String getCurrentUrl(Session session, String applicationUrl) throws CerberusEventException {
/*
* Example: URL (http://cerberus.domain.fr/Cerberus/mypage/page/index.jsp)<br>
* will return /mypage/page/index.jsp
* No matter what, the output current relative URl will start by /
*/
// We start to remove the protocol part of the urls.
String cleanedCurrentURL = StringUtil.removeProtocolFromHostURL(session.getDriver().getCurrentUrl());
String cleanedURL = StringUtil.removeProtocolFromHostURL(applicationUrl);
// We remove from current url the host part of the application.
String[] strings = cleanedCurrentURL.split(cleanedURL, 2);
if (strings.length < 2) {
MessageEvent msg = new MessageEvent(MessageEventEnum.CONTROL_FAILED_URL_NOT_MATCH_APPLICATION);
msg.setDescription(msg.getDescription().replace("%HOST%", applicationUrl));
msg.setDescription(msg.getDescription().replace("%CURRENTURL%", session.getDriver().getCurrentUrl()));
LOG.warn(msg.toString());
throw new CerberusEventException(msg);
}
String result = StringUtil.addPrefixIfNotAlready(strings[1], "/");
return result;
}
use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.
the class ActionService method doActionDoubleClick.
private MessageEvent doActionDoubleClick(TestCaseExecution tCExecution, String object, String property) {
MessageEvent message;
String element;
try {
/**
* Get element to use String object if not empty, String property if
* object empty, throws Exception if both empty)
*/
element = getElementToUse(object, property, "doubleClick", tCExecution);
/**
* Get Identifier (identifier, locator)
*/
Identifier identifier = identifierService.convertStringToIdentifier(element);
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");
} else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {
return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());
} else {
identifierService.checkWebElementIdentifier(identifier.getIdentifier());
return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, true);
}
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
identifierService.checkWebElementIdentifier(identifier.getIdentifier());
return webdriverService.doSeleniumActionDoubleClick(tCExecution.getSession(), identifier, true, false);
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
identifierService.checkSikuliIdentifier(identifier.getIdentifier());
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), identifier.getLocator(), "");
} else {
return sikuliService.doSikuliActionDoubleClick(tCExecution.getSession(), "", identifier.getLocator());
}
}
message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
message.setDescription(message.getDescription().replace("%ACTION%", "doubleClick"));
message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
return message;
} catch (CerberusEventException ex) {
LOG.fatal("Error doing Action DoubleClick :" + ex);
return ex.getMessageError();
}
}
use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.
the class ActionService method doActionMouseOverAndWait.
private MessageEvent doActionMouseOverAndWait(TestCaseExecution tCExecution, String object, String property) {
MessageEvent message;
try {
/**
* Check object is not null
*/
if (object == null) {
return new MessageEvent(MessageEventEnum.ACTION_FAILED_MOUSEOVERANDWAIT_GENERIC);
}
/**
* Get Identifier (identifier, locator)
*/
Identifier identifier = identifierService.convertStringToIdentifier(object);
identifierService.checkWebElementIdentifier(identifier.getIdentifier());
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), identifier.getLocator(), "");
} else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {
message = sikuliService.doSikuliActionMouseOver(tCExecution.getSession(), "", identifier.getLocator());
} else {
message = webdriverService.doSeleniumActionMouseOver(tCExecution.getSession(), identifier);
}
if (message.getCodeString().equals("OK")) {
message = this.doActionWait(tCExecution, property, null);
}
return message;
}
message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
message.setDescription(message.getDescription().replace("%ACTION%", "mouseOverAndWait"));
message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
return message;
} catch (CerberusEventException ex) {
LOG.fatal("Error doing Action MouseOverAndWait :" + ex);
return ex.getMessageError();
}
}
use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.
the class ActionService method doActionClickWait.
private MessageEvent doActionClickWait(TestCaseExecution tCExecution, String string1, String string2) {
MessageEvent message;
try {
Identifier identifier = identifierService.convertStringToIdentifier(string1);
identifierService.checkWebElementIdentifier(identifier.getIdentifier());
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
message = webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, true, true);
if (message.getCodeString().equals("OK")) {
message = this.doActionWait(tCExecution, string2, null);
}
return message;
}
message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
message.setDescription(message.getDescription().replace("%ACTION%", "ClickAndWait"));
message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", string1));
return message;
} catch (CerberusEventException ex) {
LOG.fatal("Error doing Action ClickAndWait :" + ex);
return ex.getMessageError();
}
}
use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.
the class ActionService method doActionSelect.
private MessageEvent doActionSelect(TestCaseExecution tCExecution, String value1, String value2) {
MessageEvent message;
try {
/**
* Check object and property are not null
*/
if (StringUtil.isNullOrEmpty(value1) || StringUtil.isNullOrEmpty(value2)) {
return new MessageEvent(MessageEventEnum.ACTION_FAILED_SELECT);
}
/**
* Get Identifier (identifier, locator)
*/
Identifier identifierObject = identifierService.convertStringToIdentifier(value1);
Identifier identifierValue = identifierService.convertStringToSelectIdentifier(value2);
identifierService.checkWebElementIdentifier(identifierObject.getIdentifier());
identifierService.checkSelectOptionsIdentifier(identifierValue.getIdentifier());
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
return webdriverService.doSeleniumActionSelect(tCExecution.getSession(), identifierObject, identifierValue);
}
message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
message.setDescription(message.getDescription().replace("%ACTION%", "Select"));
message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
return message;
} catch (CerberusEventException ex) {
LOG.fatal("Error doing Action Select :" + ex);
return ex.getMessageError();
}
}
Aggregations