Permalink
Browse files

ES: adding support for version numbers and updating the way we constr…

…uct the RemoteDriver to make it nicer
  • Loading branch information...
1 parent ca981e0 commit f30635d4ff9edaa0d1bf9b10d66f7033ef3062de extreme committed Dec 9, 2011
@@ -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;
+ }
+
+}
@@ -48,15 +48,15 @@
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;
}
@@ -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;
@@ -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."
@@ -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);
}

0 comments on commit f30635d

Please sign in to comment.