Skip to content

Commit bad871b

Browse files
committed
Better handling of exceptions in the new HTMLRunner
Tests should fail if the underlying driver throws an exception.
1 parent 3f41a29 commit bad871b

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

java/server/src/org/openqa/selenium/server/htmlrunner/CoreTestCase.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.collect.ImmutableList;
2323

2424
import com.thoughtworks.selenium.Selenium;
25+
import com.thoughtworks.selenium.SeleniumException;
2526

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

4546
List<CoreTestStep> steps = findCommands(driver);
4647
for (CoreTestStep step : steps) {
47-
step.run(results, driver, selenium);
48+
try {
49+
step.run(results, driver, selenium);
50+
} catch (SeleniumException e) {
51+
results.addTestFailure();
52+
return;
53+
}
4854
}
4955
}
5056

java/server/src/org/openqa/selenium/server/htmlrunner/CoreTestStep.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ private static ImmutableMap<String, SeleneseCommand> buildCommands() {
8989
throw new RuntimeException("Exceptionally unlikely to get here");
9090
}
9191
} catch (ReflectiveOperationException e) {
92-
throw new RuntimeException(e);
92+
for (Throwable cause = e; cause != null; cause = cause.getCause()) {
93+
if (cause instanceof SeleniumException) {
94+
throw (SeleniumException) cause;
95+
}
96+
}
97+
throw new SeleniumException(
98+
String.format("Unable to emulate %s ('%s', '%s')", method.getName(), locator, value),
99+
e);
93100
}
94101
};
95102
commands.put(method.getName(), underlyingCommand);
@@ -180,6 +187,7 @@ private static ImmutableMap<String, SeleneseCommand> buildCommands() {
180187
}
181188

182189
private interface SeleneseCommand {
183-
Object execute(WebDriver driver, Selenium selenium, String locator, String value);
190+
Object execute(WebDriver driver, Selenium selenium, String locator, String value)
191+
throws SeleniumException;
184192
}
185193
}

java/server/src/org/openqa/selenium/server/htmlrunner/Main.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public static void main(String[] args) {
8888
Results results = new Results();
8989
CoreTest test = new CoreTest(args[3]);
9090
test.run(results, driver, new WebDriverBackedSelenium(driver, args[2]));
91+
if (results.isSuccessful()) {
92+
System.out.println("SUCCESS");
93+
} else {
94+
System.out.println("FAILED");
95+
}
9196
} finally {
9297
driver.quit();
9398
}

java/server/src/org/openqa/selenium/server/htmlrunner/Results.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717

1818
package org.openqa.selenium.server.htmlrunner;
1919

20+
import com.thoughtworks.selenium.SeleniumException;
21+
2022
public class Results {
2123

24+
private boolean succeeded = true;
25+
26+
public boolean isSuccessful() {
27+
return succeeded;
28+
}
29+
30+
public void addTestFailure() {
31+
succeeded = false;
32+
}
2233
}

0 commit comments

Comments
 (0)