use of org.cerberus.engine.entity.Identifier in project cerberus-source by cerberustesting.
the class ControlService method verifyElementPresent.
private MessageEvent verifyElementPresent(TestCaseExecution tCExecution, String elementPath) {
LOG.debug("Control : verifyElementPresent on : " + elementPath);
MessageEvent mes;
if (!StringUtil.isNull(elementPath)) {
Identifier identifier = identifierService.convertStringToIdentifier(elementPath);
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
try {
if (identifier.getIdentifier().equals("picture")) {
return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator());
} else if (this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
}
} catch (WebDriverException exception) {
return parseWebDriverException(exception);
}
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_SRV)) {
if (tCExecution.getLastServiceCalled() != null) {
String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();
switch(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {
case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:
if (xmlUnitService.isElementPresent(responseBody, elementPath)) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
}
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
{
try {
if (jsonService.getFromJson(responseBody, null, elementPath) != null) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_PRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
}
} catch (Exception ex) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);
mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));
return mes;
}
}
default:
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);
mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));
mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementPresent"));
return mes;
}
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);
return mes;
}
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
return sikuliService.doSikuliVerifyElementPresent(tCExecution.getSession(), identifier.getLocator());
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
mes.setDescription(mes.getDescription().replace("%CONTROL%", "VerifyElementPresent"));
mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
return mes;
}
} else {
return new MessageEvent(MessageEventEnum.CONTROL_FAILED_PRESENT_NULL);
}
}
use of org.cerberus.engine.entity.Identifier in project cerberus-source by cerberustesting.
the class ControlService method verifyTextInElement.
private MessageEvent verifyTextInElement(TestCaseExecution tCExecution, String path, String expected) {
if (LOG.isDebugEnabled()) {
LOG.debug("Control: verifyTextInElement on " + path + " element against value: " + expected);
}
// Get value from the path element according to the application type
String actual = null;
try {
Identifier identifier = identifierService.convertStringToIdentifier(path);
String applicationType = tCExecution.getApplicationObj().getType();
if (Application.TYPE_GUI.equalsIgnoreCase(applicationType) || Application.TYPE_APK.equalsIgnoreCase(applicationType) || Application.TYPE_IPA.equalsIgnoreCase(applicationType)) {
actual = webdriverService.getValueFromHTML(tCExecution.getSession(), identifier);
// In case of null actual value then we alert user
if (actual == null) {
MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT_NULL);
mes.setDescription(mes.getDescription().replace("%STRING1%", path));
return mes;
}
// Construct the message from the actual response
MessageEvent mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINELEMENT) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", path));
mes.setDescription(mes.getDescription().replace("%STRING2%", actual));
mes.setDescription(mes.getDescription().replace("%STRING3%", expected));
return mes;
} else if (Application.TYPE_SRV.equalsIgnoreCase(applicationType)) {
if (tCExecution.getLastServiceCalled() != null) {
MessageEvent mes;
String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();
switch(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {
case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:
if (!xmlUnitService.isElementPresent(responseBody, path)) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT_NO_SUCH_ELEMENT);
mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));
return mes;
}
String newPath = StringUtil.addSuffixIfNotAlready(path, "/text()");
actual = xmlUnitService.getFromXml(responseBody, newPath);
// In case of null actual value then we alert user
if (actual == null) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT_NULL);
mes.setDescription(mes.getDescription().replace("%STRING1%", path));
return mes;
}
// Construct the message from the actual response
mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINELEMENT) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", path));
mes.setDescription(mes.getDescription().replace("%STRING2%", actual));
mes.setDescription(mes.getDescription().replace("%STRING3%", expected));
return mes;
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
{
try {
actual = jsonService.getFromJson(responseBody, null, path);
} catch (Exception ex) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);
mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));
return mes;
}
}
// In case of null actual value then we alert user
if (actual == null) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT_NO_SUCH_ELEMENT);
mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));
return mes;
}
// Construct the message from the actual response
mes = actual.equalsIgnoreCase(expected) ? new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TEXTINELEMENT) : new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", path));
mes.setDescription(mes.getDescription().replace("%STRING2%", actual));
mes.setDescription(mes.getDescription().replace("%STRING3%", expected));
return mes;
default:
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);
mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));
mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyTextInElement"));
return mes;
}
// TODO Give the actual element found into the description.
} else {
MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);
return mes;
}
} else {
MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyTextInElement"));
mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
return mes;
}
} catch (NoSuchElementException exception) {
MessageEvent mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_TEXTINELEMENT_NO_SUCH_ELEMENT);
mes.setDescription(mes.getDescription().replace("%ELEMENT%", path));
return mes;
} catch (WebDriverException exception) {
return parseWebDriverException(exception);
}
}
use of org.cerberus.engine.entity.Identifier in project cerberus-source by cerberustesting.
the class ControlService method verifyElementNotPresent.
private MessageEvent verifyElementNotPresent(TestCaseExecution tCExecution, String elementPath) {
LOG.debug("Control : verifyElementNotPresent on : " + elementPath);
MessageEvent mes;
if (!StringUtil.isNull(elementPath)) {
Identifier identifier = identifierService.convertStringToIdentifier(elementPath);
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
try {
if (identifier.getIdentifier().equals("picture")) {
return sikuliService.doSikuliVerifyElementNotPresent(tCExecution.getSession(), identifier.getLocator());
} else if (!this.webdriverService.isElementPresent(tCExecution.getSession(), identifier)) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
}
} catch (WebDriverException exception) {
return parseWebDriverException(exception);
}
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
return sikuliService.doSikuliVerifyElementNotPresent(tCExecution.getSession(), identifier.getLocator());
} else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_SRV)) {
if (tCExecution.getLastServiceCalled() != null) {
String responseBody = tCExecution.getLastServiceCalled().getResponseHTTPBody();
switch(tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()) {
case AppService.RESPONSEHTTPBODYCONTENTTYPE_XML:
if (!(xmlUnitService.isElementPresent(responseBody, elementPath))) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
}
case AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON:
{
try {
if (jsonService.getFromJson(responseBody, null, elementPath) == null) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_NOTPRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT);
mes.setDescription(mes.getDescription().replace("%STRING1%", elementPath));
return mes;
}
} catch (Exception ex) {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC);
mes.setDescription(mes.getDescription().replace("%ERROR%", ex.toString()));
return mes;
}
}
default:
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_MESSAGETYPE);
mes.setDescription(mes.getDescription().replace("%TYPE%", tCExecution.getLastServiceCalled().getResponseHTTPBodyContentType()));
mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementNotPresent"));
return mes;
}
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOOBJECTINMEMORY);
return mes;
}
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementNotPresent"));
mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
return mes;
}
} else {
return new MessageEvent(MessageEventEnum.CONTROL_FAILED_NOTPRESENT_NULL);
}
}
use of org.cerberus.engine.entity.Identifier in project cerberus-source by cerberustesting.
the class ControlService method verifyElementVisible.
private MessageEvent verifyElementVisible(TestCaseExecution tCExecution, String html) {
LOG.debug("Control : verifyElementVisible on : " + html);
MessageEvent mes;
if (!StringUtil.isNull(html)) {
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
try {
Identifier identifier = identifierService.convertStringToIdentifier(html);
if (this.webdriverService.isElementVisible(tCExecution.getSession(), identifier)) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_VISIBLE);
mes.setDescription(mes.getDescription().replace("%STRING1%", html));
return mes;
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_VISIBLE);
mes.setDescription(mes.getDescription().replace("%STRING1%", html));
return mes;
}
} catch (WebDriverException exception) {
return parseWebDriverException(exception);
}
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementVisible"));
mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
return mes;
}
} else {
return new MessageEvent(MessageEventEnum.CONTROL_FAILED_VISIBLE_NULL);
}
}
use of org.cerberus.engine.entity.Identifier in project cerberus-source by cerberustesting.
the class ControlService method verifyElementClickable.
private MessageEvent verifyElementClickable(TestCaseExecution tCExecution, String html) {
LOG.debug("Control : verifyElementClickable : " + html);
MessageEvent mes;
if (!StringUtil.isNull(html)) {
Identifier identifier = identifierService.convertStringToIdentifier(html);
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
try {
if (this.webdriverService.isElementClickable(tCExecution.getSession(), identifier)) {
mes = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_CLICKABLE);
mes.setDescription(mes.getDescription().replace("%ELEMENT%", html));
return mes;
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_FAILED_CLICKABLE);
mes.setDescription(mes.getDescription().replace("%ELEMENT%", html));
return mes;
}
} catch (WebDriverException exception) {
return parseWebDriverException(exception);
}
} else {
mes = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
mes.setDescription(mes.getDescription().replace("%CONTROL%", "verifyElementClickable"));
mes.setDescription(mes.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
return mes;
}
} else {
return new MessageEvent(MessageEventEnum.CONTROL_FAILED_CLICKABLE_NULL);
}
}
Aggregations