Skip to content

Commit eb31e47

Browse files
committed
Add a test case to allow the Core tests to run
This exercises the HTMLLauncher.
1 parent cc309c9 commit eb31e47

File tree

6 files changed

+119
-1
lines changed

6 files changed

+119
-1
lines changed

java/client/test/com/thoughtworks/selenium/BUCK

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ java_library(
5454
'//third_party/java/mockito:mockito',
5555
'//third_party/java/servlet:servlet-api',
5656
],
57+
visibility = [
58+
'//java/server/test/org/openqa/selenium/server/htmlrunner:htmlrunner',
59+
],
5760
)

java/server/src/org/openqa/selenium/server/htmlrunner/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ java_library(
2424
],
2525
visibility = [
2626
'//java/server/src/com/thoughtworks/selenium:leg-rc',
27+
'//java/server/test/org/openqa/selenium/...',
2728
],
2829
)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ public void run(Results results, WebDriver driver, Selenium selenium) {
4747
for (CoreTestStep step : steps) {
4848
try {
4949
step.run(results, driver, selenium);
50+
Thread.sleep(2000);
5051
} catch (SeleniumException e) {
5152
results.addTestFailure();
5253
return;
54+
} catch (InterruptedException e) {
55+
e.printStackTrace();
5356
}
5457
}
5558
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ private String runHTMLSuite(String browser, String browserURL, String suiteURL,
158158
}
159159
}
160160

161-
driver.quit();
161+
if (driver != null) {
162+
driver.quit();
163+
}
162164
}
163165

164166
// if (results == null) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
java_test(
2+
name = 'htmlrunner',
3+
srcs = glob(['*.java']),
4+
deps = [
5+
'//java/client/src/org/openqa/selenium:selenium',
6+
'//java/client/test/com/thoughtworks/selenium:tests',
7+
'//java/client/test/org/openqa/selenium/environment:environment',
8+
'//java/server/src/org/openqa/selenium/server/htmlrunner:htmlrunner',
9+
'//third_party/java/guava:guava',
10+
'//third_party/java/junit:junit',
11+
],
12+
)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.server.htmlrunner;
19+
20+
import static org.junit.Assert.assertTrue;
21+
22+
import com.google.common.collect.ImmutableSortedSet;
23+
24+
import com.thoughtworks.selenium.testing.SeleniumAppServer;
25+
26+
import org.junit.AfterClass;
27+
import org.junit.BeforeClass;
28+
import org.junit.Test;
29+
import org.junit.runner.RunWith;
30+
import org.junit.runners.Parameterized;
31+
import org.openqa.selenium.Platform;
32+
import org.openqa.selenium.environment.webserver.AppServer;
33+
34+
import java.io.File;
35+
import java.io.IOException;
36+
import java.util.concurrent.TimeUnit;
37+
38+
@RunWith(Parameterized.class)
39+
public class CoreSelfTest {
40+
41+
private final String browser;
42+
private static AppServer server;
43+
44+
public CoreSelfTest(String browser) {
45+
this.browser = browser;
46+
}
47+
48+
@BeforeClass
49+
public static void startTestServer() {
50+
server = new SeleniumAppServer();
51+
server.start();
52+
}
53+
54+
@AfterClass
55+
public static void stopTestServer() {
56+
server.stop();
57+
}
58+
59+
@Test
60+
public void executeTests() throws IOException {
61+
String testBase = server.whereIs("/selenium-server/tests");
62+
File outputFile = File.createTempFile("core-test-suite", browser.replace('*', '-') + ".txt");
63+
assertTrue(outputFile.delete());
64+
65+
new HTMLLauncher().runHTMLSuite(browser,
66+
// We need to do this because the path relativizing code in java.net.URL is
67+
// clearly having a bad day. "/selenium-server/tests" appended to "../tests/"
68+
// ends up as "/tests" rather than "/selenium-server/tests" as you'd expect.
69+
testBase + "/TestSuite.html",
70+
testBase + "/TestSuite.html",
71+
outputFile,
72+
TimeUnit.MINUTES.toMillis(5),
73+
true);
74+
}
75+
76+
@Parameterized.Parameters
77+
public static Iterable<String> parameters() {
78+
ImmutableSortedSet.Builder<String> browsers = ImmutableSortedSet.naturalOrder();
79+
80+
// if (CommandLine.find("wires") != null) {
81+
browsers.add("*firefox");
82+
// }
83+
84+
switch (Platform.getCurrent().family()) {
85+
case MAC:
86+
// browsers.add("*safari");
87+
break;
88+
89+
case WINDOWS:
90+
browsers.add("*iexplore");
91+
break;
92+
}
93+
94+
System.out.println("browsers.build() = " + browsers.build());
95+
return browsers.build();
96+
}
97+
}

0 commit comments

Comments
 (0)