Search in sources :

Example 21 with CerberusEventException

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;
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 22 with CerberusEventException

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();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 23 with CerberusEventException

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();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 24 with CerberusEventException

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();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 25 with CerberusEventException

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();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Aggregations

CerberusEventException (org.cerberus.exception.CerberusEventException)36 MessageEvent (org.cerberus.engine.entity.MessageEvent)35 Identifier (org.cerberus.engine.entity.Identifier)15 AnswerItem (org.cerberus.util.answer.AnswerItem)11 ArrayList (java.util.ArrayList)7 CerberusException (org.cerberus.exception.CerberusException)7 Date (java.util.Date)6 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)6 HashMap (java.util.HashMap)3 AppService (org.cerberus.crud.entity.AppService)3 CountryEnvironmentDatabase (org.cerberus.crud.entity.CountryEnvironmentDatabase)3 JSONException (org.json.JSONException)3 NoSuchElementException (org.openqa.selenium.NoSuchElementException)3 WebDriverException (org.openqa.selenium.WebDriverException)3 List (java.util.List)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 TestCase (org.cerberus.crud.entity.TestCase)2 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)2 TestCaseExecutionData (org.cerberus.crud.entity.TestCaseExecutionData)2 AnswerList (org.cerberus.util.answer.AnswerList)2