Skip to content

Commit

Permalink
Better handling of exceptions in the new HTMLRunner
Browse files Browse the repository at this point in the history
Tests should fail if the underlying driver throws an exception.
  • Loading branch information
shs96c committed Jun 18, 2016
1 parent 3f41a29 commit bad871b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.collect.ImmutableList;

import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.SeleniumException;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
Expand All @@ -44,7 +45,12 @@ public void run(Results results, WebDriver driver, Selenium selenium) {

List<CoreTestStep> steps = findCommands(driver);
for (CoreTestStep step : steps) {
step.run(results, driver, selenium);
try {
step.run(results, driver, selenium);
} catch (SeleniumException e) {
results.addTestFailure();
return;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ private static ImmutableMap<String, SeleneseCommand> buildCommands() {
throw new RuntimeException("Exceptionally unlikely to get here");
}
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
for (Throwable cause = e; cause != null; cause = cause.getCause()) {
if (cause instanceof SeleniumException) {
throw (SeleniumException) cause;
}
}
throw new SeleniumException(
String.format("Unable to emulate %s ('%s', '%s')", method.getName(), locator, value),
e);
}
};
commands.put(method.getName(), underlyingCommand);
Expand Down Expand Up @@ -180,6 +187,7 @@ private static ImmutableMap<String, SeleneseCommand> buildCommands() {
}

private interface SeleneseCommand {
Object execute(WebDriver driver, Selenium selenium, String locator, String value);
Object execute(WebDriver driver, Selenium selenium, String locator, String value)
throws SeleniumException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public static void main(String[] args) {
Results results = new Results();
CoreTest test = new CoreTest(args[3]);
test.run(results, driver, new WebDriverBackedSelenium(driver, args[2]));
if (results.isSuccessful()) {
System.out.println("SUCCESS");
} else {
System.out.println("FAILED");
}
} finally {
driver.quit();
}
Expand Down
11 changes: 11 additions & 0 deletions java/server/src/org/openqa/selenium/server/htmlrunner/Results.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@

package org.openqa.selenium.server.htmlrunner;

import com.thoughtworks.selenium.SeleniumException;

public class Results {

private boolean succeeded = true;

public boolean isSuccessful() {
return succeeded;
}

public void addTestFailure() {
succeeded = false;
}
}

0 comments on commit bad871b

Please sign in to comment.