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
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,21 @@
<artifactId>cglib</artifactId>
<version>3.1</version>
</dependency>

<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.8</version>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>xml-apis</artifactId>
<groupId>xml-apis</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<packaging>jar</packaging>
<name>java-client</name>
Expand Down
21 changes: 2 additions & 19 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.appium.java_client.internal.JsonToMobileElementConverter;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.*;
import org.openqa.selenium.html5.Location;
Expand All @@ -42,7 +41,7 @@
public abstract class AppiumDriver extends RemoteWebDriver implements MobileDriver,
ContextAware, Rotatable, FindsByAccessibilityId, LocationContext,
DeviceActionShortcuts, TouchShortcuts, InteractsWithFiles,
InteractsWithApps {
InteractsWithApps, ScrollsTo {

private final static ErrorHandler errorHandler = new ErrorHandler(
new ErrorCodesMobile(), true);
Expand Down Expand Up @@ -106,7 +105,6 @@ protected static ImmutableMap<String, Object> getCommandImmutableMap(
public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {

super(remoteAddress, desiredCapabilities);
this.setElementConverter(new JsonToMobileElementConverter(this));

this.executeMethod = new AppiumExecutionMethod(this);
this.remoteAddress = remoteAddress;
Expand Down Expand Up @@ -525,22 +523,7 @@ public void lockScreen(int seconds) {
execute(LOCK, ImmutableMap.of("seconds", seconds));
}

/**
* Scroll to an element which contains the given text.
* Implemented differently on iOS and Android, see docs for individual methods.
* @param text
*/
public abstract void scrollTo(String text);

/**
* Scroll to an element with the given text.
* Implemented differently on iOS and Android, see docs for individual methods.
* @param text
*/
public abstract void scrollToExact(String text);


@Override
@Override
public WebDriver context(String name) {
if (!_isNotNullOrEmpty(name)) {
throw new IllegalArgumentException("Must supply a context name");
Expand Down
19 changes: 1 addition & 18 deletions src/main/java/io/appium/java_client/MobileElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

import java.util.List;

public class MobileElement extends RemoteWebElement implements FindsByAccessibilityId, FindsByAndroidUIAutomator,
FindsByIosUIAutomation {
public abstract class MobileElement extends RemoteWebElement implements FindsByAccessibilityId, ScrollsTo {

protected FileDetector fileDetector;

Expand All @@ -40,22 +39,6 @@ public WebElement findElement(By by) {
return by.findElement(this);
}

public WebElement findElementByIosUIAutomation(String using) {
return findElement("-ios uiautomation", using);
}

public List<WebElement> findElementsByIosUIAutomation(String using) {
return findElements("-ios uiautomation", using);
}

public WebElement findElementByAndroidUIAutomator(String using) {
return findElement("-android uiautomator", using);
}

public List<WebElement> findElementsByAndroidUIAutomator(String using) {
return findElements("-android uiautomator", using);
}

public WebElement findElementByAccessibilityId(String using) {
return findElement("accessibility id", using);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/appium/java_client/ScrollsTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

public interface ScrollsTo {

/**
* Scroll to an element which contains the given text.
* @param text
*/
public MobileElement scrollTo(String text);

/**
* Scroll to an element with the given text.
* @param text
*/
public MobileElement scrollToExact(String text);

}
13 changes: 8 additions & 5 deletions src/main/java/io/appium/java_client/android/AndroidDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.AppiumSetting;
import io.appium.java_client.FindsByAndroidUIAutomator;
import io.appium.java_client.MobileElement;
import io.appium.java_client.NetworkConnectionSetting;
import io.appium.java_client.android.internal.JsonToAndroidElementConverter;
import io.appium.java_client.remote.MobilePlatform;

import org.openqa.selenium.Capabilities;
Expand Down Expand Up @@ -37,6 +39,7 @@ public class AndroidDriver extends AppiumDriver implements
public AndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) {
super(remoteAddress, substituteMobilePlatform(desiredCapabilities,
ANDROID_PLATFORM));
this.setElementConverter(new JsonToAndroidElementConverter(this));
}

/**
Expand All @@ -45,10 +48,10 @@ public AndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) {
* @param text
*/
@Override
public void scrollTo(String text) {
public MobileElement scrollTo(String text) {
String uiScrollables = UiScrollable("new UiSelector().descriptionContains(\"" + text + "\")") +
UiScrollable("new UiSelector().textContains(\"" + text + "\")");
findElementByAndroidUIAutomator(uiScrollables);
return (MobileElement) findElementByAndroidUIAutomator(uiScrollables);
}

/**
Expand All @@ -57,13 +60,13 @@ public void scrollTo(String text) {
* @param text
*/
@Override
public void scrollToExact(String text) {
public MobileElement scrollToExact(String text) {
String uiScrollables = UiScrollable("new UiSelector().description(\"" + text + "\")") +
UiScrollable("new UiSelector().text(\"" + text + "\")");
findElementByAndroidUIAutomator(uiScrollables);
return (MobileElement) findElementByAndroidUIAutomator(uiScrollables);
}

private String UiScrollable(String uiSelector) {
static String UiScrollable(String uiSelector) {
return "new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(" + uiSelector + ".instance(0));";
}

Expand Down
46 changes: 46 additions & 0 deletions src/main/java/io/appium/java_client/android/AndroidElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.appium.java_client.android;

import java.util.List;

import org.openqa.selenium.WebElement;

import io.appium.java_client.FindsByAndroidUIAutomator;
import io.appium.java_client.MobileElement;

public class AndroidElement extends MobileElement implements
FindsByAndroidUIAutomator {

@Override
public WebElement findElementByAndroidUIAutomator(String using) {
return findElement("-android uiautomator", using);
}

@Override
public List<WebElement> findElementsByAndroidUIAutomator(String using) {
return findElements("-android uiautomator", using);
}

/**
* Scroll forward to the element which has a description or name which contains the input text.
* The scrolling is performed on the first scrollView present on the UI
* @param text
*/
@Override
public MobileElement scrollTo(String text) {
String uiScrollables = AndroidDriver.UiScrollable("new UiSelector().descriptionContains(\"" + text + "\")") +
AndroidDriver.UiScrollable("new UiSelector().textContains(\"" + text + "\")");
return (MobileElement) findElementByAndroidUIAutomator(uiScrollables);
}

/**
* Scroll forward to the element which has a description or name which exactly matches the input text.
* The scrolling is performed on the first scrollView present on the UI
* @param text
*/
@Override
public MobileElement scrollToExact(String text) {
String uiScrollables = AndroidDriver.UiScrollable("new UiSelector().description(\"" + text + "\")") +
AndroidDriver.UiScrollable("new UiSelector().text(\"" + text + "\")");
return (MobileElement) findElementByAndroidUIAutomator(uiScrollables);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.appium.java_client.android.internal;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.internal.JsonToMobileElementConverter;

public class JsonToAndroidElementConverter extends JsonToMobileElementConverter {

public JsonToAndroidElementConverter(AppiumDriver driver) {
super(driver);
}

@Override
protected MobileElement newMobileElement() {
AndroidElement toReturn = new AndroidElement();
toReturn.setParent(driver);
return toReturn;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* Reconstitutes {@link WebElement}s from their JSON representation. Will recursively convert Lists
* and Maps to catch nested references. All other values pass through the converter unchanged.
*/
public class JsonToMobileElementConverter extends JsonToWebElementConverter {
private AppiumDriver driver;
public abstract class JsonToMobileElementConverter extends JsonToWebElementConverter {
protected AppiumDriver driver;

public JsonToMobileElementConverter(AppiumDriver driver) {
super(driver);
Expand Down Expand Up @@ -53,9 +53,9 @@ public Object apply(Object result) {
return result;
}

protected MobileElement newMobileElement() {
MobileElement toReturn = new MobileElement();
toReturn.setParent(driver);
return toReturn;
}
protected abstract MobileElement newMobileElement(); //{
//MobileElement toReturn = new MobileElement();
//toReturn.setParent(driver);
//return toReturn;
//}
}
48 changes: 12 additions & 36 deletions src/main/java/io/appium/java_client/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.FindsByIosUIAutomation;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.internal.JsonToIOSElementConverter;
import io.appium.java_client.remote.MobilePlatform;

import org.openqa.selenium.Capabilities;
Expand All @@ -21,55 +22,30 @@ public class IOSDriver extends AppiumDriver implements IOSDeviceActionShortcuts,
public IOSDriver(URL remoteAddress, Capabilities desiredCapabilities) {
super(remoteAddress, substituteMobilePlatform(desiredCapabilities,
IOS_PLATFORM));
this.setElementConverter(new JsonToIOSElementConverter(this));
}

/**
* Scroll to the element whose 'text' attribute contains the input text.
* This scrolling happens within the first UIATableView on the UI. Use the additional 'context' param to specify a different scrollView.
* @param text input text contained in text attribute
*/
@Override
public void scrollTo(String text) {
scrollTo(text, (MobileElement) findElementByClassName("UIATableView"));
}
@Override
public MobileElement scrollTo(String text) {
return ((MobileElement) findElementByClassName("UIATableView")).scrollTo(text);
}

/**
/**
* Scroll to the element whose 'text' attribute is equal to the input text.
* This scrolling happens within the first UIATableView on the UI. Use the additional 'context' param to specify a different scrollView.
* @param text input text to match
*/
@Override
public void scrollToExact(String text) {
scrollToExact(text, (MobileElement) findElementByClassName("UIATableView"));
}

/**
* Scroll to the element whose 'text' attribute contains the input text.
* @param text input text contained in text attribute
* @param context container element to scroll within
*/
public void scrollTo(String text, MobileElement context) {
context.findElementByIosUIAutomation(".scrollToElementWithPredicate(\"name CONTAINS '" + text + "'\")");
}

/**
* Scroll to the element whose 'text' attribute is equal to the input text.
* @param text input text to match
* @param context container element to scroll within
*/
public void scrollToExact(String text, MobileElement context) {
context.findElementByIosUIAutomation(".scrollToElementWithName(\"" + text + "\")");
}

/**
* Scroll to the given element.
* This scrolling happens within the first UIATableView on the UI. Use the ScrollToExactWithinContext() method to specify a different scrollView.
*/
public void scrollTo(WebElement el) {
scrollToExact(el.getText());
}
@Override
public MobileElement scrollToExact(String text) {
return ((MobileElement) findElementByClassName("UIATableView")).scrollToExact(text);
}

/**
/**
* @see IOSDeviceActionShortcuts#hideKeyboard(String, String)
*/
@Override
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/io/appium/java_client/ios/IOSElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.appium.java_client.ios;

import java.util.List;

import org.openqa.selenium.WebElement;

import io.appium.java_client.FindsByIosUIAutomation;
import io.appium.java_client.MobileElement;

public class IOSElement extends MobileElement implements FindsByIosUIAutomation{

@Override
public WebElement findElementByIosUIAutomation(String using) {
return findElement("-ios uiautomation", using);
}

@Override
public List<WebElement> findElementsByIosUIAutomation(String using) {
return findElements("-ios uiautomation", using);
}

@Override
public MobileElement scrollTo(String text) {
return (MobileElement) findElementByIosUIAutomation(".scrollToElementWithPredicate(\"name CONTAINS '" + text + "'\")");
}

@Override
public MobileElement scrollToExact(String text) {
return (MobileElement) findElementByIosUIAutomation(".scrollToElementWithName(\"" + text + "\")");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.appium.java_client.ios.internal;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.internal.JsonToMobileElementConverter;
import io.appium.java_client.ios.IOSElement;

public class JsonToIOSElementConverter extends JsonToMobileElementConverter {

public JsonToIOSElementConverter(AppiumDriver driver) {
super(driver);
}

@Override
protected MobileElement newMobileElement() {
IOSElement toReturn = new IOSElement();
toReturn.setParent(driver);
return toReturn;
}

}
Loading