diff --git a/build.gradle b/build.gradle index 8b7011386..33991f2c6 100644 --- a/build.gradle +++ b/build.gradle @@ -54,13 +54,12 @@ compileJava { } dependencies { - compile('org.seleniumhq.selenium:selenium-java:3.0.1'){ + compile('org.seleniumhq.selenium:selenium-java:3.2.0'){ exclude module: 'cglib' exclude group: 'com.google.code.gson' } compile 'com.google.code.gson:gson:2.8.0' compile 'org.apache.httpcomponents:httpclient:4.5.2' - compile 'com.google.guava:guava:20.0' compile 'cglib:cglib:3.2.4' compile 'commons-validator:commons-validator:1.5.1' compile 'org.apache.commons:commons-lang3:3.5' diff --git a/src/main/java/io/appium/java_client/events/DefaultAspect.java b/src/main/java/io/appium/java_client/events/DefaultAspect.java index 026ab5dfb..b7184b841 100644 --- a/src/main/java/io/appium/java_client/events/DefaultAspect.java +++ b/src/main/java/io/appium/java_client/events/DefaultAspect.java @@ -352,6 +352,7 @@ public void afterScript(JoinPoint joinPoint) throws Throwable { public void beforeAlertAccept(JoinPoint joinPoint) throws Throwable { try { listener.beforeAlertAccept(driver, castTarget(joinPoint)); + listener.beforeAlertAccept(driver); } catch (Throwable t) { throw getRootCause(t); } @@ -361,6 +362,7 @@ public void beforeAlertAccept(JoinPoint joinPoint) throws Throwable { public void afterAlertAccept(JoinPoint joinPoint) throws Throwable { try { listener.afterAlertAccept(driver, castTarget(joinPoint)); + listener.afterAlertAccept(driver); } catch (Throwable t) { throw getRootCause(t); } @@ -370,6 +372,7 @@ public void afterAlertAccept(JoinPoint joinPoint) throws Throwable { public void beforeAlertDismiss(JoinPoint joinPoint) throws Throwable { try { listener.beforeAlertDismiss(driver, castTarget(joinPoint)); + listener.beforeAlertDismiss(driver); } catch (Throwable t) { throw getRootCause(t); } @@ -379,6 +382,7 @@ public void beforeAlertDismiss(JoinPoint joinPoint) throws Throwable { public void afterAlertDismiss(JoinPoint joinPoint) throws Throwable { try { listener.afterAlertDismiss(driver, castTarget(joinPoint)); + listener.afterAlertDismiss(driver); } catch (Throwable t) { throw getRootCause(t); } diff --git a/src/main/java/io/appium/java_client/events/DefaultListener.java b/src/main/java/io/appium/java_client/events/DefaultListener.java index c42e6cb4d..8a7893d77 100644 --- a/src/main/java/io/appium/java_client/events/DefaultListener.java +++ b/src/main/java/io/appium/java_client/events/DefaultListener.java @@ -142,18 +142,38 @@ public void add(Collection listeners) { ((AlertEventListener) dispatcher).beforeAlertAccept(driver, alert); } + @Override + public void beforeAlertAccept(WebDriver driver) { + ((WebDriverEventListener) dispatcher).beforeAlertAccept(driver); + } + @Override public void afterAlertAccept(WebDriver driver, Alert alert) { ((AlertEventListener) dispatcher).afterAlertAccept(driver, alert); } + @Override + public void afterAlertAccept(WebDriver driver) { + ((WebDriverEventListener) dispatcher).afterAlertAccept(driver); + } + @Override public void afterAlertDismiss(WebDriver driver, Alert alert) { ((AlertEventListener) dispatcher).afterAlertDismiss(driver, alert); } + @Override + public void afterAlertDismiss(WebDriver driver) { + ((WebDriverEventListener) dispatcher).afterAlertDismiss(driver); + } + @Override public void beforeAlertDismiss(WebDriver driver, Alert alert) { ((AlertEventListener) dispatcher).beforeAlertDismiss(driver, alert); } + @Override + public void beforeAlertDismiss(WebDriver driver) { + ((WebDriverEventListener) dispatcher).beforeAlertDismiss(driver); + } + @Override public void beforeAlertSendKeys(WebDriver driver, Alert alert, String keys) { ((AlertEventListener) dispatcher).beforeAlertSendKeys(driver, alert, keys); } diff --git a/src/main/java/org/openqa/selenium/WebDriver.java b/src/main/java/org/openqa/selenium/WebDriver.java index dde47d84b..08de94859 100644 --- a/src/main/java/org/openqa/selenium/WebDriver.java +++ b/src/main/java/org/openqa/selenium/WebDriver.java @@ -17,8 +17,8 @@ package org.openqa.selenium; -import org.openqa.selenium.logging.Logs; import org.openqa.selenium.logging.LoggingPreferences; +import org.openqa.selenium.logging.Logs; import java.net.URL; import java.util.List; @@ -75,7 +75,7 @@ public interface WebDriver extends SearchContext { * The title of the current page. * * @return The title of the current page, with leading and trailing whitespace stripped, or null - * if one is not already set + * if one is not already set */ String getTitle(); @@ -98,7 +98,7 @@ public interface WebDriver extends SearchContext { * This method is affected by the 'implicit wait' times in force at the time of execution. * The findElement(..) invocation will return a matching row, or try again repeatedly until * the configured timeout is reached. - *

+ * * findElement should not be used to look for non-present elements, use {@link #findElements(By)} * and assert zero length response instead. * @@ -164,7 +164,7 @@ public interface WebDriver extends SearchContext { * URL. * * @return A {@link org.openqa.selenium.WebDriver.Navigation} that allows the selection of what to - * do next + * do next */ Navigation navigate(); @@ -242,7 +242,7 @@ interface Options { /** * Gets the {@link Logs} interface used to fetch different types of logs. - *

+ * *

To set the logging preferences {@link LoggingPreferences}. * * @return A Logs interface. @@ -318,7 +318,7 @@ interface TargetLocator { * precedence over those matched by ID. * * @param nameOrId the name of the frame window, the id of the <frame> or <iframe> - * element, or the (zero-based) index + * element, or the (zero-based) index * @return This driver focused on the given frame * @throws NoSuchFrameException If the frame cannot be found */ @@ -329,7 +329,7 @@ interface TargetLocator { * * @param frameElement The frame element to switch to. * @return This driver focused on the given frame. - * @throws NoSuchFrameException If the given element is neither an IFRAME nor a FRAME element. + * @throws NoSuchFrameException If the given element is neither an IFRAME nor a FRAME element. * @throws StaleElementReferenceException If the WebElement has gone stale. * @see WebDriver#findElement(By) */ @@ -347,7 +347,7 @@ interface TargetLocator { * Switch the focus of future commands for this driver to the window with the given name/handle. * * @param nameOrHandle The name of the window or the handle as returned by - * {@link WebDriver#getWindowHandle()} + * {@link WebDriver#getWindowHandle()} * @return This driver focused on the given window * @throws NoSuchWindowException If the window cannot be found */ @@ -367,7 +367,7 @@ interface TargetLocator { * "document.activeElement" in Javascript. * * @return The WebElement with focus, or the body element if no element with focus can be - * detected. + * detected. */ WebElement activeElement(); @@ -461,10 +461,11 @@ interface ImeHandler { * platform-independent method of activating IME (the platform-specific way being using keyboard * shortcuts). * + * * @param engine name of engine to activate. - * @throws ImeNotAvailableException if the host does not support IME. + * @throws ImeNotAvailableException if the host does not support IME. * @throws ImeActivationFailedException if the engine is not available or if activation failed - * for other reasons. + * for other reasons. */ void activateEngine(String engine); } @@ -512,4 +513,4 @@ interface Window { */ void fullscreen(); } -} +} \ No newline at end of file diff --git a/src/main/java/org/openqa/selenium/WebElement.java b/src/main/java/org/openqa/selenium/WebElement.java index c8a01a5be..1aa2da524 100644 --- a/src/main/java/org/openqa/selenium/WebElement.java +++ b/src/main/java/org/openqa/selenium/WebElement.java @@ -34,19 +34,18 @@ public interface WebElement extends SearchContext, TakesScreenshot { * should discard all references to this element and any further * operations performed on this element will throw a * StaleElementReferenceException. - *

+ * * Note that if click() is done by sending a native event (which is * the default on most browsers/platforms) then the method will * _not_ wait for the next page to load and the caller should verify * that themselves. - *

- *

+ * * There are some preconditions for an element to be clicked. The * element must be visible and it must have a height and width * greater then 0. * * @throws StaleElementReferenceException If the element no - * longer exists as initially defined + * longer exists as initially defined */ void click(); @@ -69,7 +68,7 @@ public interface WebElement extends SearchContext, TakesScreenshot { /** * If this element is a text entry element, this will clear the value. Has no effect on other * elements. Text entry elements are INPUT and TEXTAREA elements. - *

+ * * Note that the events fired by this event may not be as you'd expect. In particular, we don't * fire any keyboard or mouse events. If you want to ensure keyboard events are fired, consider * using something like {@link #sendKeys(CharSequence...)} with the backspace key. To ensure @@ -169,7 +168,7 @@ public interface WebElement extends SearchContext, TakesScreenshot { * This method is affected by the 'implicit wait' times in force at the time of execution. * The findElement(..) invocation will return a matching row, or try again repeatedly until * the configured timeout is reached. - *

+ * * findElement should not be used to look for non-present elements, use {@link #findElements(By)} * and assert zero length response instead. * @@ -213,7 +212,7 @@ public interface WebElement extends SearchContext, TakesScreenshot { * Color values should be returned as rgba strings, so, * for example if the "background-color" property is set as "green" in the * HTML source, the returned value will be "rgba(0, 255, 0, 1)". - *

+ * * Note that shorthand CSS properties (e.g. background, font, border, border-top, margin, * margin-top, padding, padding-top, list-style, outline, pause, cue) are not returned, * in accordance with the @@ -225,4 +224,4 @@ public interface WebElement extends SearchContext, TakesScreenshot { * @return The current, computed value of the property. */ String getCssValue(String propertyName); -} +} \ No newline at end of file diff --git a/src/test/java/io/appium/java_client/events/WebDriverEventListenerCompatibilityTest.java b/src/test/java/io/appium/java_client/events/WebDriverEventListenerCompatibilityTest.java index 4358566f2..acc3563a8 100644 --- a/src/test/java/io/appium/java_client/events/WebDriverEventListenerCompatibilityTest.java +++ b/src/test/java/io/appium/java_client/events/WebDriverEventListenerCompatibilityTest.java @@ -1,6 +1,7 @@ package io.appium.java_client.events; import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsCollectionContaining.hasItems; import static org.junit.Assert.assertThat; import io.appium.java_client.events.listeners.AppiumListener; @@ -9,6 +10,8 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; +import org.openqa.selenium.Alert; +import org.openqa.selenium.security.Credentials; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class WebDriverEventListenerCompatibilityTest extends BaseListenerTest { @@ -56,6 +59,51 @@ public void javaScriptEventTest() { is(true)); } + @Test + public void alertEventTest() { + try { + Alert alert = driver.switchTo().alert(); + alert.accept(); + alert.dismiss(); + alert.sendKeys("Keys"); + Credentials credentials = new Credentials() { + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public String toString() { + return "Test credentials 1"; + } + }; + + Credentials credentials2 = new Credentials() { + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public String toString() { + return "Test credentials 2"; + } + }; + + alert.setCredentials(credentials); + alert.authenticateUsing(credentials2); + + assertThat(listener.messages, + hasItems(WEBDRIVER_EVENT_LISTENER + "Attempt to accept alert", + WEBDRIVER_EVENT_LISTENER + "The alert was accepted", + WEBDRIVER_EVENT_LISTENER + "Attempt to dismiss alert", + WEBDRIVER_EVENT_LISTENER + "The alert was dismissed")); + assertThat(listener.messages.size(), is(4)); + } finally { + listener.messages.clear(); + } + } + @Test public void exceptionEventTest() { assertThat(super.assertThatExceptionListenerWorks(driver, listener, WEBDRIVER_EVENT_LISTENER), diff --git a/src/test/java/io/appium/java_client/events/listeners/AppiumListener.java b/src/test/java/io/appium/java_client/events/listeners/AppiumListener.java index 4224dc529..89740977b 100644 --- a/src/test/java/io/appium/java_client/events/listeners/AppiumListener.java +++ b/src/test/java/io/appium/java_client/events/listeners/AppiumListener.java @@ -10,6 +10,26 @@ public class AppiumListener extends TestListener implements AppiumWebDriverEvent SingleListeners.listeners.put(AppiumListener.class, this); } + @Override + public void beforeAlertAccept(WebDriver driver) { + messages.add("WebDriverEventListener: Attempt to accept alert"); + } + + @Override + public void afterAlertAccept(WebDriver driver) { + messages.add("WebDriverEventListener: The alert was accepted"); + } + + @Override + public void afterAlertDismiss(WebDriver driver) { + messages.add("WebDriverEventListener: Attempt to dismiss alert"); + } + + @Override + public void beforeAlertDismiss(WebDriver driver) { + messages.add("WebDriverEventListener: The alert was dismissed"); + } + @Override public void beforeNavigateTo(String url, WebDriver driver) { messages.add("WebDriverEventListener: Attempt to navigate to " + url); }