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;
}
}
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);
}
}
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);
}
}
Aggregations