Skip to content

Commit

Permalink
compile with latest selenium
Browse files Browse the repository at this point in the history
  • Loading branch information
rafe-g authored and rafael-chavez committed Jul 27, 2016
1 parent 35a42bf commit c40c15b
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 50 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Locators:
- findElementsByIosUIAutomation()
- findElementByAndroidUIAutomator()
- findElementsByAndroidUIAutomator()
- findElementByIosNsPredicate()
- findElementsByIosNsPredicate()

### Features and other interesting information###

Expand All @@ -94,6 +96,7 @@ Implementation: [#437](https://github.com/appium/java-client/pull/437). Also [ne
*4.0.0*
- all code marked `@Deprecated` was removed. Java client won't support old servers (v<1.5.0)
anymore.
- the searching for elements by nspredicate string was added. It requires the [XCUITest mode](https://github.com/appium/java-client/blob/master/docs/Installing-xcuitest-driver.md). Thanks to [@rafael-chavez](https://github.com/appium/java-client/pull/352) for the contribution
- the ability to start an activity using Android intent actions, intent categories, flags and arguments
was added to `AndroidDriver`. Thanks to [@saikrishna321](https://github.com/saikrishna321) for the contribution.
- `scrollTo()` and `scrollToExact()` became deprecated. They are going to be removed in the next release.
Expand All @@ -104,6 +107,7 @@ deprecated as well. They are going to be removed in the next release.
- the enum `io.appium.java_client.android.Connection` was added. All supported network bitmasks are defined there.
- Android. Old methods which get/set connection were marked `@Deprecated`
- Android. New methods which consume/return `io.appium.java_client.android.Connection` were added.
- the `nsPredicate` parameter was added to the `iOSFindBy` annotation
- the `commandRepository` field is public now. The modification of the `MobileCommand`
- Constructors like `AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities)` were added to
`io.appium.java_client.android.AndroidDriver` and `io.appium.java_client.ios.IOSDriver`
Expand Down
19 changes: 19 additions & 0 deletions docs/Installing-xcuitest-driver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Setting Up XCUITest
---

**Install Appium XCUITest Driver**

Clone Appium XCUITest Driver repo https://github.com/appium/appium-xcuitest-driver

```
git clone --recursive https://github.com/appium/appium-xcuitest-driver.git
cd appium-xcuitest-driver
npm install
```

Set your appium path to the appropriate location (Where you cloned appium-xcuitest-driver) and you can
start the driver by doing:

```
node .
```
28 changes: 22 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@

<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>5.0.0-SNAPSHOT</version>
<version>3.4.1</version>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand All @@ -30,17 +35,17 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>2.53.0</version>
<version>3.0.0-beta1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.53.0</version>
<version>3.0.0-beta1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
<version>3.0.0-beta1</version>
<exclusions>
<exclusion>
<groupId>cglib</groupId>
Expand All @@ -51,12 +56,12 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>2.53.0</version>
<version>3.0.0-beta1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.53.0</version>
<version>3.0.0-beta1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -101,6 +106,17 @@
<version>1.8.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<packaging>jar</packaging>
<name>java-client</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,10 @@ public DefaultGenericMobileDriver(CommandExecutor executor, Capabilities desired
return super.findElements(by);
}

@Override public List findElements(String by, String using) {
return super.findElements(by, using);
}

@Override public T findElement(By by) {
return (T) super.findElement(by);
}

@Override public T findElement(String by, String using) {
return (T) super.findElement(by, using);
}

@Override public List findElementsById(String id) {
return super.findElementsById(id);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/appium/java_client/FindsByIosNsPredicate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.appium.java_client;

import org.openqa.selenium.WebElement;

import java.util.List;

public interface FindsByIosNsPredicate<T extends WebElement> {
T findElementByIosNsPredicate(String using);

List<T> findElementsByIosNsPredicate(String using);
}
31 changes: 31 additions & 0 deletions src/main/java/io/appium/java_client/MobileBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public static By AndroidUIAutomator(final String uiautomatorText) {
public static By AccessibilityId(final String accessibilityId) {
return new ByAccessibilityId(accessibilityId);
}

/**
* This locator strategy is available in XCUITest Driver mode
* @param iOSNsPredicateString is an an iOS NsPredicate String
* @return an instance of {@link io.appium.java_client.MobileBy.ByIosNsPredicate}
*/
public static By IosNsPredicateString(final String iOSNsPredicateString) {
return new ByIosNsPredicate(iOSNsPredicateString);
}

public static class ByIosUIAutomation extends MobileBy implements Serializable {

Expand All @@ -97,6 +106,28 @@ public List<WebElement> findElements(SearchContext context) {
}
}

public static class ByIosNsPredicate extends MobileBy implements Serializable {

public ByIosNsPredicate(String iOSNsPredicate) {
super(iOSNsPredicate);
}

@SuppressWarnings("unchecked")
@Override public List<WebElement> findElements(SearchContext context) {
return (List<WebElement>) ((FindsByIosNsPredicate<?>) context)
.findElementsByIosNsPredicate(getLocatorString());
}

@Override public WebElement findElement(SearchContext context) {
return ((FindsByIosNsPredicate<?>) context)
.findElementByIosNsPredicate(getLocatorString());
}

@Override public String toString() {
return "By.IosNsPredicate: " + getLocatorString();
}
}


public static class ByAndroidUIAutomator extends MobileBy implements Serializable {

Expand Down
11 changes: 11 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 @@ -206,4 +206,15 @@ public void afterWindowIsMoved(WebDriver driver, WebDriver.Window window, Point
@Override public void afterRotation(WebDriver driver, ScreenOrientation orientation) {
((RotationEventListener) dispatcher).afterRotation(driver, orientation);
}


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


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

}
27 changes: 25 additions & 2 deletions src/main/java/io/appium/java_client/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.google.common.collect.ImmutableMap;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.FindsByAccessibilityId;
import io.appium.java_client.FindsByIosNsPredicate;
import io.appium.java_client.FindsByIosUIAutomation;
import io.appium.java_client.ios.internal.JsonToIOSElementConverter;
import io.appium.java_client.remote.MobilePlatform;
Expand Down Expand Up @@ -51,8 +53,7 @@
*/
public class IOSDriver<T extends WebElement>
extends AppiumDriver<T>
implements IOSDeviceActionShortcuts,
FindsByIosUIAutomation<T> {
implements IOSDeviceActionShortcuts, FindsByIosUIAutomation<T>, FindsByIosNsPredicate<T> {

private static final String IOS_PLATFORM = MobilePlatform.IOS;

Expand Down Expand Up @@ -215,6 +216,28 @@ public List<T> findElementsByIosUIAutomation(String using)
throws WebDriverException {
return (List<T>) findElements("-ios uiautomation", using);
}

/**
* @throws org.openqa.selenium.WebDriverException
* This method is not applicable with browser/webview UI.
*/
@SuppressWarnings("unchecked")
@Override
public T findElementByIosNsPredicate(String using)
throws WebDriverException {
return (T) findElement("-ios predicate string", using);
}

/**
* @throws org.openqa.selenium.WebDriverException
* This method is not applicable with browser/webview UI.
*/
@SuppressWarnings("unchecked")
@Override
public List<T> findElementsByIosNsPredicate(String using)
throws WebDriverException {
return (List<T>) findElements("-ios predicate string", using);
}

/**
* Lock the device (bring it to the lock screen) for a given number of
Expand Down
77 changes: 58 additions & 19 deletions src/main/java/io/appium/java_client/ios/IOSElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,68 @@

package io.appium.java_client.ios;

import com.google.common.collect.ImmutableMap;

import io.appium.java_client.FindsByIosNsPredicate;
import io.appium.java_client.FindsByIosUIAutomation;
import io.appium.java_client.MobileCommand;
import io.appium.java_client.MobileElement;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;

import java.util.List;
import java.util.ArrayList;

public class IOSElement extends MobileElement implements FindsByIosUIAutomation<MobileElement>,
FindsByIosNsPredicate<MobileElement> {
/**
* @throws WebDriverException
* This method is not applicable with browser/webview UI.
*/
@Override
public MobileElement findElementByIosUIAutomation(String using) throws WebDriverException {
return findElement("-ios uiautomation", using);
}

/**
* @throws WebDriverException
* This method is not applicable with browser/webview UI.
*/
@Override
public List<MobileElement> findElementsByIosUIAutomation(String using) throws WebDriverException {
List<MobileElement> found = findElements("-ios uiautomation", using);
return found;
}

/**
* @throws org.openqa.selenium.WebDriverException
* This method is not applicable with browser/webview UI.
*/
@Override
public MobileElement findElementByIosNsPredicate(String using) throws WebDriverException {
return (IOSElement) findElement("-ios predicate string", using);
}

/**
* @throws WebDriverException
* This method is not applicable with browser/webview UI.
*/
@Override
public List<MobileElement> findElementsByIosNsPredicate(String using) throws WebDriverException {
List<MobileElement> found = findElements("-ios predicate string", using);
return found;
}

public class IOSElement extends MobileElement
implements FindsByIosUIAutomation<MobileElement> {
/**
* @throws WebDriverException
* This method is not applicable with browser/webview UI.
*/
@Override public MobileElement findElementByIosUIAutomation(String using)
throws WebDriverException {
return findElement("-ios uiautomation", using);
}

/**
* @throws WebDriverException
* This method is not applicable with browser/webview UI.
*/
@Override public List<MobileElement> findElementsByIosUIAutomation(String using)
throws WebDriverException {
return findElements("-ios uiautomation", using);
}
/**
* This method sets the new value of the attribute "value".
*
* @param value
* is the new value which should be set
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public void setValue(String value) {
ImmutableMap.Builder builder = ImmutableMap.builder();
builder.put("id", id).put("value", value);
execute(MobileCommand.SET_VALUE, builder.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ enum Strategies {
return By
.partialLinkText(getValue(annotation, this));
}
};
},
BYNSPREDICATE("nsPredicate") {
@Override By getBy(Annotation annotation) {
return MobileBy
.IosNsPredicateString(getValue(annotation, this));
}
}
;

private final String valueName;

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/appium/java_client/pagefactory/iOSFindBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,15 @@
* It is a xpath to the target element.
*/
String xpath() default "";

/**
* This parameter makes perform the searching by iOS NSPredicate.
* This locator strategy is available in XCUITest Driver mode.
* Documentation to read:
* https://github.com/appium/java-client/blob/master/docs/
* Installing-xcuitest-driver.md
*
* https://github.com/appium/appium-xcuitest-driver/blob/master/README.md
*/
String nsPredicate() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class AndroidDriverTest extends BaseAndroidTest {
File temp = File.createTempFile("Temp_", "_test");
try {
FileUtils.writeStringToFile(temp, "The eventual code is no "
+ "more than the deposit of your understanding. ~E. W. Dijkstra", "UTF-8", true);
+ "more than the deposit of your understanding. ~E. W. Dijkstra", "UTF-8");
driver.pushFile("/data/local/tmp/remote2.txt", temp);
byte[] returnData = driver.pullFile("/data/local/tmp/remote2.txt");
String returnDataDecoded = new String(Base64.decodeBase64(returnData));
Expand Down
Loading

0 comments on commit c40c15b

Please sign in to comment.