Search in sources :

Example 6 with CerberusEventException

use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.

the class ActionService method doActionRightClick.

private MessageEvent doActionRightClick(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, "rightClick", 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.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");
            } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {
                return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());
            } else {
                identifierService.checkWebElementIdentifier(identifier.getIdentifier());
                return webdriverService.doSeleniumActionRightClick(tCExecution.getSession(), identifier);
            }
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
            identifierService.checkSikuliIdentifier(identifier.getIdentifier());
            if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
                return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), identifier.getLocator(), "");
            } else {
                return sikuliService.doSikuliActionRightClick(tCExecution.getSession(), "", identifier.getLocator());
            }
        }
        message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
        message.setDescription(message.getDescription().replace("%ACTION%", "rightClick"));
        message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", tCExecution.getApplicationObj().getType()));
        return message;
    } catch (CerberusEventException ex) {
        LOG.fatal("Error doing Action RightClick :" + ex);
        return ex.getMessageError();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 7 with CerberusEventException

use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.

the class ActionService method getElementToUse.

private String getElementToUse(String value1, String value2, String action, TestCaseExecution tCExecution) throws CerberusEventException {
    if (!StringUtil.isNullOrEmpty(value1)) {
        return value1;
    } else if (!StringUtil.isNullOrEmpty(value2)) {
        logEventService.createForPrivateCalls("ENGINE", action, MESSAGE_DEPRECATED + " Beware, in future release, it won't be allowed to use action without using field value1. Triggered by TestCase : ['" + tCExecution.getTest() + "'|'" + tCExecution.getTestCase() + "'] Property : " + value2);
        LOG.warn(MESSAGE_DEPRECATED + " Action : " + action + ". Beware, in future release, it won't be allowed to use action without using field value1. Triggered by TestCase : ['" + tCExecution.getTest() + "'|'" + tCExecution.getTestCase() + "'] Property : " + value2);
        return value2;
    }
    if (!(action.equals("wait"))) {
        // Wait is the only action can be excuted with no parameters. For all other actions we raize an exception as this should never happen.
        MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_NO_ELEMENT_TO_PERFORM_ACTION);
        message.setDescription(message.getDescription().replace("%ACTION%", action));
        throw new CerberusEventException(message);
    }
    return null;
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 8 with CerberusEventException

use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.

the class ActionService method doActionSwitchToWindow.

private MessageEvent doActionSwitchToWindow(TestCaseExecution tCExecution, String object, String property) {
    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, "switchToWindow", tCExecution);
        /**
         * Get Identifier (identifier, locator)
         */
        Identifier identifier = identifierService.convertStringToIdentifier(element);
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
            return webdriverService.doSeleniumActionSwitchToWindow(tCExecution.getSession(), identifier);
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
            return androidAppiumService.switchToContext(tCExecution.getSession(), identifier);
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
            return iosAppiumService.switchToContext(tCExecution.getSession(), identifier);
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
            return sikuliService.doSikuliActionSwitchApp(tCExecution.getSession(), identifier.getLocator());
        } else {
            return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION).resolveDescription("ACTION", "SwitchToWindow").resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());
        }
    } catch (CerberusEventException ex) {
        LOG.fatal("Error doing Action SwitchToWindow :" + ex);
        return ex.getMessageError();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 9 with CerberusEventException

use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.

the class ActionService method doActionClick.

private MessageEvent doActionClick(TestCaseExecution tCExecution, String value1, String value2) {
    String element;
    try {
        /**
         * Get element to use String object if not empty, String property if
         * object empty, throws Exception if both empty)
         */
        element = getElementToUse(value1, value2, TestCaseStepAction.ACTION_CLICK, tCExecution);
        /**
         * Get Identifier (identifier, locator) and check it's valid
         */
        Identifier identifier = identifierService.convertStringToIdentifier(element);
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
            if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
                return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");
            } else if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_TEXT)) {
                return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());
            } else {
                identifierService.checkWebElementIdentifier(identifier.getIdentifier());
                return webdriverService.doSeleniumActionClick(tCExecution.getSession(), identifier, true, true);
            }
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK)) {
            identifierService.checkWebElementIdentifier(identifier.getIdentifier());
            return androidAppiumService.click(tCExecution.getSession(), identifier);
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA)) {
            identifierService.checkWebElementIdentifier(identifier.getIdentifier());
            return iosAppiumService.click(tCExecution.getSession(), identifier);
        } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
            identifierService.checkSikuliIdentifier(identifier.getIdentifier());
            if (identifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
                return sikuliService.doSikuliActionClick(tCExecution.getSession(), identifier.getLocator(), "");
            } else {
                return sikuliService.doSikuliActionClick(tCExecution.getSession(), "", identifier.getLocator());
            }
        } else {
            return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION).resolveDescription("ACTION", "Click").resolveDescription("APPLICATIONTYPE", tCExecution.getApplicationObj().getType());
        }
    } catch (CerberusEventException ex) {
        LOG.fatal("Error doing Action Click :" + ex);
        return ex.getMessageError();
    }
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) Identifier(org.cerberus.engine.entity.Identifier) MessageEvent(org.cerberus.engine.entity.MessageEvent)

Example 10 with CerberusEventException

use of org.cerberus.exception.CerberusEventException in project cerberus-source by cerberustesting.

the class ActionService method doActionKeyPress.

private MessageEvent doActionKeyPress(TestCaseExecution tCExecution, String value1, String value2) {
    try {
        String appType = tCExecution.getApplicationObj().getType();
        // if (appType.equalsIgnoreCase(Application.TYPE_APK) || appType.equalsIgnoreCase(Application.TYPE_IPA)) {
        if (StringUtil.isNullOrEmpty(value2)) {
            return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS_MISSINGKEY).resolveDescription("APPLICATIONTYPE", appType);
        }
        // } else if (appType.equalsIgnoreCase(Application.TYPE_GUI) || appType.equalsIgnoreCase(Application.TYPE_FAT)) {
        // if (StringUtil.isNullOrEmpty(value1) || StringUtil.isNullOrEmpty(value2)) {
        // return new MessageEvent(MessageEventEnum.ACTION_FAILED_KEYPRESS);
        // }
        // }
        /**
         * Get Identifier (identifier, locator)
         */
        Identifier objectIdentifier = identifierService.convertStringToIdentifier(value1);
        if (appType.equalsIgnoreCase(Application.TYPE_GUI)) {
            if (objectIdentifier.getIdentifier().equals(SikuliService.SIKULI_IDENTIFIER_PICTURE)) {
                return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), value2);
            } else {
                identifierService.checkWebElementIdentifier(objectIdentifier.getIdentifier());
                return webdriverService.doSeleniumActionKeyPress(tCExecution.getSession(), objectIdentifier, value2);
            }
        } else if (appType.equalsIgnoreCase(Application.TYPE_APK)) {
            return androidAppiumService.keyPress(tCExecution.getSession(), value2);
        } else if (appType.equalsIgnoreCase(Application.TYPE_IPA)) {
            return iosAppiumService.keyPress(tCExecution.getSession(), value2);
        } else if (appType.equalsIgnoreCase(Application.TYPE_FAT)) {
            return sikuliService.doSikuliActionKeyPress(tCExecution.getSession(), objectIdentifier.getLocator(), value2);
        } else {
            return new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION).resolveDescription("ACTION", "KeyPress").resolveDescription("APPLICATIONTYPE", appType);
        }
    } catch (CerberusEventException ex) {
        LOG.fatal("Error doing Action KeyPress :" + 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