Search in sources :

Example 1 with ActionResult

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

the class DriverSessionCommand method swipe.

public void swipe(String sessionId, List<com.testsigma.agent.request.TapPoint> tapPoints) throws MobileAutomationServerCommandExecutionException {
    try {
        RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);
        SwipeAction swipeAction = new SwipeAction();
        List<com.testsigma.automator.actions.mobile.TapPoint> targetTapPoints = new ArrayList<>();
        for (com.testsigma.agent.request.TapPoint tapPoint : tapPoints) {
            targetTapPoints.add(new com.testsigma.automator.actions.mobile.TapPoint(tapPoint.getX(), tapPoint.getY()));
        }
        swipeAction.setTapPoints(targetTapPoints.toArray(new com.testsigma.automator.actions.mobile.TapPoint[2]));
        swipeAction.setDriver(remoteWebDriver);
        ActionResult result = swipeAction.run();
        if (ActionResult.FAILED.equals(result)) {
            log.error(swipeAction.getErrorMessage());
            throw new Exception("Failed to swipe from " + tapPoints.get(0) + " to " + tapPoints.get(1) + " : " + swipeAction.getErrorMessage());
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);
    }
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) ArrayList(java.util.ArrayList) com.testsigma.automator.actions.mobile(com.testsigma.automator.actions.mobile) MobileAutomationServerCommandExecutionException(com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException) MobileAutomationServerCommandExecutionException(com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException) ActionResult(com.testsigma.automator.constants.ActionResult)

Example 2 with ActionResult

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

the class DriverSessionCommand method pageSourceElements.

public MobileElement pageSourceElements(String sessionId, Platform platform) throws MobileAutomationServerCommandExecutionException {
    try {
        RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);
        PageElementsAction pageElementsAction = new PageElementsAction();
        pageElementsAction.setDriver(remoteWebDriver);
        pageElementsAction.setPlatform(platform);
        ActionResult result = pageElementsAction.run();
        if (result.equals(ActionResult.FAILED)) {
            log.error(pageElementsAction.getErrorMessage());
            throw new Exception("Failed to fetch page elements " + " : " + pageElementsAction.getErrorMessage());
        }
        return (MobileElement) pageElementsAction.getActualValue();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);
    }
}
Also used : ActionResult(com.testsigma.automator.constants.ActionResult) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) MobileAutomationServerCommandExecutionException(com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException) MobileAutomationServerCommandExecutionException(com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException)

Example 3 with ActionResult

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

the class DriverSessionCommand method tapOnElement.

public void tapOnElement(String sessionId, MobileElement mobileElement) throws MobileAutomationServerCommandExecutionException {
    try {
        RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);
        if (mobileElement.getWebViewName() != null)
            this.switchToContextByName(remoteWebDriver, mobileElement);
        MobileInspectorTapOnElement mobileInspectorTapOnElement = new MobileInspectorTapOnElement();
        mobileInspectorTapOnElement.setElementPropertiesEntityMap(createElementPropertiesMap(FindByType.XPATH, mobileElement.getXpath()));
        mobileInspectorTapOnElement.setDriver(remoteWebDriver);
        ActionResult result = mobileInspectorTapOnElement.run();
        if (ActionResult.FAILED.equals(result)) {
            log.error(mobileInspectorTapOnElement.getErrorMessage());
            throw new Exception("Failed to tap on element " + " : " + mobileInspectorTapOnElement.getErrorMessage());
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);
    } finally {
        if (mobileElement.getWebViewName() != null) {
            try {
                switchToNativeContext(sessionContainer.getSessionMap().get(sessionId), mobileElement);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);
            }
        }
    }
}
Also used : ActionResult(com.testsigma.automator.constants.ActionResult) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) MobileAutomationServerCommandExecutionException(com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException) MobileAutomationServerCommandExecutionException(com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException)

Example 4 with ActionResult

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

the class DriverSessionCommand method clearElement.

public void clearElement(String sessionId, MobileElement mobileElement) throws MobileAutomationServerCommandExecutionException {
    try {
        RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);
        if (mobileElement.getWebViewName() != null)
            this.switchToContextByName(remoteWebDriver, mobileElement);
        ClearElementAction clearElementAction = new ClearElementAction();
        clearElementAction.setElementPropertiesEntityMap(createElementPropertiesMap(FindByType.XPATH, mobileElement.getXpath()));
        clearElementAction.setDriver(remoteWebDriver);
        ActionResult result = clearElementAction.run();
        if (ActionResult.FAILED.equals(result)) {
            log.error(clearElementAction.getErrorMessage());
            throw new Exception("Failed to clear element " + " : " + clearElementAction.getErrorMessage());
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);
    } finally {
        if (mobileElement.getWebViewName() != null) {
            try {
                switchToNativeContext(sessionContainer.getSessionMap().get(sessionId), mobileElement);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);
            }
        }
    }
}
Also used : ActionResult(com.testsigma.automator.constants.ActionResult) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) MobileAutomationServerCommandExecutionException(com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException) MobileAutomationServerCommandExecutionException(com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException)

Example 5 with ActionResult

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

the class DriverSessionCommand method getScreenDimensions.

public ScreenDimensions getScreenDimensions(String sessionId) throws MobileAutomationServerCommandExecutionException {
    try {
        RemoteWebDriver remoteWebDriver = sessionContainer.getSessionMap().get(sessionId);
        ScreenDimensionsAction screenDimensionsAction = new ScreenDimensionsAction();
        screenDimensionsAction.setDriver(remoteWebDriver);
        ActionResult result = screenDimensionsAction.run();
        if (result.equals(ActionResult.FAILED)) {
            log.error(screenDimensionsAction.getErrorMessage());
            throw new Exception("Failed to get device screen dimensions " + " : " + screenDimensionsAction.getErrorMessage());
        }
        ScreenDimensions screenDimensions = new ScreenDimensions();
        Dimension dimension = (Dimension) screenDimensionsAction.getActualValue();
        screenDimensions.setScreenHeight(dimension.getHeight());
        screenDimensions.setScreenWidth(dimension.getWidth());
        return screenDimensions;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new MobileAutomationServerCommandExecutionException(e.getMessage(), e);
    }
}
Also used : ScreenDimensions(com.testsigma.agent.dto.ScreenDimensions) ActionResult(com.testsigma.automator.constants.ActionResult) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Dimension(org.openqa.selenium.Dimension) MobileAutomationServerCommandExecutionException(com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException) MobileAutomationServerCommandExecutionException(com.testsigma.agent.exception.MobileAutomationServerCommandExecutionException)

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