Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SrinivasanTarget committed Mar 10, 2017
2 parents 8ac84e7 + 48f3a96 commit 937cc91
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 23 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ This is the Java language binding for writing Appium Tests, conforms to [Mobile
##Changelog##
*5.0.0 (under construction yet)*

*5.0.0-BETA5*
- **[UPDATE]** Update to Selenium 3.2.0
- **[BUG FIX]** Excessive dependency on `guava` was removed. It causes errors. Issue report: [#588](https://github.com/appium/java-client/issues/588). FIX: [#589](https://github.com/appium/java-client/pull/589).
- **[ENHANCEMENT]**. The capability `io.appium.java_client.remote.AndroidMobileCapabilityType#SYSTEM_PORT` was added. [#591](https://github.com/appium/java-client/pull/591)

*5.0.0-BETA4*
- **[ENHANCEMENT]** Android. API to read the performance data was added. [#562](https://github.com/appium/java-client/pull/562)
- **[REFACTOR]** Android. Simplified the activity starting by reducing the number of parameters through POJO clas. Old methods which start activities were marked `@Deprecated`. [#579](https://github.com/appium/java-client/pull/579) [#585](https://github.com/appium/java-client/pull/585)
Expand Down
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'signing'
apply plugin: 'maven-publish'

group 'io.appium'
version '5.0.0-BETA4'
version '5.0.0-BETA5'

repositories {
jcenter()
Expand Down Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/appium/java_client/events/DefaultAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/appium/java_client/events/DefaultListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,38 @@ public void add(Collection<Listener> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,9 @@ public interface AndroidMobileCapabilityType extends CapabilityType {
String ANDROID_SCREENSHOT_PATH = "androidScreenshotPath";

String SELENDROID_PORT = "selendroidPort";

/**
* The port number, which being used by UIAutomator2
*/
String SYSTEM_PORT = "systemPort";
}
25 changes: 13 additions & 12 deletions src/main/java/org/openqa/selenium/WebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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.
* <p>
*
* findElement should not be used to look for non-present elements, use {@link #findElements(By)}
* and assert zero length response instead.
*
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -242,7 +242,7 @@ interface Options {

/**
* Gets the {@link Logs} interface used to fetch different types of logs.
* <p>
*
* <p>To set the logging preferences {@link LoggingPreferences}.
*
* @return A Logs interface.
Expand Down Expand Up @@ -318,7 +318,7 @@ interface TargetLocator {
* precedence over those matched by ID.
*
* @param nameOrId the name of the frame window, the id of the &lt;frame&gt; or &lt;iframe&gt;
* 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
*/
Expand All @@ -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)
*/
Expand All @@ -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
*/
Expand All @@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -512,4 +513,4 @@ interface Window {
*/
void fullscreen();
}
}
}
15 changes: 7 additions & 8 deletions src/main/java/org/openqa/selenium/WebElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
*
* 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.
* <p>
* <p>
*
* 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();

Expand All @@ -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.
* <p>
*
* 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
Expand Down Expand Up @@ -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.
* <p>
*
* findElement should not be used to look for non-present elements, use {@link #findElements(By)}
* and assert zero length response instead.
*
Expand Down Expand Up @@ -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)".
* <p>
*
* 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
Expand All @@ -225,4 +224,4 @@ public interface WebElement extends SearchContext, TakesScreenshot {
* @return The current, computed value of the property.
*/
String getCssValue(String propertyName);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 937cc91

Please sign in to comment.