diff --git a/src/io/appium/java_client/AppiumDriver.java b/src/io/appium/java_client/AppiumDriver.java index 27c020205..09d989586 100644 --- a/src/io/appium/java_client/AppiumDriver.java +++ b/src/io/appium/java_client/AppiumDriver.java @@ -18,10 +18,7 @@ import com.google.common.collect.ImmutableMap; -import org.openqa.selenium.Capabilities; -import org.openqa.selenium.ContextAware; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.*; import org.openqa.selenium.remote.*; import java.net.URL; @@ -30,7 +27,7 @@ import java.util.Map; import java.util.Set; -public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware { +public class AppiumDriver extends RemoteWebDriver implements MobileDriver, ContextAware, FindsByIosUIAutomation { private final MobileErrorHandler errorHandler = new MobileErrorHandler(); @@ -45,6 +42,7 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){ } + @Override protected Response execute(String driverCommand, Map parameters) { try { return super.execute(driverCommand, parameters); @@ -56,6 +54,7 @@ protected Response execute(String driverCommand, Map parameters) { "definitely in the Appium Driver"); } + @Override protected Response execute(String command) { return execute(command, ImmutableMap.of()); } @@ -63,7 +62,7 @@ protected Response execute(String command) { - + @Override public WebDriver context(String name) { if (name == null) { throw new IllegalArgumentException("Must supply a context name"); @@ -74,7 +73,7 @@ public WebDriver context(String name) { return AppiumDriver.this; } - + @Override public Set getContextHandles() { Response response = execute(DriverCommand.GET_CONTEXT_HANDLES); Object value = response.getValue(); @@ -86,7 +85,7 @@ public Set getContextHandles() { } } - + @Override public String getContext() { String contextName = String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue()); if (contextName.equals("null")) { @@ -94,4 +93,14 @@ public String getContext() { } return contextName; } + + @Override + public WebElement findElementByIosUIAutomation(String using) { + return findElement("-ios uiautomation", using); + } + + @Override + public List findElementsByIosUIAutomation(String using) { + return findElements("-ios uiautomation", using); + } } \ No newline at end of file diff --git a/src/io/appium/java_client/FindsByIosUIAutomation.java b/src/io/appium/java_client/FindsByIosUIAutomation.java new file mode 100644 index 000000000..a5a94bd8c --- /dev/null +++ b/src/io/appium/java_client/FindsByIosUIAutomation.java @@ -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 FindsByIosUIAutomation { + WebElement findElementByIosUIAutomation(String using); + + List findElementsByIosUIAutomation(String using); +} \ No newline at end of file diff --git a/src/io/appium/java_client/MobileBy.java b/src/io/appium/java_client/MobileBy.java new file mode 100644 index 000000000..03b9a4864 --- /dev/null +++ b/src/io/appium/java_client/MobileBy.java @@ -0,0 +1,48 @@ +package io.appium.java_client; + +import org.openqa.selenium.By; +import org.openqa.selenium.SearchContext; +import org.openqa.selenium.WebElement; + +import java.io.Serializable; +import java.util.List; + +/** + * Created by jonahss on 4/10/14. + */ +public abstract class MobileBy extends By { + + public static By IosUIAutomation(final String uiautomationText) { + if (uiautomationText == null) { + throw new IllegalArgumentException("Must supply a uiautomationText"); + } + + return new ByIosUIAutomation(uiautomationText); + } + + public static class ByIosUIAutomation extends By implements Serializable { + + private final String automationText; + + public ByIosUIAutomation(String uiautomationText) { + automationText = uiautomationText; + } + + @Override + public List findElements(SearchContext context) { + return ((FindsByIosUIAutomation) context).findElementsByIosUIAutomation(automationText); + } + + @Override + public WebElement findElement(SearchContext context) { + return ((FindsByIosUIAutomation) context).findElementByIosUIAutomation(automationText); + } + + @Override + public String toString() { + return "By.IosUIAutomation: " + automationText; + } + } +} + + diff --git a/test/io/appium/java_client/ContextTest.java b/test/io/appium/java_client/ContextTest.java index 85468b70f..90eabb306 100644 --- a/test/io/appium/java_client/ContextTest.java +++ b/test/io/appium/java_client/ContextTest.java @@ -21,7 +21,7 @@ public class ContextTest { @Before public void setup() throws Exception { File appDir = new File("test/io/appium/java_client"); - File app = new File(appDir, "WebViewApp.app"); + File app = new File(appDir, "WebViewApp.app.zip"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability(CapabilityType.VERSION, "7.1"); diff --git a/test/io/appium/java_client/IosUIAutomationTest.java b/test/io/appium/java_client/IosUIAutomationTest.java new file mode 100644 index 000000000..b374e7ba9 --- /dev/null +++ b/test/io/appium/java_client/IosUIAutomationTest.java @@ -0,0 +1,66 @@ +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; + +/** + * Test context-related features + */ +public class IosUIAutomationTest { + + private AppiumDriver driver; + + @Before + public void setup() throws Exception { + File appDir = new File("test/io/appium/java_client"); + File app = new File(appDir, "UICatalog.app.zip"); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); + capabilities.setCapability(CapabilityType.VERSION, "7.1"); + capabilities.setCapability(CapabilityType.PLATFORM, "Mac"); + capabilities.setCapability("device", "iPhone Simulator"); + 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.findElementByIosUIAutomation(".elements()[0]"); + assertEquals(element.getAttribute("name"), "UICatalog"); + } + + @Test + public void findElementsTest() { + List elements = driver.findElementsByIosUIAutomation("elements()"); + assertEquals(3, elements.size()); + } + + @Test + public void MobileElementByTest() { + WebElement element = driver.findElement(MobileBy.IosUIAutomation(".elements()[0]")); + System.out.println(element); + assertEquals(element.getAttribute("name"), "UICatalog"); + } + + @Test + public void MobileElementsByTest() { + List elements = driver.findElements(MobileBy.IosUIAutomation(".elements()")); + assertEquals(3, elements.size()); + } + +} diff --git a/test/io/appium/java_client/UICatalog.app.zip b/test/io/appium/java_client/UICatalog.app.zip new file mode 100755 index 000000000..ad64ffa46 Binary files /dev/null and b/test/io/appium/java_client/UICatalog.app.zip differ diff --git a/test/io/appium/java_client/WebViewApp.app.zip b/test/io/appium/java_client/WebViewApp.app.zip new file mode 100755 index 000000000..45266abef Binary files /dev/null and b/test/io/appium/java_client/WebViewApp.app.zip differ diff --git a/test/io/appium/java_client/WebViewApp.app/Default-568h@2x.png b/test/io/appium/java_client/WebViewApp.app/Default-568h@2x.png deleted file mode 100644 index 0891b7aab..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/Default-568h@2x.png and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/Default.png b/test/io/appium/java_client/WebViewApp.app/Default.png deleted file mode 100644 index 4c8ca6f69..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/Default.png and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/Default@2x.png b/test/io/appium/java_client/WebViewApp.app/Default@2x.png deleted file mode 100644 index 35b84cffe..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/Default@2x.png and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/Info.plist b/test/io/appium/java_client/WebViewApp.app/Info.plist deleted file mode 100644 index 745f9ce1d..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/Info.plist and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/PkgInfo b/test/io/appium/java_client/WebViewApp.app/PkgInfo deleted file mode 100644 index bd04210fb..000000000 --- a/test/io/appium/java_client/WebViewApp.app/PkgInfo +++ /dev/null @@ -1 +0,0 @@ -APPL???? \ No newline at end of file diff --git a/test/io/appium/java_client/WebViewApp.app/WebViewApp b/test/io/appium/java_client/WebViewApp.app/WebViewApp deleted file mode 100755 index 10f58dc08..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/WebViewApp and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/cybervillainsCA.cer b/test/io/appium/java_client/WebViewApp.app/cybervillainsCA.cer deleted file mode 100644 index 945a93de0..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/cybervillainsCA.cer and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/en.lproj/InfoPlist.strings b/test/io/appium/java_client/WebViewApp.app/en.lproj/InfoPlist.strings deleted file mode 100644 index 3967e063f..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/en.lproj/InfoPlist.strings and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPad.storyboardc/Info.plist b/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPad.storyboardc/Info.plist deleted file mode 100644 index 191e37b8a..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPad.storyboardc/Info.plist and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPad.storyboardc/UIViewController-qCV-AS-rCm.nib b/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPad.storyboardc/UIViewController-qCV-AS-rCm.nib deleted file mode 100644 index 168e87b22..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPad.storyboardc/UIViewController-qCV-AS-rCm.nib and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPad.storyboardc/qCV-AS-rCm-view-Thv-qS-DhF.nib b/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPad.storyboardc/qCV-AS-rCm-view-Thv-qS-DhF.nib deleted file mode 100644 index 1b872f7a7..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPad.storyboardc/qCV-AS-rCm-view-Thv-qS-DhF.nib and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPhone.storyboardc/2-view-3.nib b/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPhone.storyboardc/2-view-3.nib deleted file mode 100644 index fe94c5b97..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPhone.storyboardc/2-view-3.nib and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPhone.storyboardc/Info.plist b/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPhone.storyboardc/Info.plist deleted file mode 100644 index 4254a33d2..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPhone.storyboardc/Info.plist and /dev/null differ diff --git a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPhone.storyboardc/UIViewController-2.nib b/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPhone.storyboardc/UIViewController-2.nib deleted file mode 100644 index c9d4126dd..000000000 Binary files a/test/io/appium/java_client/WebViewApp.app/en.lproj/MainStoryboard_iPhone.storyboardc/UIViewController-2.nib and /dev/null differ