diff --git a/java/client/src/org/openqa/selenium/htmlunit/AsyncScriptExecutor.java b/java/client/src/org/openqa/selenium/htmlunit/AsyncScriptExecutor.java index 746f8a70e7ec3..572e445d621fa 100644 --- a/java/client/src/org/openqa/selenium/htmlunit/AsyncScriptExecutor.java +++ b/java/client/src/org/openqa/selenium/htmlunit/AsyncScriptExecutor.java @@ -17,20 +17,21 @@ package org.openqa.selenium.htmlunit; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import net.sourceforge.htmlunit.corejs.javascript.Function; +import net.sourceforge.htmlunit.corejs.javascript.NativeJavaObject; + import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebDriverException; import com.gargoylesoftware.htmlunit.ScriptException; import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.html.HtmlPage; -import net.sourceforge.htmlunit.corejs.javascript.Function; -import net.sourceforge.htmlunit.corejs.javascript.NativeJavaObject; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; /** - * Injects an asynchronous script into the current page for execution. The script should signla that + * Injects an asynchronous script into the current page for execution. The script should signal that * it is finished by invoking the callback function, which will always be the last argument passed * to the injected script. */ diff --git a/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java b/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java index 29b6d10d14c4d..bd835292f1244 100755 --- a/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java +++ b/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java @@ -19,44 +19,20 @@ import static org.openqa.selenium.remote.CapabilityType.SUPPORTS_FINDING_BY_CSS; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; +import java.io.IOException; +import java.net.ConnectException; +import java.net.SocketTimeoutException; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; -import com.gargoylesoftware.htmlunit.BrowserVersion; -import com.gargoylesoftware.htmlunit.CookieManager; -import com.gargoylesoftware.htmlunit.ElementNotFoundException; -import com.gargoylesoftware.htmlunit.Page; -import com.gargoylesoftware.htmlunit.ProxyConfig; -import com.gargoylesoftware.htmlunit.ScriptResult; -import com.gargoylesoftware.htmlunit.SgmlPage; -import com.gargoylesoftware.htmlunit.StringWebResponse; -import com.gargoylesoftware.htmlunit.TopLevelWindow; -import com.gargoylesoftware.htmlunit.UnexpectedPage; -import com.gargoylesoftware.htmlunit.Version; -import com.gargoylesoftware.htmlunit.WaitingRefreshHandler; -import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.WebClientOptions; -import com.gargoylesoftware.htmlunit.WebResponse; -import com.gargoylesoftware.htmlunit.WebWindow; -import com.gargoylesoftware.htmlunit.WebWindowEvent; -import com.gargoylesoftware.htmlunit.WebWindowListener; -import com.gargoylesoftware.htmlunit.WebWindowNotFoundException; -import com.gargoylesoftware.htmlunit.html.BaseFrameElement; -import com.gargoylesoftware.htmlunit.html.DomElement; -import com.gargoylesoftware.htmlunit.html.DomNode; -import com.gargoylesoftware.htmlunit.html.DomNodeList; -import com.gargoylesoftware.htmlunit.html.FrameWindow; -import com.gargoylesoftware.htmlunit.html.HtmlAnchor; -import com.gargoylesoftware.htmlunit.html.HtmlElement; -import com.gargoylesoftware.htmlunit.html.HtmlHtml; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.javascript.host.Element; -import com.gargoylesoftware.htmlunit.javascript.host.Location; -import com.gargoylesoftware.htmlunit.javascript.host.html.DocumentProxy; -import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection; -import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.ContextAction; @@ -108,19 +84,43 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.io.IOException; -import java.net.ConnectException; -import java.net.SocketTimeoutException; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeUnit; +import com.gargoylesoftware.htmlunit.BrowserVersion; +import com.gargoylesoftware.htmlunit.CookieManager; +import com.gargoylesoftware.htmlunit.ElementNotFoundException; +import com.gargoylesoftware.htmlunit.Page; +import com.gargoylesoftware.htmlunit.ProxyConfig; +import com.gargoylesoftware.htmlunit.ScriptResult; +import com.gargoylesoftware.htmlunit.SgmlPage; +import com.gargoylesoftware.htmlunit.StringWebResponse; +import com.gargoylesoftware.htmlunit.TopLevelWindow; +import com.gargoylesoftware.htmlunit.UnexpectedPage; +import com.gargoylesoftware.htmlunit.Version; +import com.gargoylesoftware.htmlunit.WaitingRefreshHandler; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.WebClientOptions; +import com.gargoylesoftware.htmlunit.WebResponse; +import com.gargoylesoftware.htmlunit.WebWindow; +import com.gargoylesoftware.htmlunit.WebWindowEvent; +import com.gargoylesoftware.htmlunit.WebWindowListener; +import com.gargoylesoftware.htmlunit.WebWindowNotFoundException; +import com.gargoylesoftware.htmlunit.html.BaseFrameElement; +import com.gargoylesoftware.htmlunit.html.DomElement; +import com.gargoylesoftware.htmlunit.html.DomNode; +import com.gargoylesoftware.htmlunit.html.DomNodeList; +import com.gargoylesoftware.htmlunit.html.FrameWindow; +import com.gargoylesoftware.htmlunit.html.HtmlAnchor; +import com.gargoylesoftware.htmlunit.html.HtmlElement; +import com.gargoylesoftware.htmlunit.html.HtmlHtml; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.javascript.host.Element; +import com.gargoylesoftware.htmlunit.javascript.host.Location; +import com.gargoylesoftware.htmlunit.javascript.host.html.DocumentProxy; +import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection; +import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; +import com.google.common.collect.Collections2; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; public class HtmlUnitDriver implements WebDriver, JavascriptExecutor, FindsById, FindsByLinkText, FindsByXPath, FindsByName, FindsByCssSelector, @@ -151,10 +151,12 @@ public HtmlUnitDriver(BrowserVersion version) { initialWindowDimension = new Dimension(currentWindow.getOuterWidth(), currentWindow.getOuterHeight()); webClient.addWebWindowListener(new WebWindowListener() { + @Override public void webWindowOpened(WebWindowEvent webWindowEvent) { // Ignore } + @Override public void webWindowContentChanged(WebWindowEvent event) { if (event.getWebWindow() != currentWindow) { return; @@ -164,6 +166,7 @@ public void webWindowContentChanged(WebWindowEvent event) { switchToDefaultContentOfWindow(currentWindow); } + @Override public void webWindowClosed(WebWindowEvent event) { // Check if the event window refers to us or one of our parent windows // setup the currentWindow appropriately if necessary @@ -437,6 +440,7 @@ public void setAutoProxy(String autoProxyUrl) { getWebClient().getOptions().setProxyConfig(proxyConfig); } + @Override public Capabilities getCapabilities() { DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit(); @@ -448,6 +452,7 @@ public Capabilities getCapabilities() { return capabilities; } + @Override public void get(String url) { // Prevent the malformed url exception. if (WebClient.URL_ABOUT_BLANK.toString().equals(url)) { @@ -506,6 +511,7 @@ protected void pickWindow() { } } + @Override public String getCurrentUrl() { // TODO(simon): Blech. I can see this being baaad URL url = getRawUrl(); @@ -516,6 +522,7 @@ public String getCurrentUrl() { return url.toString(); } + @Override public String getTitle() { Page page = lastPage(); if (page == null || !(page instanceof HtmlPage)) { @@ -528,14 +535,17 @@ public String getTitle() { return ((HtmlPage) page).getTitleText(); } + @Override public WebElement findElement(By by) { return findElement(by, this); } + @Override public List findElements(By by) { return findElements(by, this); } + @Override public String getPageSource() { Page page = lastPage(); if (page == null) { @@ -549,6 +559,7 @@ public String getPageSource() { return response.getContentAsString(); } + @Override public void close() { getWebClient(); // check that session is active WebWindow thisWindow = getCurrentWindow(); // check that the current window is active @@ -566,6 +577,7 @@ public void close() { } } + @Override public void quit() { if (webClient != null) { webClient.closeAllWindows(); @@ -574,6 +586,7 @@ public void quit() { currentWindow = null; } + @Override public Set getWindowHandles() { final Set allHandles = Sets.newHashSet(); for (final WebWindow window : getWebClient().getTopLevelWindows()) { @@ -583,6 +596,7 @@ public Set getWindowHandles() { return allHandles; } + @Override public String getWindowHandle() { WebWindow topWindow = getCurrentWindow().getTopWindow(); if (topWindow.isClosed()) { @@ -591,6 +605,7 @@ public String getWindowHandle() { return String.valueOf(System.identityHashCode(topWindow)); } + @Override public Object executeScript(String script, final Object... args) { HtmlPage page = getPageToInjectScriptInto(); @@ -613,6 +628,7 @@ public Object executeScript(String script, final Object... args) { return parseNativeJavascriptResult(result); } + @Override public Object executeAsyncScript(String script, Object... args) { HtmlPage page = getPageToInjectScriptInto(); args = convertScriptArgs(page, args); @@ -628,6 +644,7 @@ private Object[] convertScriptArgs(HtmlPage page, final Object[] args) { final Object[] parameters = new Object[args.length]; final ContextAction action = new ContextAction() { + @Override public Object run(final Context context) { for (int i = 0; i < args.length; i++) { parameters[i] = parseArgumentIntoJavascriptParameter(context, scope, args[i]); @@ -737,10 +754,12 @@ protected void assertElementNotStale(HtmlElement element) { } } + @Override public Keyboard getKeyboard() { return keyboard; } + @Override public Mouse getMouse() { return mouse; } @@ -788,17 +807,19 @@ private Object parseNativeJavascriptResult(Object result) { } if (value instanceof Location) { - return convertLocationtoMap((Location) value); + return convertLocationToMap((Location) value); } if (value instanceof NativeArray) { final NativeArray array = (NativeArray) value; JavaScriptResultsCollection collection = new JavaScriptResultsCollection() { + @Override public int getLength() { return (int) array.getLength(); } + @Override public Object item(int index) { return array.get(index); } @@ -811,10 +832,12 @@ public Object item(int index) { final HTMLCollection array = (HTMLCollection) value; JavaScriptResultsCollection collection = new JavaScriptResultsCollection() { + @Override public int getLength() { return array.getLength(); } + @Override public Object item(int index) { return array.get(index); } @@ -830,7 +853,7 @@ public Object item(int index) { return value; } - private Map convertLocationtoMap(Location location) { + private Map convertLocationToMap(Location location) { Map map = Maps.newHashMap(); map.put("href", location.getHref()); map.put("protocol", location.getProtocol()); @@ -852,6 +875,7 @@ private List parseJavascriptResultsList(JavaScriptResultsCollection arra return list; } + @Override public TargetLocator switchTo() { return new HtmlUnitTargetLocator(); } @@ -863,6 +887,7 @@ private void switchToDefaultContentOfWindow(WebWindow window) { } } + @Override public Navigation navigate() { return new HtmlUnitNavigation(); } @@ -872,6 +897,7 @@ protected Page lastPage() { return getCurrentWindow().getEnclosedPage(); } + @Override public WebElement findElementByLinkText(String selector) { if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Cannot find links for " + lastPage()); @@ -892,6 +918,7 @@ protected WebElement newHtmlUnitWebElement(HtmlElement element) { return new HtmlUnitWebElement(this, element); } + @Override public List findElementsByLinkText(String selector) { List elements = new ArrayList(); @@ -910,6 +937,7 @@ public List findElementsByLinkText(String selector) { return elements; } + @Override public WebElement findElementById(String id) { if (!(lastPage() instanceof HtmlPage)) { throw new NoSuchElementException("Unable to locate element by id for " + lastPage()); @@ -923,6 +951,7 @@ public WebElement findElementById(String id) { } } + @Override public List findElementsById(String id) { return findElementsByXPath("//*[@id='" + id + "']"); } @@ -943,6 +972,7 @@ public List findElementsByClassName(String className) { return findElementsByCssSelector("." + className); } + @Override public WebElement findElementByCssSelector(String using) { if (!(lastPage() instanceof HtmlPage)) { throw new NoSuchElementException("Unable to locate element using css: " + lastPage()); @@ -962,6 +992,7 @@ public WebElement findElementByCssSelector(String using) { throw new NoSuchElementException("Returned node was not an HTML element"); } + @Override public List findElementsByCssSelector(String using) { if (!(lastPage() instanceof HtmlPage)) { throw new NoSuchElementException("Unable to locate element using css: " + lastPage()); @@ -988,6 +1019,7 @@ public List findElementsByCssSelector(String using) { return toReturn; } + @Override public WebElement findElementByName(String name) { if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Unable to locate element by name for " + lastPage()); @@ -1001,6 +1033,7 @@ public WebElement findElementByName(String name) { throw new NoSuchElementException("Unable to locate element with name: " + name); } + @Override public List findElementsByName(String using) { if (!(lastPage() instanceof HtmlPage)) { return new ArrayList(); @@ -1010,6 +1043,7 @@ public List findElementsByName(String using) { return convertRawHtmlElementsToWebElements(allElements); } + @Override public WebElement findElementByTagName(String name) { if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Unable to locate element by name for " + lastPage()); @@ -1023,6 +1057,7 @@ public WebElement findElementByTagName(String name) { throw new NoSuchElementException("Unable to locate element with name: " + name); } + @Override public List findElementsByTagName(String using) { if (!(lastPage() instanceof HtmlPage)) { return new ArrayList(); @@ -1039,6 +1074,7 @@ public List findElementsByTagName(String using) { return toReturn; } + @Override public WebElement findElementByXPath(String selector) { if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Unable to locate element by xpath for " + lastPage()); @@ -1065,6 +1101,7 @@ public WebElement findElementByXPath(String selector) { String.format(INVALIDSELECTIONERROR, selector, node.getClass())); } + @Override public List findElementsByXPath(String selector) { if (!(lastPage() instanceof HtmlPage)) { return new ArrayList(); @@ -1121,6 +1158,7 @@ public void setJavascriptEnabled(boolean enableJavascript) { private class HtmlUnitTargetLocator implements TargetLocator { + @Override public WebDriver frame(int index) { Page page = lastPage(); if (page instanceof HtmlPage) { @@ -1133,6 +1171,7 @@ public WebDriver frame(int index) { return HtmlUnitDriver.this; } + @Override public WebDriver frame(final String nameOrId) { Page page = lastPage(); if (page instanceof HtmlPage) { @@ -1163,6 +1202,7 @@ public WebDriver frame(final String nameOrId) { throw new NoSuchFrameException("Unable to locate frame with name or ID: " + nameOrId); } + @Override public WebDriver frame(WebElement frameElement) { while (frameElement instanceof WrapsElement) { frameElement = ((WrapsElement) frameElement).getWrappedElement(); @@ -1180,11 +1220,13 @@ public WebDriver frame(WebElement frameElement) { return HtmlUnitDriver.this; } + @Override public WebDriver parentFrame() { currentWindow = currentWindow.getParentWindow(); return HtmlUnitDriver.this; } + @Override public WebDriver window(String windowId) { try { WebWindow window = getWebClient().getWebWindowByName(windowId); @@ -1209,11 +1251,13 @@ private WebDriver finishSelecting(WebWindow window) { return HtmlUnitDriver.this; } + @Override public WebDriver defaultContent() { switchToDefaultContentOfWindow(getCurrentWindow().getTopWindow()); return HtmlUnitDriver.this; } + @Override public WebElement activeElement() { Page page = lastPage(); if (page instanceof HtmlPage) { @@ -1232,13 +1276,10 @@ public WebElement activeElement() { throw new NoSuchElementException("Unable to locate element with focus or body tag"); } + @Override public Alert alert() { throw new UnsupportedOperationException("alert()"); } - - public WebDriver context(String name) { - throw new UnsupportedOperationException("context(String)"); - } } protected X implicitlyWaitFor(Callable condition) { @@ -1300,6 +1341,7 @@ private URL getRawUrl() { private class HtmlUnitNavigation implements Navigation { + @Override public void back() { try { getCurrentWindow().getHistory().back(); @@ -1308,6 +1350,7 @@ public void back() { } } + @Override public void forward() { try { getCurrentWindow().getHistory().forward(); @@ -1316,15 +1359,17 @@ public void forward() { } } - + @Override public void to(String url) { get(url); } + @Override public void to(URL url) { get(url); } + @Override public void refresh() { if (lastPage() instanceof HtmlPage) { try { @@ -1338,16 +1383,19 @@ public void refresh() { } } + @Override public Options manage() { return new HtmlUnitOptions(); } private class HtmlUnitOptions implements Options { + @Override public Logs logs() { throw new UnsupportedOperationException("Driver does not support this operation."); } + @Override public void addCookie(Cookie cookie) { Page page = lastPage(); if (!(page instanceof HtmlPage)) { @@ -1390,6 +1438,7 @@ private void verifyDomain(Cookie cookie, String expectedDomain) { } } + @Override public Cookie getCookieNamed(String name) { Set allCookies = getCookies(); for (Cookie cookie : allCookies) { @@ -1401,6 +1450,7 @@ public Cookie getCookieNamed(String name) { return null; } + @Override public void deleteCookieNamed(String name) { CookieManager cookieManager = getWebClient().getCookieManager(); @@ -1413,14 +1463,17 @@ public void deleteCookieNamed(String name) { } } + @Override public void deleteCookie(Cookie cookie) { getWebClient().getCookieManager().removeCookie(convertSeleniumCookieToHtmlUnit(cookie)); } + @Override public void deleteAllCookies() { getWebClient().getCookieManager().clearCookies(); } + @Override public Set getCookies() { URL url = getRawUrl(); @@ -1451,6 +1504,7 @@ private com.gargoylesoftware.htmlunit.util.Cookie convertSeleniumCookieToHtmlUni private final com.google.common.base.Function htmlUnitCookieToSeleniumCookieTransformer = new com.google.common.base.Function() { + @Override public org.openqa.selenium.Cookie apply(com.gargoylesoftware.htmlunit.util.Cookie c) { return new Cookie.Builder(c.getName(), c.getValue()) .domain(c.getDomain()) @@ -1466,14 +1520,17 @@ private String getDomainForCookie() { return current.getHost(); } + @Override public Timeouts timeouts() { return new HtmlUnitTimeouts(); } + @Override public ImeHandler ime() { throw new UnsupportedOperationException("Cannot input IME using HtmlUnit."); } + @Override public Window window() { return new HtmlUnitWindow(); } @@ -1481,17 +1538,21 @@ public Window window() { } class HtmlUnitTimeouts implements Timeouts { + + @Override public Timeouts implicitlyWait(long time, TimeUnit unit) { HtmlUnitDriver.this.implicitWait = TimeUnit.MILLISECONDS.convert(Math.max(0, time), unit); return this; } + @Override public Timeouts setScriptTimeout(long time, TimeUnit unit) { HtmlUnitDriver.this.scriptTimeout = TimeUnit.MILLISECONDS.convert(time, unit); return this; } + @Override public Timeouts pageLoadTimeout(long time, TimeUnit unit) { int timeout = (int) TimeUnit.MILLISECONDS.convert(time, unit); getWebClient().getOptions().setTimeout(timeout > 0 ? timeout : 0); @@ -1542,6 +1603,7 @@ public void maximize() { } } + @Override public WebElement findElementByPartialLinkText(String using) { if (!(lastPage() instanceof HtmlPage)) { throw new IllegalStateException("Cannot find links for " + lastPage()); @@ -1556,8 +1618,8 @@ public WebElement findElementByPartialLinkText(String using) { throw new NoSuchElementException("No link found with text: " + using); } + @Override public List findElementsByPartialLinkText(String using) { - List anchors = ((HtmlPage) lastPage()).getAnchors(); List elements = new ArrayList(); for (HtmlAnchor anchor : anchors) { @@ -1571,6 +1633,7 @@ public List findElementsByPartialLinkText(String using) { WebElement findElement(final By locator, final SearchContext context) { return implicitlyWaitFor(new Callable() { + @Override public WebElement call() throws Exception { return locator.findElement(context); } diff --git a/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitKeyboard.java b/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitKeyboard.java index f2a961c3daf8f..d9567370f091c 100644 --- a/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitKeyboard.java +++ b/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitKeyboard.java @@ -16,9 +16,12 @@ package org.openqa.selenium.htmlunit; +import java.io.IOException; + import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Keyboard; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlFileInput; @@ -27,13 +30,11 @@ import com.gargoylesoftware.htmlunit.javascript.host.Event; import com.gargoylesoftware.htmlunit.javascript.host.KeyboardEvent; -import java.io.IOException; - /** * Implements keyboard operations using the HtmlUnit WebDriver. * */ -public class HtmlUnitKeyboard implements org.openqa.selenium.interactions.Keyboard { +public class HtmlUnitKeyboard implements Keyboard { private KeyboardModifiersState modifiersState = new KeyboardModifiersState(); private final HtmlUnitDriver parent; @@ -50,6 +51,7 @@ private HtmlUnitWebElement getElementToSend(WebElement toElement) { return (HtmlUnitWebElement) sendToElement; } + @Override public void sendKeys(CharSequence... keysToSend) { WebElement toElement = parent.switchTo().activeElement(); @@ -84,6 +86,7 @@ public void sendKeys(HtmlElement element, String currentValue, InputKeysContaine } } + @Override public void pressKey(CharSequence keyToPress) { WebElement toElement = parent.switchTo().activeElement(); @@ -92,6 +95,7 @@ public void pressKey(CharSequence keyToPress) { htmlElement.sendKeyDownEvent(keyToPress); } + @Override public void releaseKey(CharSequence keyToRelease) { WebElement toElement = parent.switchTo().activeElement(); diff --git a/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitMouse.java b/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitMouse.java index d460681b68107..44567dc6796bd 100644 --- a/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitMouse.java +++ b/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitMouse.java @@ -16,24 +16,24 @@ package org.openqa.selenium.htmlunit; -import com.google.common.base.Preconditions; +import java.io.IOException; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.interactions.InvalidCoordinatesException; +import org.openqa.selenium.interactions.Mouse; import org.openqa.selenium.interactions.internal.Coordinates; import com.gargoylesoftware.htmlunit.ScriptException; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.javascript.host.MouseEvent; - -import java.io.IOException; +import com.google.common.base.Preconditions; /** * Implements mouse operations using the HtmlUnit WebDriver. * */ -public class HtmlUnitMouse implements org.openqa.selenium.interactions.Mouse { +public class HtmlUnitMouse implements Mouse { private final HtmlUnitDriver parent; private final HtmlUnitKeyboard keyboard; private HtmlElement currentActiveElement = null; @@ -56,7 +56,7 @@ private HtmlElement getElementForOperation(Coordinates potentialCoordinates) { return currentActiveElement; } - + @Override public void click(Coordinates elementCoordinates) { HtmlElement element = getElementForOperation(elementCoordinates); @@ -116,6 +116,7 @@ public void click(Coordinates where, long xOffset, long yOffset) { click(where); } + @Override public void doubleClick(Coordinates elementCoordinates) { HtmlElement element = getElementForOperation(elementCoordinates); @@ -132,6 +133,7 @@ public void doubleClick(Coordinates elementCoordinates) { } } + @Override public void contextClick(Coordinates elementCoordinates) { HtmlElement element = getElementForOperation(elementCoordinates); @@ -143,6 +145,7 @@ public void contextClick(Coordinates elementCoordinates) { updateActiveElement(element); } + @Override public void mouseDown(Coordinates elementCoordinates) { HtmlElement element = getElementForOperation(elementCoordinates); @@ -155,6 +158,7 @@ public void mouseDown(Coordinates elementCoordinates) { updateActiveElement(element); } + @Override public void mouseUp(Coordinates elementCoordinates) { HtmlElement element = getElementForOperation(elementCoordinates); @@ -167,6 +171,7 @@ public void mouseUp(Coordinates elementCoordinates) { updateActiveElement(element); } + @Override public void mouseMove(Coordinates elementCoordinates) { Preconditions.checkNotNull(elementCoordinates); HtmlElement element = (HtmlElement) elementCoordinates.getAuxiliary(); @@ -185,7 +190,7 @@ private void mouseMove(HtmlElement element) { MouseEvent.BUTTON_LEFT); } - + @Override public void mouseMove(Coordinates where, long xOffset, long yOffset) { throw new UnsupportedOperationException("Moving to arbitrary X,Y coordinates not supported."); } diff --git a/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitWebElement.java b/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitWebElement.java index 2ccfda624fca0..3d7d6eec95e10 100644 --- a/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitWebElement.java +++ b/java/client/src/org/openqa/selenium/htmlunit/HtmlUnitWebElement.java @@ -18,14 +18,20 @@ package org.openqa.selenium.htmlunit; -import com.google.common.base.Throwables; +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.Callable; + +import net.sourceforge.htmlunit.corejs.javascript.Undefined; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.ElementNotVisibleException; import org.openqa.selenium.InvalidElementStateException; import org.openqa.selenium.InvalidSelectorException; -import org.openqa.selenium.Keys; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.Point; import org.openqa.selenium.StaleElementReferenceException; @@ -41,6 +47,8 @@ import org.openqa.selenium.internal.Locatable; import org.openqa.selenium.internal.WrapsDriver; import org.openqa.selenium.internal.WrapsElement; +import org.w3c.dom.Attr; +import org.w3c.dom.NamedNodeMap; import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.html.DomElement; @@ -61,16 +69,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import com.gargoylesoftware.htmlunit.html.HtmlTextArea; import com.gargoylesoftware.htmlunit.javascript.host.Event; -import net.sourceforge.htmlunit.corejs.javascript.Undefined; -import org.w3c.dom.Attr; -import org.w3c.dom.NamedNodeMap; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.Callable; +import com.google.common.base.Throwables; public class HtmlUnitWebElement implements WrapsDriver, @@ -134,6 +133,7 @@ public HtmlUnitWebElement(HtmlUnitDriver parent, HtmlElement element) { this.element = element; } + @Override public void click() { try { verifyCanInteractWithElement(); @@ -166,6 +166,7 @@ public void click() { } + @Override public void submit() { try { if (element instanceof HtmlForm) { @@ -219,9 +220,8 @@ private void submitForm(HtmlForm form) { parent.executeScript("arguments[0].submit()", form); } return; - } else { - throw new WebDriverException("Cannot locate element used to submit form"); } + throw new WebDriverException("Cannot locate element used to submit form"); } try { submit.click(); @@ -251,6 +251,7 @@ private boolean isBefore(HtmlElement submit) { return submit == null; } + @Override public void clear() { assertElementNotStale(); @@ -281,6 +282,7 @@ private void verifyCanInteractWithElement() { assertElementNotStale(); Boolean displayed = parent.implicitlyWaitFor(new Callable() { + @Override public Boolean call() throws Exception { return isDisplayed(); } @@ -335,6 +337,7 @@ private void sendSingleKeyEvent(CharSequence modifierKey, String eventDescriptio keyboard.performSingleKeyAction(getElement(), modifierKey, eventDescription); } + @Override public void sendKeys(CharSequence... value) { verifyCanInteractWithElement(); @@ -354,11 +357,13 @@ private boolean isInputElement() { return element instanceof HtmlInput; } + @Override public String getTagName() { assertElementNotStale(); return element.getNodeName(); } + @Override public String getAttribute(String name) { assertElementNotStale(); @@ -456,6 +461,7 @@ private String trueOrNull(boolean condition) { return condition ? "true" : null; } + @Override public boolean isSelected() { assertElementNotStale(); @@ -469,12 +475,14 @@ public boolean isSelected() { "Unable to determine if element is selected. Tag name is: " + element.getTagName()); } + @Override public boolean isEnabled() { assertElementNotStale(); return !element.hasAttribute("disabled"); } + @Override public boolean isDisplayed() { assertElementNotStale(); @@ -485,6 +493,7 @@ public boolean isDisplayed() { return !(element instanceof HtmlHiddenInput) && element.isDisplayed(); } + @Override public Point getLocation() { assertElementNotStale(); @@ -495,6 +504,7 @@ public Point getLocation() { } } + @Override public Dimension getSize() { assertElementNotStale(); @@ -516,6 +526,7 @@ private int readAndRound(final String property) { } // This isn't very pretty. Sorry. + @Override public String getText() { assertElementNotStale(); @@ -637,34 +648,40 @@ public List getElementsByTagName(String tagName) { return elements; } + @Override public WebElement findElement(By by) { assertElementNotStale(); return parent.findElement(by, this); } + @Override public List findElements(By by) { assertElementNotStale(); return parent.findElements(by, this); } + @Override public WebElement findElementById(String id) { assertElementNotStale(); return findElementByXPath(".//*[@id = '" + id + "']"); } + @Override public List findElementsById(String id) { assertElementNotStale(); return findElementsByXPath(".//*[@id = '" + id + "']"); } + @Override public List findElementsByCssSelector(String using) { List allElements = parent.findElementsByCssSelector(using); return findChildNodes(allElements); } + @Override public WebElement findElementByCssSelector(String using) { List allElements = parent.findElementsByCssSelector(using); @@ -690,6 +707,7 @@ private List findChildNodes(List allElements) { return toReturn; } + @Override public WebElement findElementByXPath(String xpathExpr) { assertElementNotStale(); @@ -714,6 +732,7 @@ public WebElement findElementByXPath(String xpathExpr) { String.format(HtmlUnitDriver.INVALIDSELECTIONERROR, xpathExpr, node.getClass().toString())); } + @Override public List findElementsByXPath(String xpathExpr) { assertElementNotStale(); @@ -743,6 +762,7 @@ public List findElementsByXPath(String xpathExpr) { return webElements; } + @Override public WebElement findElementByLinkText(String linkText) { assertElementNotStale(); @@ -753,6 +773,7 @@ public WebElement findElementByLinkText(String linkText) { return elements.get(0); } + @Override public List findElementsByLinkText(String linkText) { assertElementNotStale(); @@ -767,6 +788,7 @@ public List findElementsByLinkText(String linkText) { return webElements; } + @Override public WebElement findElementByPartialLinkText(String linkText) { assertElementNotStale(); @@ -778,6 +800,7 @@ public WebElement findElementByPartialLinkText(String linkText) { return elements.size() > 0 ? elements.get(0) : null; } + @Override public List findElementsByPartialLinkText(String linkText) { assertElementNotStale(); @@ -792,6 +815,7 @@ public List findElementsByPartialLinkText(String linkText) { return webElements; } + @Override public WebElement findElementByTagName(String name) { assertElementNotStale(); @@ -802,6 +826,7 @@ public WebElement findElementByTagName(String name) { return elements.get(0); } + @Override public List findElementsByTagName(String name) { assertElementNotStale(); @@ -848,6 +873,7 @@ protected void assertElementNotStale() { parent.assertElementNotStale(element); } + @Override public String getCssValue(String propertyName) { assertElementNotStale(); @@ -918,25 +944,31 @@ public int hashCode() { * * @see org.openqa.selenium.internal.WrapsDriver#getContainingDriver() */ + @Override public WebDriver getWrappedDriver() { return parent; } + @Override public Coordinates getCoordinates() { return new Coordinates() { + @Override public Point onScreen() { throw new UnsupportedOperationException("Not displayed, no screen location."); } + @Override public Point inViewPort() { return getLocation(); } + @Override public Point onPage() { return getLocation(); } + @Override public Object getAuxiliary() { return getElement(); } diff --git a/java/client/src/org/openqa/selenium/htmlunit/InputKeysContainer.java b/java/client/src/org/openqa/selenium/htmlunit/InputKeysContainer.java index a1cf8cf99b74a..afa9b2c60fc87 100644 --- a/java/client/src/org/openqa/selenium/htmlunit/InputKeysContainer.java +++ b/java/client/src/org/openqa/selenium/htmlunit/InputKeysContainer.java @@ -62,7 +62,6 @@ private int indexOfSubmitKey() { return -1; } - @Override public String toString() { String toReturn = builder.toString();