This repository has been archived by the owner on May 22, 2018. It is now read-only.
forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JasonLeyba: Migrate the js test infrastructure to junit4. Delete the …
…e2e infrastructure for webdriverjs, which has long since rotted. I'll have to bring it back in a future change. r17602
- Loading branch information
Showing
23 changed files
with
394 additions
and
931 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 0 additions & 97 deletions
97
java/client/test/org/openqa/selenium/javascript/ClosureTestCase.java
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
java/client/test/org/openqa/selenium/javascript/ClosureTestStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.openqa.selenium.javascript; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import org.openqa.selenium.JavascriptExecutor; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebDriverException; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.base.Stopwatch; | ||
import com.google.common.base.Supplier; | ||
import org.junit.runners.model.Statement; | ||
|
||
import java.net.URL; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.logging.Logger; | ||
|
||
public class ClosureTestStatement extends Statement { | ||
|
||
private static final Logger LOG = Logger.getLogger(ClosureTestStatement.class.getName()); | ||
|
||
private final Supplier<WebDriver> driverSupplier; | ||
private final String testPath; | ||
private final Function<String, URL> filePathToUrlFn; | ||
private final long timeoutSeconds; | ||
|
||
public ClosureTestStatement(Supplier<WebDriver> driverSupplier, | ||
String testPath, Function<String, URL> filePathToUrlFn, long timeoutSeconds) { | ||
this.driverSupplier = driverSupplier; | ||
this.testPath = testPath; | ||
this.filePathToUrlFn = filePathToUrlFn; | ||
this.timeoutSeconds = Math.max(0, timeoutSeconds); | ||
} | ||
|
||
@Override | ||
public void evaluate() throws Throwable { | ||
URL testUrl = filePathToUrlFn.apply(testPath); | ||
LOG.info("Running: " + testUrl); | ||
|
||
Stopwatch stopwatch = new Stopwatch(); | ||
stopwatch.start(); | ||
|
||
WebDriver driver = driverSupplier.get(); | ||
JavascriptExecutor executor = (JavascriptExecutor) driver; | ||
// Avoid Safari JS leak between tests. | ||
executor.executeScript("if (window && window.top) window.top.G_testRunner = null"); | ||
|
||
try { | ||
driver.get(testUrl.toString()); | ||
} catch (WebDriverException e) { | ||
fail("Test failed to load: " + e.getMessage()); | ||
} | ||
|
||
while (!getBoolean(executor, Query.IS_FINISHED)) { | ||
long elapsedTime = stopwatch.elapsedTime(TimeUnit.SECONDS); | ||
if (timeoutSeconds > 0 && elapsedTime > timeoutSeconds) { | ||
throw new JavaScriptAssertionError("Tests timed out after " + elapsedTime + " s"); | ||
} | ||
TimeUnit.MILLISECONDS.sleep(100); | ||
} | ||
|
||
if (!getBoolean(executor, Query.IS_SUCCESS)) { | ||
String report = getString(executor, Query.GET_REPORT); | ||
throw new JavaScriptAssertionError(report); | ||
} | ||
} | ||
|
||
private boolean getBoolean(JavascriptExecutor executor, Query query) { | ||
return (Boolean) executor.executeScript(query.script); | ||
} | ||
|
||
private String getString(JavascriptExecutor executor, Query query) { | ||
return (String) executor.executeScript(query.script); | ||
} | ||
|
||
private static enum Query { | ||
IS_FINISHED("return !!tr && tr.isFinished();"), | ||
IS_SUCCESS("return !!tr && tr.isSuccess();"), | ||
GET_REPORT("return tr.getReport(true);"); | ||
|
||
private final String script; | ||
|
||
private Query(String script) { | ||
this.script = "var tr = window.top.G_testRunner;" + script; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
java/client/test/org/openqa/selenium/javascript/JavaScriptAssertionError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.openqa.selenium.javascript; | ||
|
||
class JavaScriptAssertionError extends AssertionError { | ||
|
||
public JavaScriptAssertionError(String message) { | ||
super(message); | ||
} | ||
|
||
@Override | ||
public Throwable fillInStackTrace() { | ||
return this; // No java stack traces. | ||
} | ||
|
||
@Override | ||
public void setStackTrace(StackTraceElement[] stackTraceElements) { | ||
// No java stack traces. | ||
} | ||
} |
Oops, something went wrong.