Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ compileJava {
}

dependencies {
compile('org.seleniumhq.selenium:selenium-java:2.53.1'){
compile('org.seleniumhq.selenium:selenium-java:3.0.0'){
exclude module: 'cglib'
exclude group: 'com.google.code.gson'
}
Expand All @@ -60,6 +60,7 @@ dependencies {
compile 'cglib:cglib:3.2.4'
compile 'commons-validator:commons-validator:1.5.1'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'commons-io:commons-io:2.5'
compile 'com.google.code.gson:gson:2.6.2'
compile 'org.springframework:spring-context:4.3.2.RELEASE'
compile 'org.aspectj:aspectjweaver:1.8.9'
Expand Down
68 changes: 42 additions & 26 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.DeviceRotation;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.ScreenOrientation;
Expand Down Expand Up @@ -57,17 +58,18 @@
import java.util.Map;
import java.util.Set;


/**
* @param <T> the required type of class which implement {@link org.openqa.selenium.WebElement}.
* Instances of the defined type will be returned via findElement* and findElements*
* Warning (!!!). Allowed types:
* {@link org.openqa.selenium.WebElement}
* {@link io.appium.java_client.TouchableElement}
* {@link org.openqa.selenium.remote.RemoteWebElement}
* {@link io.appium.java_client.MobileElement} and its subclasses that designed
* specifically
* for each target mobile OS (still Android and iOS)
*/
* @param <T> the required type of class which implement {@link org.openqa.selenium.WebElement}.
* Instances of the defined type will be returned via findElement* and findElements*
* Warning (!!!). Allowed types:
* {@link org.openqa.selenium.WebElement}
* {@link io.appium.java_client.TouchableElement}
* {@link org.openqa.selenium.remote.RemoteWebElement}
* {@link io.appium.java_client.MobileElement} and its subclasses that designed
* specifically
* for each target mobile OS (still Android and iOS)
*/
@SuppressWarnings("unchecked")
public abstract class AppiumDriver<T extends WebElement>
extends DefaultGenericMobileDriver<T> {
Expand All @@ -79,13 +81,13 @@ public abstract class AppiumDriver<T extends WebElement>
private ExecuteMethod executeMethod;

/**
* @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}
* or class that extends it. Default commands or another vendor-specific
* commands may be specified there.
* @param capabilities take a look
* at {@link org.openqa.selenium.Capabilities}
* @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor}
* or class that extends it. Default commands or another vendor-specific
* commands may be specified there.
* @param capabilities take a look
* at {@link org.openqa.selenium.Capabilities}
* @param converterClazz is an instance of a class that extends
* {@link org.openqa.selenium.remote.internal.JsonToWebElementConverter}. It converts
* {@link org.openqa.selenium.remote.internal.JsonToWebElementConverter}. It converts
* JSON response to an instance of
* {@link org.openqa.selenium.WebElement}
*/
Expand All @@ -98,10 +100,10 @@ protected AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities,
this.remoteAddress = executor.getAddressOfRemoteServer();
try {
Constructor<? extends JsonToWebElementConverter> constructor =
converterClazz.getConstructor(RemoteWebDriver.class);
converterClazz.getConstructor(RemoteWebDriver.class);
this.setElementConverter(constructor.newInstance(this));
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException
| InvocationTargetException e) {
| InvocationTargetException e) {
throw new RuntimeException(e);
}
}
Expand All @@ -114,7 +116,7 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities,

public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,
Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
Class<? extends JsonToWebElementConverter> converterClazz) {
this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress,
httpClientFactory), desiredCapabilities, converterClazz);
}
Expand All @@ -127,7 +129,7 @@ public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabi

public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,
Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
Class<? extends JsonToWebElementConverter> converterClazz) {
this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory),
desiredCapabilities, converterClazz);
}
Expand All @@ -139,14 +141,14 @@ public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabiliti

public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,
Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
Class<? extends JsonToWebElementConverter> converterClazz) {
this(builder.build(), httpClientFactory, desiredCapabilities, converterClazz);
}

public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory,
desiredCapabilities, converterClazz);
this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory, desiredCapabilities,
converterClazz);
}

public AppiumDriver(Capabilities desiredCapabilities,
Expand All @@ -156,8 +158,8 @@ public AppiumDriver(Capabilities desiredCapabilities,

/**
* @param originalCapabilities the given {@link Capabilities}.
* @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has
* to be set up
* @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has
* to be set up
* @return {@link Capabilities} with changed mobile platform value
*/
protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities,
Expand Down Expand Up @@ -409,6 +411,21 @@ public void zoom(int x, int y) {
return contextName;
}

@Override public DeviceRotation rotation() {
Response response = execute(DriverCommand.GET_SCREEN_ROTATION);
DeviceRotation deviceRotation =
new DeviceRotation((Map<String, Number>) response.getValue());
if (deviceRotation.getX() < 0 || deviceRotation.getY() < 0 || deviceRotation.getZ() < 0) {
throw new WebDriverException("Unexpected orientation returned: " + deviceRotation);
}
return deviceRotation;
}

@Override public void rotate(DeviceRotation rotation) {
execute(DriverCommand.SET_SCREEN_ROTATION, rotation.parameters());
}


@Override public void rotate(ScreenOrientation orientation) {
execute(DriverCommand.SET_SCREEN_ORIENTATION,
ImmutableMap.of("orientation", orientation.value().toUpperCase()));
Expand Down Expand Up @@ -450,7 +467,6 @@ public URL getRemoteAddress() {

/**
* @return a map with values that hold session details.
*
*/
public Map<String, Object> getSessionDetails() {
Response response = execute(GET_SESSION);
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/io/appium/java_client/events/DefaultListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,18 @@
import java.util.Collection;
import java.util.List;

class DefaultListener implements Listener, AppiumWebDriverEventListener, ListensToException,
SearchingEventListener, NavigationEventListener,
JavaScriptEventListener, ElementEventListener, AlertEventListener,
class DefaultListener
implements Listener, AppiumWebDriverEventListener, ListensToException, SearchingEventListener,
NavigationEventListener, JavaScriptEventListener, ElementEventListener, AlertEventListener,
WindowEventListener, ContextEventListener, RotationEventListener {

private final List<Listener> listeners = new ArrayList<>();

private Object dispatcher = Proxy.newProxyInstance(Listener.class.getClassLoader(),
new Class[] {AlertEventListener.class,
ContextEventListener.class, ElementEventListener.class, JavaScriptEventListener.class,
ListensToException.class, NavigationEventListener.class, RotationEventListener.class,
SearchingEventListener.class, WindowEventListener.class,
WebDriverEventListener.class},
private Object dispatcher = Proxy.newProxyInstance(Listener.class.getClassLoader(),
new Class[] {AlertEventListener.class, ContextEventListener.class,
ElementEventListener.class, JavaScriptEventListener.class, ListensToException.class,
NavigationEventListener.class, RotationEventListener.class,
SearchingEventListener.class, WindowEventListener.class, WebDriverEventListener.class},
new ListenerInvocationHandler(listeners));

@Override public void beforeNavigateTo(String url, WebDriver driver) {
Expand Down Expand Up @@ -109,10 +108,20 @@ class DefaultListener implements Listener, AppiumWebDriverEventListener, Listens
((ElementEventListener) dispatcher).beforeChangeValueOf(element, driver);
}

@Override public void beforeChangeValueOf(WebElement element, WebDriver driver,
CharSequence[] keysToSend) {
((ElementEventListener) dispatcher).beforeChangeValueOf(element, driver, keysToSend);
}

@Override public void afterChangeValueOf(WebElement element, WebDriver driver) {
((ElementEventListener) dispatcher).afterChangeValueOf(element, driver);
}

@Override public void afterChangeValueOf(WebElement element, WebDriver driver,
CharSequence[] keysToSend) {
((ElementEventListener) dispatcher).afterChangeValueOf(element, driver, keysToSend);
}

@Override public void beforeScript(String script, WebDriver driver) {
((JavaScriptEventListener) dispatcher).beforeScript(script, driver);
}
Expand Down Expand Up @@ -206,4 +215,4 @@ public void afterWindowIsMoved(WebDriver driver, WebDriver.Window window, Point
@Override public void afterRotation(WebDriver driver, ScreenOrientation orientation) {
((RotationEventListener) dispatcher).afterRotation(driver, orientation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public interface ElementEventListener extends Listener {
*/
void beforeChangeValueOf(WebElement element, WebDriver driver);

/**
* Called before {@link org.openqa.selenium.WebElement#clear WebElement.clear()},
* {@link org.openqa.selenium.WebElement#sendKeys WebElement.sendKeys(...)}.
*
* @param driver WebDriver
* @param element the WebElement being used for the action
*/
void beforeChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend);

/**
* Called after {@link org.openqa.selenium.WebElement#clear WebElement.clear()},
* {@link org.openqa.selenium.WebElement#sendKeys WebElement.sendKeys(...)} .
Expand All @@ -56,4 +65,14 @@ public interface ElementEventListener extends Listener {
* @param element the WebElement being used for the action
*/
void afterChangeValueOf(WebElement element, WebDriver driver);
}

/**
* Called after {@link org.openqa.selenium.WebElement#clear WebElement.clear()},
* {@link org.openqa.selenium.WebElement#sendKeys WebElement.sendKeys(...)} .
* Not called, if an exception is thrown.
*
* @param driver WebDriver
* @param element the WebElement being used for the action
*/
void afterChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ContextAware;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.DeviceRotation;
import org.openqa.selenium.HasCapabilities;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
Expand Down Expand Up @@ -61,10 +62,18 @@ private static List<StubWebElement> createStubList() {
//The rotation does nothing there
}

@Override public void rotate(DeviceRotation rotation) {
//The rotation does nothing there
}

@Override public ScreenOrientation getOrientation() {
return null;
}

@Override public DeviceRotation rotation() {
return null;
}

@Override public void get(String url) {
//There is no navigation. It is added only for event firing
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public class AppiumListener extends TestListener implements AppiumWebDriverEvent
messages.add("WebDriverEventListener: Thee element was clicked");
}

@Override public void beforeChangeValueOf(WebElement element, WebDriver driver,
CharSequence[] keysToSend) {
messages.add("WebDriverEventListener: Attempt to click on the element");
}

@Override public void beforeChangeValueOf(WebElement element, WebDriver driver) {
messages.add("WebDriverEventListener: Attempt to change value of the element");
}
Expand All @@ -71,6 +76,11 @@ public class AppiumListener extends TestListener implements AppiumWebDriverEvent
messages.add("WebDriverEventListener: The value of the element was changed");
}

@Override public void afterChangeValueOf(WebElement element, WebDriver driver,
CharSequence[] keysToSend) {
messages.add("WebDriverEventListener: Thee element was clicked");
}

@Override public void beforeScript(String script, WebDriver driver) {
messages.add("WebDriverEventListener: Attempt to perform java script: " + script);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ public class ElementListener extends TestListener implements ElementEventListene
messages.add("Attempt to change value of the element");
}

@Override public void beforeChangeValueOf(WebElement element, WebDriver driver,
CharSequence[] keysToSend) {
messages.add("Attempt to change value of the element");
}

@Override public void afterChangeValueOf(WebElement element, WebDriver driver) {
messages.add("The value of the element was changed");
}

@Override public void afterChangeValueOf(WebElement element, WebDriver driver,
CharSequence[] keysToSend) {
messages.add("The value of the element was changed");
}

@Override protected void add() {
SingleListeners.listeners.put(ElementListener.class, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ public class ElementListener2 extends TestListener implements ElementEventListen
messages.add("Externally defined listener: Attempt to change value of the element");
}

@Override public void beforeChangeValueOf(WebElement element, WebDriver driver,
CharSequence[] keysToSend) {
messages.add("Externally defined listener: Attempt to change value of the element");
}

@Override public void afterChangeValueOf(WebElement element, WebDriver driver) {
messages.add("Externally defined listener: The value of the element was changed");
}

@Override public void afterChangeValueOf(WebElement element, WebDriver driver,
CharSequence[] keysToSend) {
messages.add("Externally defined listener: The value of the element was changed");
}

@Override protected void add() {
SingleListeners.listeners.put(ElementListener2.class, this);
}
Expand Down