Skip to content

Commit 2732605

Browse files
committed
Run Core tests directly from JUnit
Removing the Selenium indirection allows more granular test feedback
1 parent bef17b0 commit 2732605

File tree

7 files changed

+124
-222
lines changed

7 files changed

+124
-222
lines changed

common/src/js/core/lib/scriptaculous/unittest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Test.Unit.Runner.prototype = {
165165
}
166166
this.currentTest = 0;
167167
this.logger = new Test.Unit.Logger(this.options.testLog);
168-
setTimeout(this.runTests.bind(this), 100);
168+
setTimeout(this.runTests.bind(this), 1000);
169169
},
170170
parseResultsURLQueryParameter: function() {
171171
return window.location.search.parseQuery()["resultsURL"];

ide/src/extension/content/tests/functional/CoreSuite.html

-100
This file was deleted.

ide/src/extension/content/tests/functional/TestCore-test.html

-71
This file was deleted.

ide/src/extension/content/tests/functional/TestCore.html

-48
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+
<title>Selenium IDE Test</title>
6+
<script type="application/javascript;version=1.7" src="chrome://browser/content/browser.js"></script>
7+
<script type="text/javascript" src="chrome://selenium-ide/content/selenium-ide-loader.js"></script>
8+
<script type="text/javascript" charset="utf-8">
9+
function runTest(testFile){
10+
var editor = SeleniumIDE.Loader.getTopEditor();
11+
var testPath = "chrome://selenium-ide/content/selenium-tests/tests/"+testFile;
12+
var testCase = editor.app.getFormats().getDefaultFormat().loadFile(testPath, true);
13+
editor.app.setTestCaseWithNewSuite(testCase);
14+
editor.app.setBaseURL("chrome://selenium-ide/content/selenium-tests/tests/");
15+
editor.setInterval(200); // slow down because of Core test suite race conditions
16+
var testWindow = editor.showInBrowser("about:blank", true);
17+
editor.selDebugger.start(function(failed) {
18+
if(failed){
19+
document.getElementById('testResults').innerHTML = 'failed';
20+
} else {
21+
document.getElementById('testResults').innerHTML = 'succeeded';
22+
}
23+
testWindow.close();
24+
});
25+
}
26+
27+
function init(){
28+
var editor = SeleniumIDE.Loader.getTopEditor();
29+
if(!editor){
30+
SeleniumIDE.Loader.openRecorder();
31+
}
32+
}
33+
34+
</script>
35+
</head>
36+
37+
<body onload="init()">
38+
<div id="testResults">running</div>
39+
</body>
40+
</html>
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.openqa.selenium.ide;
2+
3+
import junit.framework.TestCase;
4+
5+
import java.io.File;
6+
import java.io.IOException;
7+
8+
import org.openqa.selenium.AbstractDriverTestCase;
9+
import org.openqa.selenium.By;
10+
import org.openqa.selenium.NeedsDriver;
11+
import org.openqa.selenium.WebDriverException;
12+
import org.openqa.selenium.firefox.FirefoxDriver;
13+
import org.openqa.selenium.firefox.FirefoxProfile;
14+
15+
public class IDECoreTest extends TestCase {
16+
private FirefoxDriver driver;
17+
private String testName;
18+
private static final String TEST_PATH = "chrome://selenium-ide/content/selenium-tests/tests/";
19+
20+
public IDECoreTest(FirefoxDriver driver, String testName) {
21+
super(testName);
22+
this.driver = driver;
23+
this.testName = testName;
24+
}
25+
26+
@Override
27+
public void runTest() throws Exception {
28+
driver.get("chrome://selenium-ide/content/tests/runner.html");
29+
while(Boolean.TRUE.equals(driver.executeScript("return SeleniumIDE.Loader.getTopEditor() == null;"))){
30+
Thread.sleep(100);
31+
}
32+
driver.executeScript("runTest('"+testName+"')");
33+
while("running".equals(driver.findElement(By.id("testResults")).getText())){
34+
Thread.sleep(100);
35+
}
36+
assertEquals("succeeded", driver.findElement(By.id("testResults")).getText());
37+
}
38+
}

ide/test/java/org/openqa/selenium/ide/IDETestSuite.java

+44-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.openqa.selenium.ide;
22

3+
import junit.extensions.TestSetup;
34
import junit.framework.Test;
45
import junit.framework.TestCase;
56
import junit.framework.TestSuite;
@@ -20,6 +21,7 @@
2021
import org.openqa.selenium.internal.TemporaryFilesystem;
2122

2223
import java.io.File;
24+
import java.io.FilenameFilter;
2325
import java.io.IOException;
2426
import java.util.HashMap;
2527
import java.util.Map;
@@ -29,7 +31,29 @@ public class IDETestSuite extends TestCase {
2931

3032
public static Test suite() throws Exception {
3133
TestSuite suite = new TestSuite(IDETestSuite.class);
32-
return suite;
34+
return addCoreTests(suite);
35+
}
36+
37+
private static Test addCoreTests(TestSuite suite) throws Exception {
38+
FirefoxProfile profile = new FirefoxProfile();
39+
profile.addExtension(findIDEExtensionRootInSourceCode());
40+
final FirefoxDriver persistentDriver = new FirefoxDriver(profile);
41+
File coreTestsDir = findCoreTestsInSourceCode();
42+
File[] files = coreTestsDir.listFiles(new FilenameFilter(){
43+
public boolean accept(File dir, String name) {
44+
return name.endsWith(".html");
45+
}
46+
});
47+
for(File testFile : files){
48+
suite.addTest(new IDECoreTest(persistentDriver, testFile.getName()));
49+
}
50+
return new TestSetup(suite){
51+
@Override
52+
protected void tearDown() throws Exception {
53+
System.err.println("Closing driver");
54+
persistentDriver.close();
55+
}
56+
};
3357
}
3458

3559
public void testExtensionFinding() throws Exception {
@@ -80,7 +104,7 @@ public void testFunctionalTests() throws Exception {
80104
}
81105
}
82106

83-
private File findIDEExtensionRootInSourceCode() {
107+
static File findIDEExtensionRootInSourceCode() {
84108
String[] possiblePaths = {
85109
"ide/src/extension",
86110
"../ide/src/extension",
@@ -98,4 +122,22 @@ private File findIDEExtensionRootInSourceCode() {
98122
throw new WebDriverException("Unable to locate IDE driver extension in developer source");
99123
}
100124

125+
static File findCoreTestsInSourceCode() {
126+
String[] possiblePaths = {
127+
"ide/src/extension/content/selenium-tests/tests",
128+
"../ide/src/extension/content/selenium-tests/tests",
129+
"../../ide/src/extension/content/selenium-tests/tests",
130+
};
131+
132+
File current;
133+
for (String potential : possiblePaths) {
134+
current = new File(potential);
135+
if (current.exists()) {
136+
return current;
137+
}
138+
}
139+
140+
throw new WebDriverException("Unable to locate IDE driver extension in developer source");
141+
}
142+
101143
}

0 commit comments

Comments
 (0)