Skip to content

Commit f7f5d04

Browse files
committed
Attempt better backwards compatability with the old html suite runner command line flags
The 2.x `htmlSuite` option was one of many passed to the standalone server. With this change, we handle lots of the original flags that could be used.
1 parent 73adc59 commit f7f5d04

File tree

4 files changed

+102
-36
lines changed

4 files changed

+102
-36
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ java_library(
2121
'//java/client/src/org/openqa/selenium/remote:remote',
2222
'//java/client/src/org/openqa/selenium/safari:safari',
2323
'//third_party/java/guava:guava',
24+
'//third_party/java/beust:jcommander',
2425
'//third_party/java/jetty:jetty',
2526
],
2627
visibility = [

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

Lines changed: 98 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import static org.openqa.selenium.firefox.FirefoxDriver.MARIONETTE;
2121

22+
import com.beust.jcommander.JCommander;
23+
import com.beust.jcommander.Parameter;
2224
import com.thoughtworks.selenium.Selenium;
2325
import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
2426

@@ -52,6 +54,7 @@
5254
import java.nio.file.Files;
5355
import java.nio.file.Path;
5456
import java.nio.file.Paths;
57+
import java.util.ArrayList;
5558
import java.util.List;
5659
import java.util.logging.Level;
5760
import java.util.logging.Logger;
@@ -76,31 +79,16 @@ public class HTMLLauncher {
7679
* @param suiteURL - the relative URL to the HTML suite
7780
* @param outputFile - The file to which we'll output the HTML results
7881
* @param timeoutInSeconds - the amount of time (in seconds) to wait for the browser to finish
79-
* @param multiWindow TODO
8082
* @return PASS or FAIL
8183
* @throws IOException if we can't write the output file
8284
*/
83-
public String runHTMLSuite(String browser, String browserURL, String suiteURL, File outputFile,
84-
long timeoutInSeconds, boolean multiWindow) throws IOException {
85-
return runHTMLSuite(browser, browserURL, suiteURL, outputFile,
86-
timeoutInSeconds, multiWindow, "info");
87-
}
88-
89-
/**
90-
* Launches a single HTML Selenium test suite.
91-
*
92-
* @param browser - the browserString ("*firefox", "*iexplore" or an executable path)
93-
* @param browserURL - the start URL for the browser
94-
* @param suiteURL - the relative URL to the HTML suite
95-
* @param outputFile - The file to which we'll output the HTML results
96-
* @param multiWindow TODO
97-
* @param defaultLogLevel TODO
98-
* @param timeoutInSeconds - the amount of time (in seconds) to wait for the browser to finish
99-
* @return PASS or FAIL
100-
* @throws IOException if we can't write the output file
101-
*/
102-
private String runHTMLSuite(String browser, String browserURL, String suiteURL, File outputFile,
103-
long timeoutInSeconds, boolean multiWindow, String defaultLogLevel) throws IOException {
85+
public String runHTMLSuite(
86+
String browser,
87+
String browserURL,
88+
String suiteURL,
89+
File outputFile,
90+
long timeoutInSeconds,
91+
String userExtensions) throws IOException {
10492
File parent = outputFile.getParentFile();
10593
if (parent != null && !parent.exists()) {
10694
parent.mkdirs();
@@ -121,6 +109,10 @@ private String runHTMLSuite(String browser, String browserURL, String suiteURL,
121109

122110
driver.get(suiteUrl.toString());
123111
Selenium selenium = new WebDriverBackedSelenium(driver, browserURL);
112+
selenium.setTimeout(String.valueOf(timeoutInMs));
113+
if (userExtensions != null) {
114+
selenium.setExtensionJs(userExtensions);
115+
}
124116
List<WebElement> allTables = driver.findElements(By.id("suiteTable"));
125117
if (allTables.isEmpty()) {
126118
throw new RuntimeException("Unable to find suite table: " + driver.getPageSource());
@@ -211,31 +203,46 @@ private URL verifySuiteUrl(URL url) throws IOException {
211203
}
212204

213205
public static int mainInt(String... args) throws Exception {
214-
if (args.length != 4) {
215-
throw new IllegalAccessException(
216-
"Usage: HTMLLauncher outputDir testSuite startUrl browser");
206+
Args processed = new Args();
207+
JCommander jCommander = new JCommander(processed);
208+
jCommander.setCaseSensitiveOptions(false);
209+
jCommander.parse(args);
210+
211+
if (processed.help) {
212+
StringBuilder help = new StringBuilder();
213+
jCommander.usage(help);
214+
System.err.print(help);
215+
return 0;
217216
}
218217

219-
File dir = new File(args[0]);
220-
if (!dir.exists() && !dir.mkdirs()) {
221-
throw new RuntimeException("Cannot create output directory for: " + dir);
218+
if (!validateArgs(processed)) {
219+
return -1;
222220
}
223221

224-
String suite = args[1];
225-
String startURL = args[2];
226-
String[] browsers;
227-
browsers = new String[] {args[3]};
222+
Path resultsPath = Paths.get(processed.htmlSuite.get(3));
223+
Files.createDirectories(resultsPath);
224+
225+
String suite = processed.htmlSuite.get(2);
226+
String startURL = processed.htmlSuite.get(1);
227+
String[] browsers = new String[] {processed.htmlSuite.get(0)};
228228

229229
HTMLLauncher launcher = new HTMLLauncher();
230230

231231
boolean passed = true;
232232
for (String browser : browsers) {
233233
// Turns out that Windows doesn't like "*" in a path name
234-
File results = new File(dir, browser.substring(1) + ".results");
234+
File results = resultsPath.resolve(browser.substring(1) + ".results").toFile();
235235
String result = "FAILED";
236236

237237
try {
238-
result = launcher.runHTMLSuite(browser, startURL, suite, results, 600, true);
238+
long timeout;
239+
try {
240+
timeout = Long.parseLong(processed.timeout);
241+
} catch (NumberFormatException e) {
242+
System.err.println("Timeout does not appear to be a number: " + processed.timeout);
243+
return -2;
244+
}
245+
result = launcher.runHTMLSuite(browser, startURL, suite, results, timeout, processed.userExtensions);
239246
passed &= "PASSED".equals(result);
240247
} catch (Throwable e) {
241248
log.log(Level.WARNING, "Test of browser failed: " + browser, e);
@@ -246,6 +253,22 @@ public static int mainInt(String... args) throws Exception {
246253
return passed ? 1 : 0;
247254
}
248255

256+
private static boolean validateArgs(Args processed) {
257+
if (processed.multiWindow) {
258+
System.err.println("Multi-window mode is longer used as an option and will be ignored.");
259+
}
260+
261+
if (processed.port != 0) {
262+
System.err.println("Port is longer used as an option and will be ignored.");
263+
}
264+
265+
if (processed.trustAllSSLCertificates) {
266+
System.err.println("Trusting all ssl certificates is no longer a user-settable option.");
267+
}
268+
269+
return true;
270+
}
271+
249272
public static void main(String[] args) throws Exception {
250273
System.exit(mainInt(args));
251274
}
@@ -285,4 +308,45 @@ private WebDriver createDriver(String browser) {
285308
throw new RuntimeException("Unrecognized browser: " + browser);
286309
}
287310
}
311+
312+
public static class Args {
313+
@Parameter(
314+
names = "-htmlSuite",
315+
required = true,
316+
arity = 4,
317+
description = "Run an HTML Suite: '*browser' 'http://baseUrl.com' 'path\\to\\HTMLSuite.html' 'c:\\absolute\\path\\to\\my\\results.html'")
318+
private List<String> htmlSuite;
319+
320+
@Parameter(
321+
names = "-timeout",
322+
description = "Timeout to use in seconds")
323+
private String timeout = "30";
324+
325+
@Parameter(
326+
names = "-userExtensions",
327+
description = "User extensions to attempt to use."
328+
)
329+
private String userExtensions;
330+
331+
@Parameter(
332+
names = "-multiwindow",
333+
hidden = true)
334+
private boolean multiWindow = true;
335+
336+
@Parameter(
337+
names = "-port",
338+
hidden = true)
339+
private Integer port;
340+
341+
@Parameter(
342+
names = "-trustAllSSLCertificates",
343+
hidden = true)
344+
private boolean trustAllSSLCertificates;
345+
346+
@Parameter(
347+
names = {"-help", "--help", "-h"},
348+
description = "This help message",
349+
help = true)
350+
private boolean help;
351+
}
288352
}

java/server/test/org/openqa/selenium/server/htmlrunner/CoreSelfTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public void executeTests() throws IOException {
7979
testBase + "/TestSuite.html",
8080
testBase + "/TestSuite.html",
8181
outputFile.toFile(),
82-
TimeUnit.MINUTES.toMillis(5),
83-
true);
82+
TimeUnit.MINUTES.toSeconds(5),
83+
null);
8484

8585
assertEquals("PASSED", result);
8686
}

third_party/java/beust/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ prebuilt_jar(
77
'//java/server/src/org/openqa/grid:grid',
88
'//java/server/src/org/openqa/grid/selenium:classes',
99
'//java/server/src/org/openqa/selenium/remote/server:standalone-server-lib',
10+
'//java/server/src/org/openqa/selenium/server/htmlrunner:htmlrunner',
1011
'//java/server/test/...',
1112
'//third_party/java/testng:testng'
1213
],

0 commit comments

Comments
 (0)