Search in sources :

Example 16 with ActionResult

use of com.testsigma.automator.constants.ActionResult in project testsigma by testsigmahq.

the class ActionStepExecutor method execute.

public void execute() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, NoSuchMethodException, AutomatorException, ClassNotFoundException, InstantiationException {
    Class<?> className = Class.forName(testCaseStepEntity.getSnippetClass());
    DriverAction snippet = (DriverAction) className.getDeclaredConstructor().newInstance();
    snippet.setDriver(DriverManager.getRemoteWebDriver());
    snippet.setTimeout(testCaseStepEntity.getWaitTime().longValue());
    snippet.setTestDataPropertiesEntityMap(testCaseStepEntity.getTestDataMap());
    snippet.setElementPropertiesEntityMap(testCaseStepEntity.getElementsMap());
    snippet.setAttributesMap(testCaseStepEntity.getAttributesMap());
    snippet.setGlobalElementTimeOut(testCaseStepResult.getTestPlanRunSettingEntity().getElementTimeOut().longValue());
    snippet.setRuntimeDataProvider(prepareRunTimeDataProvider());
    snippet.setEnvSettings(envSettings);
    snippet.setAdditionalData(testCaseStepEntity.getAdditionalData());
    ActionResult snippetResult = snippet.run();
    // We retry test step execution on failure based on the exception type.
    snippetResult = reTrySnippetIfEligible(snippetResult, snippet, testCaseStepEntity, testCaseStepResult);
    testCaseStepResult.getMetadata().setSnippetResultMetadata(snippet.getResultMetadata());
    testCaseStepResult.getOutputData().putAll(snippet.getTestDataParams());
    if (snippetResult == ActionResult.FAILED) {
        log.error("Test case step FAILED....");
        NaturalActionException naturalActionException = new NaturalActionException(snippet.getErrorMessage(), snippet.getException(), snippet.getErrorCode().getErrorCode().intValue());
        testCaseStepResult.setWebDriverException(naturalActionException.getErrorStackTraceTruncated());
        testCaseStepResult.setErrorCode(snippet.getErrorCode().getErrorCode().intValue());
        testCaseStepResult.setMessage(snippet.getErrorMessage());
        markTestcaseAborted(testCaseResult, testCaseStepResult, snippet);
        testCaseStepResult.getMetadata().setLog(testCaseStepResult.getWebDriverException());
        // We are throwing an InvocationTargetException to handle Auto Healing
        throw naturalActionException;
    } else {
        testCaseStepResult.setMessage(snippet.getSuccessMessage());
    }
}
Also used : ActionResult(com.testsigma.automator.constants.ActionResult) NaturalActionException(com.testsigma.automator.actions.exceptions.NaturalActionException) DriverAction(com.testsigma.automator.actions.DriverAction)

Example 17 with ActionResult

use of com.testsigma.automator.constants.ActionResult in project testsigma by testsigmahq.

the class AddonNaturalTextActionStepExecutor method execute.

public void execute() throws IOException, IllegalAccessException, NoSuchMethodException, ClassNotFoundException, InvocationTargetException, InstantiationException, AutomatorException, NoSuchFieldException, NaturalActionException {
    AddonAction addonAction = new AddonAction(testCaseStepEntity, testCaseStepResult, this.addonElementPropertiesEntity, this.envSettings);
    ActionResult snippetResult = addonAction.run();
    if (snippetResult == ActionResult.FAILED) {
        log.error("Test case step FAILED....");
        NaturalActionException actionException;
        if (addonAction.getException() != null) {
            actionException = new NaturalActionException(addonAction.getErrorMessage(), addonAction.getException(), addonAction.getErrorCode().getErrorCode().intValue());
        } else {
            actionException = new NaturalActionException(addonAction.getErrorMessage());
        }
        testCaseStepResult.setWebDriverException(actionException.getErrorStackTraceTruncated());
        testCaseStepResult.setErrorCode(addonAction.getErrorCode().getErrorCode().intValue());
        testCaseStepResult.setMessage(addonAction.getErrorMessage());
        markTestcaseAborted(testCaseResult, testCaseStepResult, addonAction);
        testCaseStepResult.getMetadata().setLog(testCaseStepResult.getWebDriverException());
        // We are throwing an InvocationTargetException to handle Auto Healing
        throw actionException;
    } else {
        testCaseStepResult.setMessage(addonAction.getSuccessMessage());
    }
}
Also used : ActionResult(com.testsigma.automator.constants.ActionResult) NaturalActionException(com.testsigma.automator.actions.exceptions.NaturalActionException) AddonAction(com.testsigma.automator.actions.AddonAction)

Example 18 with ActionResult

use of com.testsigma.automator.constants.ActionResult in project testsigma by testsigmahq.

the class AddonAction method run.

@SneakyThrows
public ActionResult run() {
    ActionResult snippetResult;
    try {
        beforeExecute();
        snippetResult = execute();
        if (snippetResult == ActionResult.SUCCESS)
            setSuccessMessage();
        else
            setErrorMessage();
        return snippetResult;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        setException(new Exception(ObjectUtils.defaultIfNull(e.getCause(), e)));
        String message = StringUtils.isBlank(e.getMessage()) ? e.getCause().getMessage() : e.getMessage();
        setErrorMessage(message);
        if (e.getCause() == null || !e.getCause().getClass().getName().equals("java.lang.AssertionError"))
            handleException((Exception) getException().getCause());
        log.info(ActionResult.FAILED + " - " + getErrorMessage());
        snippetResult = ActionResult.FAILED;
    } finally {
        afterExecute();
    }
    return snippetResult;
}
Also used : ActionResult(com.testsigma.automator.constants.ActionResult) AutomatorException(com.testsigma.automator.exceptions.AutomatorException) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) UnexpectedTagNameException(org.openqa.selenium.support.ui.UnexpectedTagNameException) MoveTargetOutOfBoundsException(org.openqa.selenium.interactions.MoveTargetOutOfBoundsException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ElementNotDisplayedException(com.testsigma.automator.actions.exceptions.ElementNotDisplayedException) SneakyThrows(lombok.SneakyThrows)

Example 19 with ActionResult

use of com.testsigma.automator.constants.ActionResult in project testsigma by testsigmahq.

the class PageElementsAction method execute.

@Override
public void execute() throws Exception {
    MobileElement mobileElement;
    getDriver().context("NATIVE_APP");
    String pageSource = getDriver().getPageSource();
    log.debug("Page source fetched: " + pageSource);
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(new ByteArrayInputStream(pageSource.getBytes(StandardCharsets.UTF_8)));
    Match match = JOOX.$(document).xpath("//*");
    mobileElement = new MobileElement(match.get(0).cloneNode(true), 1, getPlatform());
    mobileElement.setParent(null);
    Set<String> contextNames = getDriver().getContextHandles();
    mobileElement.setContextNames(contextNames);
    List<MobileWebElement> webViewElements = new ArrayList<>();
    List<MobileElement> webViewElementReferences = new ArrayList<>();
    if (contextNames.size() > 1) {
        this.findWebViewNativeElementReferences(mobileElement, webViewElementReferences);
        log.info("webViewElementReferences size:" + webViewElementReferences.size());
        log.info("No of Contexts:" + contextNames.size());
        log.info("Contexts:" + contextNames);
    }
    if (webViewElementReferences.size() > 0) {
        int webViewIndex = 0;
        for (String name : contextNames) {
            if (name.equals("NATIVE_APP") || name.equals("WEBVIEW_chrome"))
                continue;
            if (webViewIndex >= webViewElementReferences.size()) {
                break;
            }
            MobileWebViewElementsAction webViewSnippet = new MobileWebViewElementsAction();
            webViewSnippet.setDriver(getDriver());
            webViewSnippet.setContext(name);
            webViewSnippet.setPlatform(platform);
            webViewSnippet.setNativeReference(webViewElementReferences.get(webViewIndex));
            ActionResult result = webViewSnippet.run();
            if (result.equals(ActionResult.FAILED)) {
                log.error(webViewSnippet.getErrorMessage());
                continue;
            // throw new Exception("Failed to fetch page elements " + " : " + webViewSnippet.getErrorMessage());
            }
            MobileWebElement webViewParentElement = (MobileWebElement) webViewSnippet.getActualValue();
            MobileElement nativeRef = webViewSnippet.getNativeReference();
            // webViewParentElement.setParent(nativeRef.getParent());
            List<MobileElement> children = nativeRef.getParent().getChildElements();
            if (children == null)
                children = new ArrayList<>();
            children.add(children.size() - 1, webViewParentElement);
            nativeRef.getParent().setChildElements(children);
            webViewElements.add(webViewParentElement);
            webViewIndex++;
        }
    }
    mobileElement.setWebViewElements(webViewElements);
    getDriver().context("NATIVE_APP");
    setActualValue(mobileElement);
    populateXpath(mobileElement);
    setSuccessMessage(SUCCESS_MESSAGE);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Match(org.joox.Match) ActionResult(com.testsigma.automator.constants.ActionResult) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

ActionResult (com.testsigma.automator.constants.ActionResult)19 MobileAutomationServerCommandExecutionException (com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException)13 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)11 AutomatorException (com.testsigma.automator.exceptions.AutomatorException)3 ArrayList (java.util.ArrayList)3 NaturalActionException (com.testsigma.automator.actions.exceptions.NaturalActionException)2 com.testsigma.automator.actions.mobile (com.testsigma.automator.actions.mobile)2 ScreenDimensions (com.testsigma.agent.dto.ScreenDimensions)1 AddonAction (com.testsigma.automator.actions.AddonAction)1 DriverAction (com.testsigma.automator.actions.DriverAction)1 ElementNotDisplayedException (com.testsigma.automator.actions.exceptions.ElementNotDisplayedException)1 SwitchToContextWithNameAction (com.testsigma.automator.actions.mobile.android.switchactions.SwitchToContextWithNameAction)1 SwitchToNativeAppContextAction (com.testsigma.automator.actions.mobile.android.switchactions.SwitchToNativeAppContextAction)1 SuggestionActionResult (com.testsigma.automator.suggestion.actions.SuggestionActionResult)1 AndroidElement (io.appium.java_client.android.AndroidElement)1 IOSElement (io.appium.java_client.ios.IOSElement)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1