Skip to content

Commit

Permalink
Deleting ability to run html suites with selenium-server-standalone, …
Browse files Browse the repository at this point in the history
…users are adviced to use htmlrunner
  • Loading branch information
barancev committed Feb 8, 2018
1 parent 63f7b50 commit b8b0d09
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 103 deletions.

This file was deleted.

56 changes: 5 additions & 51 deletions java/server/src/org/openqa/grid/selenium/GridLauncherV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import org.openqa.grid.common.GridRole;
import org.openqa.grid.internal.utils.SelfRegisteringRemote;
import org.openqa.grid.internal.utils.configuration.CoreRunnerConfiguration;
import org.openqa.grid.internal.utils.configuration.GridHubConfiguration;
import org.openqa.grid.internal.utils.configuration.GridNodeConfiguration;
import org.openqa.grid.internal.utils.configuration.StandaloneConfiguration;
Expand All @@ -40,7 +39,6 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand All @@ -56,8 +54,6 @@
public class GridLauncherV3 {

private static final Logger log = Logger.getLogger(GridLauncherV3.class.getName());
private static final String CORE_RUNNER_CLASS =
"org.openqa.selenium.server.htmlrunner.HTMLLauncher";
private static final BuildInfo buildInfo = new BuildInfo();

private PrintStream out;
Expand Down Expand Up @@ -132,18 +128,10 @@ private GridItemLauncher buildLauncher(String[] args) {

for (int i = 0; i < args.length; i++) {
if (args[i].equals("-htmlSuite")) {
Function<String[], GridItemLauncher> launcherSupplier = LAUNCHERS.get("corerunner");
if (launcherSupplier == null) {
out.println(Joiner.on("\n").join(
"Unable to find the HTML runner. This is normally because you have not downloaded",
"or made available the 'selenium-leg-rc' jar on the CLASSPATH. Your test will",
"not be run.",
"Download the Selenium HTML Runner from http://www.seleniumhq.org/download/ and",
"use that in place of the selenium-server-standalone.jar for the simplest way of",
"running your HTML suite."));
return null;
}
return launcherSupplier.apply(args);
out.println(Joiner.on("\n").join(
"Download the Selenium HTML Runner from http://www.seleniumhq.org/download/ and",
"use that to run your HTML suite."));
return null;
}
if (args[i].startsWith("-role=")) {
role = args[i].substring("-role=".length());
Expand Down Expand Up @@ -266,7 +254,7 @@ public StandaloneConfiguration getConfiguration() {
return configuration;
}

public Stoppable launch() throws Exception {
public Stoppable launch() {
log.info(String.format(
"Launching a standalone Selenium Server on port %s", configuration.port));
SeleniumServer server = new SeleniumServer(configuration);
Expand Down Expand Up @@ -338,40 +326,6 @@ public Stoppable launch() throws Exception {
}
});

try {
Class.forName(CORE_RUNNER_CLASS, false, GridLauncherV3.class.getClassLoader());

launchers.put("corerunner", (args) -> new GridItemLauncher() {
CoreRunnerConfiguration configuration = new CoreRunnerConfiguration();
{
JCommander.newBuilder().addObject(configuration).build().parse(args);
}
public StandaloneConfiguration getConfiguration() {
return configuration;
}

@Override
public Stoppable launch() throws Exception {
Class<?> coreRunnerClass = Class.forName(CORE_RUNNER_CLASS);
Object coreRunner = coreRunnerClass.newInstance();
Method mainInt = coreRunnerClass.getMethod("mainInt", String[].class);

CoreRunnerConfiguration runnerConfig = this.configuration;
String[] args = new String[] {
"-htmlSuite",
/* browser string */ runnerConfig.htmlSuite.get(0),
/* start url */ runnerConfig.htmlSuite.get(1),
/* suite */ runnerConfig.htmlSuite.get(2),
/* Results file */ runnerConfig.htmlSuite.get(3),
};
mainInt.invoke(coreRunner, (Object) args);
return () -> {};
}
});
} catch (ReflectiveOperationException e) {
// Do nothing. It's fine.
}

return launchers.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
public class GridViaCommandLineTest {

@Test
public void unrecognizedRole() throws Exception {
public void unrecognizedRole() {
ByteArrayOutputStream outSpy = new ByteArrayOutputStream();
String[] args = {"-role", "hamlet"};
new GridLauncherV3(new PrintStream(outSpy), args).launch();
Expand All @@ -64,15 +64,15 @@ public void unrecognizedRole() throws Exception {
}

@Test
public void canPrintVersion() throws Exception {
public void canPrintVersion() {
ByteArrayOutputStream outSpy = new ByteArrayOutputStream();
String[] args = {"-version"};
new GridLauncherV3(new PrintStream(outSpy), args).launch();
assertThat(outSpy.toString(), startsWith("Selenium server version: "));
}

@Test
public void canPrintGeneralHelp() throws Exception {
public void canPrintGeneralHelp() {
ByteArrayOutputStream outSpy = new ByteArrayOutputStream();
String[] args = {"-help"};
new GridLauncherV3(new PrintStream(outSpy), args).launch();
Expand All @@ -81,7 +81,7 @@ public void canPrintGeneralHelp() throws Exception {
}

@Test
public void canPrintHubHelp() throws Exception {
public void canPrintHubHelp() {
ByteArrayOutputStream outSpy = new ByteArrayOutputStream();
String[] args = {"-role", "hub", "-help"};
new GridLauncherV3(new PrintStream(outSpy), args).launch();
Expand All @@ -90,7 +90,7 @@ public void canPrintHubHelp() throws Exception {
}

@Test
public void canPrintNodeHelp() throws Exception {
public void canPrintNodeHelp() {
ByteArrayOutputStream outSpy = new ByteArrayOutputStream();
String[] args = {"-role", "node", "-help"};
new GridLauncherV3(new PrintStream(outSpy), args).launch();
Expand All @@ -111,13 +111,11 @@ public void canRedirectLogToFile() throws Exception {
}

@Test
@org.junit.Ignore
public void canStartHtmlSuite() throws Exception {
Path tempLog = Files.createTempFile("test", ".log");
String[] args = {"-htmlSuite", "*quantum", "http://base.url", "suite.html", "report.html", "-log", tempLog.toString()};
new GridLauncherV3(args).launch();
String log = String.join("", Files.readAllLines(tempLog));
assertThat(log, containsString("Unrecognized browser: *quantum"));
public void canStartHtmlSuite() {
ByteArrayOutputStream outSpy = new ByteArrayOutputStream();
String[] args = {"-htmlSuite", "*quantum", "http://base.url", "suite.html", "report.html"};
new GridLauncherV3(new PrintStream(outSpy), args).launch();
assertThat(outSpy.toString(), containsString("Download the Selenium HTML Runner"));
}

@Test
Expand All @@ -126,15 +124,19 @@ public void testRegisterNodeToHub() throws Exception {
String[] hubArgs = {"-role", "hub", "-port", hubPort.toString()};
Optional<Stoppable> hub = new GridLauncherV3(hubArgs).launch();
UrlChecker urlChecker = new UrlChecker();
urlChecker.waitUntilAvailable(10, TimeUnit.SECONDS, new URL(String.format("http://localhost:%d/grid/console", hubPort)));
urlChecker.waitUntilAvailable(10, TimeUnit.SECONDS, new URL(
String.format("http://localhost:%d/grid/console", hubPort)));

Integer nodePort = PortProber.findFreePort();

String[] nodeArgs = {"-role", "node", "-hub", "http://localhost:" + hubPort, "-browser", "browserName=htmlunit,maxInstances=1", "-port", nodePort.toString()};
String[] nodeArgs = {"-role", "node", "-hub", "http://localhost:" + hubPort,
"-browser", "browserName=htmlunit,maxInstances=1", "-port", nodePort.toString()};
Optional<Stoppable> node = new GridLauncherV3(nodeArgs).launch();
urlChecker.waitUntilAvailable(100, TimeUnit.SECONDS, new URL(String.format("http://localhost:%d/wd/hub/status", nodePort)));
urlChecker.waitUntilAvailable(100, TimeUnit.SECONDS, new URL(
String.format("http://localhost:%d/wd/hub/status", nodePort)));

new FluentWait<>(new URL(String.format("http://localhost:%d/grid/console", hubPort))).withTimeout(5, TimeUnit.SECONDS).pollingEvery(50, TimeUnit.MILLISECONDS)
new FluentWait<>(new URL(String.format("http://localhost:%d/grid/console", hubPort)))
.withTimeout(5, TimeUnit.SECONDS).pollingEvery(50, TimeUnit.MILLISECONDS)
.until((Function<URL, Boolean>) u -> {
try (InputStream is = u.openConnection().getInputStream();
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
Expand All @@ -150,7 +152,8 @@ public void testRegisterNodeToHub() throws Exception {

try {
driver.get(String.format("http://localhost:%d/grid/console", hubPort));
assertEquals("Should only have one htmlunit registered to the hub", 1, driver.findElements(By.cssSelector("img[src$='htmlunit.png']")).size());
assertEquals("Should only have one htmlunit registered to the hub",
1, driver.findElements(By.cssSelector("img[src$='htmlunit.png']")).size());
} finally {
try {
driver.quit();
Expand Down

0 comments on commit b8b0d09

Please sign in to comment.