Revision: 5384
Author:   [email protected]
Date:     Mon Apr 29 17:15:34 2013
Log:      partial support for Safari testing
https://codereview.appspot.com/9022043

With this CL, browser tests of safari work when connecting to a remote
webdriver.  Meaning:
  1. start "java -jar selenium-standalone*.jar"
2. run "ant brtest -Dtest.browser=safari -Dtest.webdriver.url=http://127.0.0.1:4444/wd/hub";

the main fix in this CL is that window.open doesn't work in the
Safari webdriver.

There's also code to start a local SafariDriver, but that doesn't work
yet. (There's a weird protocol failure when trying to send a command
to the webdriver Safari extension, and I haven't figured out why yet.)

R=kpreid2


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

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

=======================================
--- /trunk/tests/com/google/caja/plugin/WebDriverHandle.java Mon Apr 29 14:12:29 2013 +++ /trunk/tests/com/google/caja/plugin/WebDriverHandle.java Mon Apr 29 17:15:34 2013
@@ -23,10 +23,12 @@

 import org.openqa.selenium.Capabilities;
 import org.openqa.selenium.JavascriptExecutor;
-import org.openqa.selenium.UnsupportedCommandException;
+import org.openqa.selenium.NoSuchWindowException;
 import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebDriverException;
 import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.safari.SafariDriver;
 import org.openqa.selenium.remote.DesiredCapabilities;
 import org.openqa.selenium.remote.RemoteWebDriver;

@@ -69,11 +71,22 @@
       firstWindow = driver.getWindowHandle();
       try {
         driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
+      } catch (WebDriverException e) {
+        log("failed to set pageLoadTimeout: " + e.toString());
+        // harmless, ignore
+      }
+      try {
         driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
-      } catch (UnsupportedCommandException e) {
-        // ignore
+      } catch (WebDriverException e) {
+        log("failed to setScriptTimeout: " + e.toString());
+        // harmless, ignore
       }
     }
+    // We try to run tests in a fresh window in an existing session,
+    // so we can avoid session startup overhead for each test.
+    // In some webdriver implementations (such as Safari), the
+    // window.open will fail, which is fine, we'll just run the test
+    // in the base window and open a new session for the next test.
     JavascriptExecutor jsexec = driver;
     String name = "cajatestwin" + (windowSeq++);
     Boolean result = (Boolean) jsexec.executeScript(
@@ -110,9 +123,15 @@
   }

   void closeWindow() {
-    if (driver != null) {
-      driver.close();
+    if (driver == null) { return; }
+    driver.close();
+    try {
       driver.switchTo().window(firstWindow);
+    } catch (NoSuchWindowException e) {
+      // if makeWindow didn't succeed in creating a new window, then we
+      // closed our only window, and we'll need a new webdriver session.
+      driver.quit();
+      driver = null;
     }
   }

@@ -144,6 +163,9 @@
   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);
@@ -163,6 +185,9 @@
       return new ChromeDriver(dc);
     } else if ("firefox".equals(browserType)) {
       return new FirefoxDriver();
+    } else if ("safari".equals(browserType)) {
+      // TODO(felix8a): local safari doesn't work yet
+      return new SafariDriver();
     } else {
       throw new RuntimeException("No local driver for browser type '"
           + browserType + "'");

--

--- 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