Search in sources :

Example 6 with AutomatorException

use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.

the class CloseCurrentWindowAction method execute.

@Override
public void execute() throws Exception {
    try {
        String currWindowHandle = getDriver().getWindowHandle();
        getDriver().switchTo().window(currWindowHandle).close();
        setSuccessMessage(SUCCESS_MESSAGE);
        // Once current window is closed, We cannot perform element/browser actions using driver. So we switch to a window if available.
        try {
            Set<String> windowHandles = getDriver().getWindowHandles();
            if (windowHandles != null) {
                for (String window : windowHandles) {
                    getDriver().switchTo().window(window);
                    break;
                }
            }
        } catch (Exception e) {
            log.error("Current window is closed and no other window/tab is present to switch to. " + "Ignore this exception as natural text action is already done", e);
            setSuccessMessage("Current window is closed and no other window/tab is present to switch to.");
            return;
        }
    } catch (NoSuchSessionException e) {
        throw new AutomatorException(String.format(FAILURE_MESSAGE));
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException) AutomatorException(com.testsigma.automator.exceptions.AutomatorException) NoSuchSessionException(org.openqa.selenium.NoSuchSessionException)

Example 7 with AutomatorException

use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.

the class PressKeyAction method execute.

@Override
protected void execute() throws Exception {
    try {
        Actions actions = new Actions(getDriver());
        actions.sendKeys(Keys.valueOf(getTestData().toUpperCase().trim())).build().perform();
        setSuccessMessage("Successfully typed given test data.");
    } catch (Exception e) {
        throw new AutomatorException(String.format(FAILURE_MESSAGE, getTestData()));
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) Actions(org.openqa.selenium.interactions.Actions) AutomatorException(com.testsigma.automator.exceptions.AutomatorException)

Example 8 with AutomatorException

use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.

the class CurrentWebPageLoadingStatusAction method execute.

@Override
public void execute() throws Exception {
    String status = getTestData();
    switch(status) {
        case ActionConstants.LOADED:
            try {
                boolean pageLoaded = getWebDriverWait().until(CustomExpectedConditions.waitForPageLoadUsingJS());
                Assert.isTrue(pageLoaded, LOADED_FAILURE_MESSAGE);
                setSuccessMessage(LOADED_SUCCESS_MESSAGE);
                break;
            } catch (TimeoutException e) {
                throw new AutomatorException(LOADED_FAILURE_MESSAGE, (Exception) e.getCause());
            }
        case ActionConstants.NOT_LOADED:
            try {
                boolean pageLoaded = getWebDriverWait().until(CustomExpectedConditions.waitForPageLoadUsingJS());
                Assert.isTrue(!pageLoaded, NOT_LOADED_ERROR_MESSAGE);
                setSuccessMessage(NOT_LOADED_SUCCESS_MESSAGE);
                break;
            } catch (TimeoutException e) {
                throw new AutomatorException(NOT_LOADED_ERROR_MESSAGE, (Exception) e.getCause());
            }
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) AutomatorException(com.testsigma.automator.exceptions.AutomatorException) TimeoutException(org.openqa.selenium.TimeoutException) TimeoutException(org.openqa.selenium.TimeoutException)

Example 9 with AutomatorException

use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.

the class DriverSessionsService method driverExecutableExists.

public File driverExecutableExists(String browserNameKey, String browserMajorVersion) throws TestsigmaException {
    try {
        String driversFolderPath = PathUtil.getInstance().getDriversPath();
        String driverPath = AutomatorConfig.getInstance().getAppBridge().getDriverExecutablePath(browserNameKey, browserMajorVersion);
        File driverFile = Paths.get(driversFolderPath, driverPath).toFile();
        log.info("Checking if driver executable exists at : " + driverFile.getAbsolutePath());
        return driverFile.exists() ? driverFile : null;
    } catch (AutomatorException e) {
        log.error(e.getMessage(), e);
        throw new TestsigmaException(e.getMessage(), e);
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) TestsigmaException(com.testsigma.agent.exception.TestsigmaException) File(java.io.File)

Example 10 with AutomatorException

use of com.testsigma.automator.exceptions.AutomatorException in project testsigma by testsigmahq.

the class CloudAppBridge method getRunTimeData.

@Override
public String getRunTimeData(String variableName, Long environmentResultId, String sessionId) throws AutomatorException {
    try {
        MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
        queryParams.add("environmentResultId", environmentResultId.toString());
        queryParams.add("sessionId", sessionId);
        String url = ServerURLBuilder.runTimeDataURL(variableName, queryParams);
        String authHeader = HttpClient.BEARER + " " + agentConfig.getJwtApiKey();
        HttpResponse<String> response = webAppHttpClient.get(url, new TypeReference<>() {
        }, authHeader);
        if (response.getStatusCode() == HttpStatus.NOT_FOUND.value()) {
            throw new AutomatorException(AutomatorMessages.getMessage(AutomatorMessages.EXCEPTION_INVALID_TESTDATA, variableName));
        }
        return response.getResponseEntity();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new AutomatorException(e.getMessage(), e);
    }
}
Also used : AutomatorException(com.testsigma.automator.exceptions.AutomatorException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) AutomatorException(com.testsigma.automator.exceptions.AutomatorException)

Aggregations

AutomatorException (com.testsigma.automator.exceptions.AutomatorException)119 TimeoutException (org.openqa.selenium.TimeoutException)31 WebElement (org.openqa.selenium.WebElement)19 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)9 Select (org.openqa.selenium.support.ui.Select)6 TestsigmaException (com.testsigma.agent.exception.TestsigmaException)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 RuntimeDataProvider (com.testsigma.automator.utilities.RuntimeDataProvider)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Map (java.util.Map)3 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)3 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)3 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)2 ElementNotDisplayedException (com.testsigma.automator.actions.exceptions.ElementNotDisplayedException)2 MobileApp (com.testsigma.automator.mobile.MobileApp)2 ObjectMapperService (com.testsigma.automator.service.ObjectMapperService)2 ErrorUtil (com.testsigma.automator.utilities.ErrorUtil)2 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2