Skip to content

Commit

Permalink
AlexeiBarantsev: Fixing openWindow in WebDriverBackedSelenium to allo…
Browse files Browse the repository at this point in the history
…w opening relative URLs

r18293
  • Loading branch information
barancev committed Dec 10, 2012
1 parent 9eaca55 commit eaa30a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private void setUpMethodMap() {
seleneseMethods.put("mouseUp", new MouseEvent(elementFinder, javascriptLibrary, "mouseup"));
seleneseMethods.put("mouseUpAt", new MouseEventAt(elementFinder, javascriptLibrary, "mouseup"));
seleneseMethods.put("open", new Open(baseUrl));
seleneseMethods.put("openWindow", new OpenWindow(new GetEval(scriptMutator)));
seleneseMethods.put("openWindow", new OpenWindow(baseUrl, new GetEval(scriptMutator)));
seleneseMethods.put("refresh", new Refresh());
seleneseMethods.put("removeAllSelections", new RemoveAllSelections(elementFinder));
seleneseMethods.put("removeSelection", new RemoveSelection(javascriptLibrary, elementFinder));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,40 @@

package org.openqa.selenium.internal.seleniumemulation;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebDriver;

import com.thoughtworks.selenium.SeleniumException;

public class OpenWindow extends SeleneseCommand<Void> {
private final URL baseUrl;
private final GetEval opener;

public OpenWindow(GetEval opener) {
public OpenWindow(String baseUrl, GetEval opener) {
try {
this.baseUrl = new URL(baseUrl);
} catch (MalformedURLException e) {
throw new SeleniumException(e.getMessage(), e);
}
this.opener = opener;
}

@Override
protected Void handleSeleneseCommand(final WebDriver driver, final String url,
final String windowID) {
String[] args = {String.format("window.open('%s', '%s'); null;", url, windowID)};
try {
final String urlToOpen = url.indexOf("://") == -1 ?
new URL(baseUrl, url).toString() :
url;

String[] args = {String.format("window.open('%s', '%s'); null;", urlToOpen, windowID)};

opener.apply(driver, args);
opener.apply(driver, args);
} catch (MalformedURLException e) {
throw new SeleniumException(e.getMessage(), e);
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.thoughtworks.selenium.corebased.TestFailingVerifications;
import com.thoughtworks.selenium.corebased.TestFramesClick;
import com.thoughtworks.selenium.corebased.TestFramesOpen;
import com.thoughtworks.selenium.corebased.TestFramesSpecialTargets;
import com.thoughtworks.selenium.corebased.TestFunkEventHandling;
import com.thoughtworks.selenium.corebased.TestGet;
import com.thoughtworks.selenium.corebased.TestGetTextContent;
Expand Down Expand Up @@ -109,7 +110,7 @@
// TestFramesClickJavascriptHref.class,
// TestFramesNested.class,
TestFramesOpen.class,
// TestFramesSpecialTargets.class,
TestFramesSpecialTargets.class,
TestFunkEventHandling.class,
TestGet.class,
TestGetTextContent.class,
Expand Down

0 comments on commit eaa30a5

Please sign in to comment.