Revision: 5428
Author:   [email protected]
Date:     Wed May 29 22:56:37 2013
Log:      chrome testing fixes
https://codereview.appspot.com/9854046

1. Starting with Chrome 29 (canary), chromedriver no longer works.
   Instead we need chromedriver2 (which also works with earlier Chromes).

2. Chromedriver2 no longer supports the old way of setting
   Chrome options with capability names like "chrome.binary".
   We need to use the ChromeOptions object.

3. This adds a new flag test.chrome.args which lets you specify a
   semicolon-separated list of command-line args for Chrome.

   In particular "--js-flags=--harmony" will turn on experimental js
   features.  (Note, if you look at about:flags, "experimental js"
   will show as off. The "experimental js" flag causes Chrome to pass
   --harmony to the js engine, and it doesn't reflect the current
   state of the js engine. There isn't a command-line arg that will
   set the "experimental js" flag itself.)

4. I'm updating selenium to the latest 2.33 for no reason, it's not
   relevant to any of the Chrome problems.  (The jar isn't in this
   CL because codereview gets confused by the large binary file.)

I'll update the wiki page on testing after committing this.

R=kpreid2


http://code.google.com/p/google-caja/source/detail?r=5428

Modified:
 /trunk/tests/com/google/caja/plugin/WebDriverHandle.java
 /trunk/tests/com/google/caja/util/TestFlag.java

=======================================
--- /trunk/tests/com/google/caja/plugin/WebDriverHandle.java Tue May 14 14:13:11 2013 +++ /trunk/tests/com/google/caja/plugin/WebDriverHandle.java Wed May 29 22:56:37 2013
@@ -26,10 +26,11 @@
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebDriverException;
 import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeOptions;
 import org.openqa.selenium.firefox.FirefoxDriver;
-import org.openqa.selenium.safari.SafariDriver;
 import org.openqa.selenium.remote.DesiredCapabilities;
 import org.openqa.selenium.remote.RemoteWebDriver;
+import org.openqa.selenium.safari.SafariDriver;

 import com.google.caja.util.TestFlag;

@@ -52,8 +53,8 @@
   WebDriver makeWindow() {
     if (driver == null) {
       driver = makeDriver();
+      firstWindow = driver.getWindowHandle();
       reportVersion(driver);
-      firstWindow = driver.getWindowHandle();
       try {
         driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
       } catch (WebDriverException e) {
@@ -116,6 +117,12 @@
   void closeWindow() {
     if (driver == null) { return; }
     driver.close();
+    if (firstWindow == null) {
+      // we failed sometime during initialization; quit and try again.
+      driver.quit();
+      driver = null;
+      return;
+    }
     try {
       driver.switchTo().window(firstWindow);
     } catch (NoSuchWindowException e) {
@@ -150,16 +157,28 @@
   private RemoteWebDriver makeDriver() {
     DesiredCapabilities dc = new DesiredCapabilities();

-    // Chrome driver is odd in that the path to Chrome is specified
-    // by a desiredCapability when you start a session. The other
-    // browser drivers will read a java system property on start.
-    String chrome = TestFlag.CHROME_BINARY.getString(null);
-    if (chrome != null) {
-      dc.setCapability("chrome.binary", chrome);
+    String browserType = getBrowserType();
+
+    if ("chrome".equals(browserType)) {
+      // Chrome driver is odd in that the path to Chrome is specified
+      // by a desiredCapability when you start a session. The other
+      // browser drivers will read a java system property on start.
+      // This applies to both remote Chrome and local Chrome.
+      ChromeOptions chromeOpts = new ChromeOptions();
+      String chromeBin = TestFlag.CHROME_BINARY.getString(null);
+      if (chromeBin != null) {
+        chromeOpts.setBinary(chromeBin);
+      }
+      String chromeArgs = TestFlag.CHROME_ARGS.getString(null);
+      if (chromeArgs!= null) {
+        String[] args = chromeArgs.split(";");
+        chromeOpts.addArguments(args);
+      }
+      dc.setCapability(ChromeOptions.CAPABILITY, chromeOpts);
     }

-    String browserType = getBrowserType();
     String webdriver = TestFlag.WEBDRIVER_URL.getString("");
+
     if (!"".equals(webdriver)) {
       dc.setBrowserName(browserType);
       dc.setJavascriptEnabled(true);
=======================================
--- /trunk/tests/com/google/caja/util/TestFlag.java     Mon Apr 29 14:12:29 2013
+++ /trunk/tests/com/google/caja/util/TestFlag.java     Wed May 29 22:56:37 2013
@@ -34,6 +34,8 @@
       "test.browser"),
   BROWSER_CLOSE(
       "test.browser.close"),
+  CHROME_ARGS(
+      "test.chrome.args"),
   CHROME_BINARY(
       "test.chrome.binary"),
   DEBUG(

--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to