Skip to content

Commit

Permalink
ES: adding support for version numbers and updating the way we constr…
Browse files Browse the repository at this point in the history
…uct the RemoteDriver to make it nicer
  • Loading branch information
extreme committed Dec 9, 2011
1 parent ca981e0 commit f30635d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 16 deletions.
55 changes: 55 additions & 0 deletions src/play/modules/webdrive/Driver.java
@@ -0,0 +1,55 @@
package play.modules.webdrive;

import org.openqa.selenium.Platform;

public class Driver {

public static String ANY = "ANY";
public String name;
public String version;
public Platform platform;

public Driver(String[] driverParts) {
switch (driverParts.length) {
case 0:
System.out.println("wtf?");
break;
case 1:
this.name = driverParts[0];
this.version = ANY;
this.platform = Platform.ANY;
break;
case 2:
this.name = driverParts[0];
this.version = driverParts[1];
this.platform = Platform.ANY;
break;
case 3:
this.name = driverParts[0];
this.version = driverParts[1];
this.platform = Platform.valueOf(driverParts[2]);
break;
default:
this.name = driverParts[0];
this.version = driverParts[1];
this.platform = Platform.valueOf(driverParts[2]);
System.out.println("wtf? why haven't you updated this?");
break;
}
}

public Driver(String name) {
this(name, ANY);
}

public Driver(String name, String version) {
this(name, version, Platform.ANY);
}

public Driver(String name, String version, Platform platform) {
this.name = name;
this.version = version;
this.platform = platform;
}

}
8 changes: 4 additions & 4 deletions src/play/modules/webdrive/DriverManager.java
Expand Up @@ -48,15 +48,15 @@ public class DriverManager {
simpleDriverNames.put("iphone", IPhoneDriver.class);
}

public List<String> getRemoteDriverNames() {
List<String> drivers = new ArrayList<String>();
public List<Driver> getRemoteDriverNames() {
List<Driver> drivers = new ArrayList<Driver>();
String driversProp = System.getProperty("webdrive.remote.browsers");
if (driversProp == null || driversProp.trim().isEmpty()) {
return drivers;
}

for (String driver : driversProp.split(",")) {
drivers.add(driver);
for (String rawDriver : driversProp.split(",")) {
drivers.add(new Driver(rawDriver.split(":")));
}
return drivers;
}
Expand Down
34 changes: 22 additions & 12 deletions src/play/modules/webdrive/WebDriverRunner.java
Expand Up @@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.List;

import org.openqa.selenium.Platform;
import org.openqa.selenium.SeleneseCommandExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
Expand Down Expand Up @@ -184,30 +185,33 @@ private boolean run() throws Exception {
}

private boolean runRemote() throws Exception {
/* Run non-selenium tests */
// runTestsWithDriver(HtmlUnitDriver.class, nonSeleniumTests);

String thisHost = System.getProperty("webdrive.this.ipAddress");
String thisPort = System.getProperty("webdrive.this.port", "9000");
appUrlBase = "http://"+thisHost+":"+thisPort;

System.out.println("&&&&& - Going to pass this to remote node to connect back to me: " + appUrlBase);
System.out.println("~ Going to pass this to remote node to connect back to me: " + appUrlBase);

DriverManager manager = new DriverManager();
List<String> driverNames = manager.getRemoteDriverNames();
List<Driver> drivers = manager.getRemoteDriverNames();

for (String driver : driverNames) {
for (Driver driver : drivers) {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(driver);
capabilities.setBrowserName(driver.name);

if (!driver.version.equals(Driver.ANY)) {
capabilities.setVersion(driver.version);
}
if (!driver.platform.equals(Platform.ANY)) {
capabilities.setPlatform(driver.platform);
}

CommandExecutor executor = new SeleneseCommandExecutor(new URL(System.getProperty("webdrive.remoteUrl")), new URL(appUrlBase + "/@tests/init"), capabilities);
WebDriver webDriver = new RemoteWebDriver(executor, capabilities);

System.out.println("~ Starting tests remotely with " + capabilities.getBrowserName());
WebDriver webDriver = new RemoteWebDriver(new URL(System.getProperty("webdrive.remoteUrl")), capabilities);

System.out.println("~ Starting tests remotely with " + constructNiceDriverName(capabilities));

/* Run selenium tests on all browsers */
runTests(seleniumTests, webDriver);

}

File resultFile = new File(testResultRoot, "result."
Expand All @@ -216,12 +220,18 @@ private boolean runRemote() throws Exception {

return !failed;
}

private String constructNiceDriverName(DesiredCapabilities capabilities) {
return capabilities.getBrowserName()
+ ((capabilities.getVersion() != null) ? " v" + capabilities.getVersion() : "")
+ ((capabilities.getPlatform() != null) ? " on " + capabilities.getPlatform().name() : "");
}



private void runTestsWithDriver(Class<?> webDriverClass, List<String> tests)
throws Exception {
System.out.println("~ Starting tests with " + webDriverClass);
System.out.println("~ Starting tests locally with " + webDriverClass);
WebDriver webDriver = (WebDriver) webDriverClass.newInstance();
runTests(tests, webDriver);
}
Expand Down

0 comments on commit f30635d

Please sign in to comment.