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
13 changes: 12 additions & 1 deletion src/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import java.util.Map;
import java.util.Set;

public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware, FindsByIosUIAutomation {
public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware, FindsByIosUIAutomation,
FindsByAndroidUIAutomator {

private final MobileErrorHandler errorHandler = new MobileErrorHandler();

Expand Down Expand Up @@ -103,4 +104,14 @@ public WebElement findElementByIosUIAutomation(String using) {
public List<WebElement> findElementsByIosUIAutomation(String using) {
return findElements("-ios uiautomation", using);
}

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

@Override
public List<WebElement> findElementsByAndroidUIAutomator(String using) {
return findElements("-android uiautomator", using);
}
}
27 changes: 27 additions & 0 deletions src/io/appium/java_client/FindsByAndroidUIAutomator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2014 Appium committers

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package io.appium.java_client;

import org.openqa.selenium.WebElement;

import java.util.List;

public interface FindsByAndroidUIAutomator {
WebElement findElementByAndroidUIAutomator(String using);

List<WebElement> findElementsByAndroidUIAutomator(String using);
}
32 changes: 31 additions & 1 deletion src/io/appium/java_client/MobileBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ public abstract class MobileBy extends By {

public static By IosUIAutomation(final String uiautomationText) {
if (uiautomationText == null) {
throw new IllegalArgumentException("Must supply a uiautomationText");
throw new IllegalArgumentException("Must supply an iOS UIAutomation string");
}

return new ByIosUIAutomation(uiautomationText);
}

public static By AndroidUIAutomator(final String uiautomatorText) {
if (uiautomatorText == null) {
throw new IllegalArgumentException("Must supply an Android UIAutomator string");
}

return new ByAndroidUIAutomator(uiautomatorText);
}

public static class ByIosUIAutomation extends By implements Serializable {

private final String automationText;
Expand All @@ -43,6 +51,28 @@ public String toString() {
return "By.IosUIAutomation: " + automationText;
}
}

public static class ByAndroidUIAutomator extends By implements Serializable {

private final String automatorText;

public ByAndroidUIAutomator(String uiautomatorText) {
automatorText = uiautomatorText;
}

@Override
public List<WebElement> findElements(SearchContext context) {
return ((FindsByAndroidUIAutomator) context).findElementsByAndroidUIAutomator(automatorText);
}

@Override
public WebElement findElement(SearchContext context) {
return ((FindsByAndroidUIAutomator) context).findElementByAndroidUIAutomator(automatorText);
}

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


68 changes: 68 additions & 0 deletions test/io/appium/java_client/AndroidUIAutomatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.appium.java_client;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.File;
import java.net.URL;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Test -android uiautomator locator strategy
*/
public class AndroidUIAutomatorTest {

private AppiumDriver driver;

@Before
public void setup() throws Exception {
File appDir = new File("test/io/appium/java_client");
File app = new File(appDir, "ApiDemos-debug.apk.zip");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("device", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@After
public void tearDown() throws Exception {
driver.quit();
}

@Test
public void findElementTest() {
WebElement element = driver.findElementByAndroidUIAutomator("new UiSelector().index(0)");
assertEquals("android.widget.FrameLayout", element.getTagName());
}

@Test
public void findElementsTest() {
List<WebElement> elements = driver.findElementsByAndroidUIAutomator("new UiSelector().clickable(true)");
assertTrue(elements.size() > 11);
}

@Test
public void findElementByTest() {
WebElement element = driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().index(0)"));
assertEquals("android.widget.FrameLayout", element.getTagName());
}

@Test
public void findElementsByTest() {
List<WebElement> elements = driver.findElements(MobileBy.AndroidUIAutomator("new UiSelector().clickable(true)"));
assertTrue(elements.size() > 11);
}

@Test(expected = IllegalArgumentException.class)
public void ErrorTest() {
driver.findElementByAndroidUIAutomator(null);
}
}
Binary file added test/io/appium/java_client/ApiDemos-debug.apk
Binary file not shown.
6 changes: 5 additions & 1 deletion test/io/appium/java_client/IosUIAutomationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.junit.Assert.assertEquals;

/**
* Test context-related features
* Test -ios uiautomation locator strategy
*/
public class IosUIAutomationTest {

Expand Down Expand Up @@ -63,4 +63,8 @@ public void MobileElementsByTest() {
assertEquals(3, elements.size());
}

@Test(expected = IllegalArgumentException.class)
public void ErrorTest() {
driver.findElementByIosUIAutomation(null);
}
}