Search in sources :

Example 1 with TestRunException

use of org.asqatasun.sebuilder.interpreter.exception.TestRunException in project Asqatasun by Asqatasun.

the class TgTestRun method next.

/**
     * Executes the next step.
     *
     * @return True on success.
     */
@Override
public boolean next() {
    if (stepIndex == -1) {
        getLog().debug("Starting test run.");
    }
    initRemoteWebDriver();
    isStepOpenNewPage = false;
    getLog().debug("Running step " + (stepIndex + 2) + ":" + getScript().steps.get(stepIndex + 1).type.toString() + " step.");
    boolean result = false;
    String previousUrl = null;
    try {
        previousUrl = getDriver().getCurrentUrl();
        result = getScript().steps.get(++stepIndex).type.run(this);
        // wait a second to make sure the page is fully loaded
        Thread.sleep(500);
        if (!isStepOpenNewPage && !StringUtils.equals(previousUrl, getDriver().getCurrentUrl())) {
            fireNewPage();
        }
    } catch (TimeoutException te) {
        result = true;
        if (!isStepOpenNewPage && !StringUtils.equals(previousUrl, getDriver().getCurrentUrl())) {
            getLog().debug(" The page " + getDriver().getCurrentUrl() + " is fired as new page but" + " is incomplete : " + te.getMessage());
            fireNewPage();
        }
    } catch (UnhandledAlertException uae) {
        getLog().warn(uae.getMessage());
        properlyCloseWebDriver();
        throw new TestRunException(currentStep() + " failed.", uae, currentStep().toString(), stepIndex);
    } catch (Exception e) {
        getLog().warn(e.getCause());
        getLog().warn(e.getMessage());
        properlyCloseWebDriver();
        throw new TestRunException(currentStep() + " failed.", e, currentStep().toString(), stepIndex);
    }
    if (!result) {
        // If a verify failed, we just note this but continue.
        if (currentStep().type instanceof Verify) {
            getLog().error(currentStep() + " failed.");
            return false;
        }
        // In all other cases, we throw an exception to stop the run.
        RuntimeException e = new TestRunException(currentStep() + " failed.", currentStep().toString(), stepIndex);
        e.fillInStackTrace();
        getLog().error(e);
        properlyCloseWebDriver();
        throw e;
    } else {
        return true;
    }
}
Also used : Verify(com.sebuilder.interpreter.Verify) TestRunException(org.asqatasun.sebuilder.interpreter.exception.TestRunException) TestRunException(org.asqatasun.sebuilder.interpreter.exception.TestRunException) IOException(java.io.IOException)

Example 2 with TestRunException

use of org.asqatasun.sebuilder.interpreter.exception.TestRunException in project Asqatasun by Asqatasun.

the class TgTestRun method getSourceCodeAndFireNewPage.

/**
     * 
     * @param url 
     */
private void getSourceCodeAndFireNewPage(String url) {
    try {
        try {
            Thread.sleep(500);
        } catch (InterruptedException ex) {
            throw new TestRunException(currentStep() + " failed.", ex, currentStep().toString(), stepIndex);
        }
        String sourceCode = getDriver().getPageSource();
        /* ##############################################################
             * ACHTUNG !!!!!!!!!!!!!!!!!!!!!!!!!!
             * this sendKeys action is here to grab the focus on the page.
             * It is needed later by the js script to execute the focus()
             * method on each element. Without it, the focus is kept by the adress
             * bar.
             */
        WebElement body = getDriver().findElementByTagName("html");
        Map<String, String> jsScriptResult = Collections.EMPTY_MAP;
        try {
            body.sendKeys(Keys.TAB);
            jsScriptResult = executeJsScripts();
        } catch (WebDriverException wde) {
            getLog().warn(wde.getMessage());
        }
        /* byte[] snapshot = createPageSnapshot();*/
        for (NewPageListener npl : newPageListeners) {
            npl.fireNewPage(url, sourceCode, null, jsScriptResult);
        }
    } catch (UnhandledAlertException uae) {
        getLog().warn(uae.getMessage());
        throw new TestRunException(currentStep() + " failed.", uae, currentStep().toString(), stepIndex);
    }
}
Also used : TestRunException(org.asqatasun.sebuilder.interpreter.exception.TestRunException)

Example 3 with TestRunException

use of org.asqatasun.sebuilder.interpreter.exception.TestRunException in project Asqatasun by Asqatasun.

the class ScenarioLoaderImpl method run.

@Override
public void run() {
    try {
        LOGGER.debug("Launch Scenario " + scenario);
        FirefoxProfile firefoxProfile;
        if (isScenarioOnlyLoadPage(scenario)) {
            LOGGER.debug("Audit page script");
            firefoxProfile = profileFactory.getOnlineProfile();
        } else {
            LOGGER.debug("Scenario script, images are loaded and implicitly " + "wait timeout set");
            implicitelyWaitDriverTimeout = SCENARIO_IMPLICITELY_WAIT_TIMEOUT;
            firefoxProfile = profileFactory.getScenarioProfile();
        }
        Script script = getScriptFromScenario(scenario, firefoxProfile);
        try {
            if (script.run()) {
                LOGGER.debug(webResource.getURL() + " succeeded");
            } else {
                LOGGER.debug(webResource.getURL() + " failed");
            }
        } catch (TestRunException tre) {
            // The TestRunException is caught but not as runtime, to audit
            // at least pages already fetched
            LOGGER.warn(tre.getMessage());
        } catch (RuntimeException re) {
            LOGGER.warn(re.getMessage());
            throw new ScenarioLoaderException(re);
        }
        profileFactory.shutdownFirefoxProfile(firefoxProfile);
    } catch (IOException | JSONException | SuiteException ex) {
        LOGGER.warn(ex.getMessage());
        throw new ScenarioLoaderException(ex);
    }
}
Also used : Script(com.sebuilder.interpreter.Script) ScenarioLoaderException(org.asqatasun.scenarioloader.exception.ScenarioLoaderException) SuiteException(com.sebuilder.interpreter.factory.ScriptFactory.SuiteException) JSONException(org.json.JSONException) IOException(java.io.IOException) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) TestRunException(org.asqatasun.sebuilder.interpreter.exception.TestRunException)

Aggregations

TestRunException (org.asqatasun.sebuilder.interpreter.exception.TestRunException)3 IOException (java.io.IOException)2 Script (com.sebuilder.interpreter.Script)1 Verify (com.sebuilder.interpreter.Verify)1 SuiteException (com.sebuilder.interpreter.factory.ScriptFactory.SuiteException)1 ScenarioLoaderException (org.asqatasun.scenarioloader.exception.ScenarioLoaderException)1 JSONException (org.json.JSONException)1 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)1