Search in sources :

Example 1 with Verify

use of com.sebuilder.interpreter.Verify 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)

Aggregations

Verify (com.sebuilder.interpreter.Verify)1 IOException (java.io.IOException)1 TestRunException (org.asqatasun.sebuilder.interpreter.exception.TestRunException)1