Index: clients/java/src/test/java/com/thoughtworks/selenium/ClientDriverSuite.java =================================================================== --- clients/java/src/test/java/com/thoughtworks/selenium/ClientDriverSuite.java (revision 1715) +++ clients/java/src/test/java/com/thoughtworks/selenium/ClientDriverSuite.java (working copy) @@ -62,6 +62,8 @@ if (isProxyInjectionMode) { + // Run test for selecting windows by titles through PI mode + suite.addTestSuite(TestSelectWindowTitle.class); suite.addTestSuite(TestClick.class); // ok, run just a single test in PI mode } else { Index: server-coreless/src/main/java/org/openqa/selenium/server/FrameGroupCommandQueueSet.java =================================================================== --- server-coreless/src/main/java/org/openqa/selenium/server/FrameGroupCommandQueueSet.java (revision 1715) +++ server-coreless/src/main/java/org/openqa/selenium/server/FrameGroupCommandQueueSet.java (working copy) @@ -88,8 +88,25 @@ } FrameAddress match = findMatchingFrameAddress(frameAddressToCommandQueue.keySet(), seleniumWindowName, DEFAULT_LOCAL_FRAME_ADDRESS); - if (match==null) { - return "ERROR: could not find window " + seleniumWindowName; + + // If we didn't find a match, try finding the frame address by window title + if (match == null) { + boolean windowFound = false; + for (FrameAddress frameAddress : frameAddressToCommandQueue.keySet()) { + CommandQueue commandQueue = frameAddressToCommandQueue.get(frameAddress); + String cmdResult = commandQueue.doCommand("getTitle", "", ""); + cmdResult = cmdResult.substring(3); + if (cmdResult.equals(seleniumWindowName)) { + windowFound = true; + match = frameAddress; + break; + } + } + + // Return with an error if we didn't find the window + if (!windowFound) { + return "ERROR: could not find window " + seleniumWindowName; + } } setCurrentFrameAddress(match); return "OK"; @@ -249,6 +266,11 @@ return waitForLoad(SeleniumServer.getTimeoutInSeconds() * 1000l); } + + if (command.equals("getAllWindowNames")) { + return getAllWindowNames(); + } + } // if (SeleniumServer.isProxyInjectionMode()) return getCommandQueue().doCommand(command, arg, value); } @@ -256,6 +278,59 @@ dataLock.unlock(); } } + + /** + * Generates a CSV string from the given string array. + * + * @param stringArray Array of strings to generate a CSV. + */ + public String getStringArrayAccessorCSV(String[] stringArray) { + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < stringArray.length; i++) { + // Obey specs for String Array accessor responses + String str = stringArray[i]; + + // If the string contains a slash make it appear as \\ in the protocol + // 1 slash in Java/regex is \\\\ + str = str.replaceAll("\\\\", "\\\\\\\\"); + str = str.replaceAll(",", "\\\\,"); + sb.append(str); + if ((i+1) < stringArray.length) { + sb.append('\\'); + sb.append(','); + sb.append(" "); + } + } + + return sb.toString(); + } + + /** + * Get all window names from the server. Since the JS in the browser + * cannot possibly know about all windows. + */ + private String getAllWindowNames() { + // If we're not in PI mode, send the command back to the browser. + if (!SeleniumServer.isProxyInjectionMode()) { + return doCommand("getAllWindowNames", "", ""); + } + + Set frameAddressSet = frameAddressToCommandQueue.keySet(); + List windowNames = new ArrayList(); + + // Find all window names in the set of frame addresses + for (FrameAddress frameAddress : frameAddressSet) { + String windowName = frameAddress.getWindowName(); + if (!windowNames.contains(windowName)) { + windowNames.add(windowName); + } + } + + String frameAddressCSV = getStringArrayAccessorCSV(windowNames.toArray(new String[0])); + + return "OK," + frameAddressCSV; + } private String waitForLoad(long timeoutInMilliseconds) { int timeoutInSeconds = (int)(timeoutInMilliseconds / 1000l); @@ -318,6 +393,7 @@ if (!f.getLocalFrameAddress().equals(localFrame)) { return false; } + if (f.getWindowName().equals(windowName)) { return true; } Index: selenium-server/pom.xml =================================================================== --- selenium-server/pom.xml (revision 1715) +++ selenium-server/pom.xml (working copy) @@ -64,7 +64,7 @@ org.openqa.selenium.core selenium-core - 0.8.2-SNAPSHOT + 0.8.3-SNAPSHOT provided