From f7dd095b24b64fdd5b4f2f02531146cc2d9cf183 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sat, 21 May 2016 23:35:18 +0530 Subject: [PATCH] Removed findelement by nsPredicate string Override findelements method in AppiumDriver fixed code styling issues minor corrections --- README.md | 4 - docs/Installing-xcuitest-driver.md | 19 --- pom.xml | 11 -- .../io/appium/java_client/AppiumDriver.java | 4 + .../DefaultGenericMobileDriver.java | 8 ++ .../java_client/FindsByIosNsPredicate.java | 11 -- .../java/io/appium/java_client/MobileBy.java | 31 ----- .../io/appium/java_client/ios/IOSDriver.java | 25 +--- .../io/appium/java_client/ios/IOSElement.java | 26 +--- .../pagefactory/bys/builder/Strategies.java | 9 +- .../java_client/pagefactory/iOSFindBy.java | 11 -- .../java_client/ios/XCUIDriverTest.java | 112 ------------------ 12 files changed, 15 insertions(+), 256 deletions(-) delete mode 100644 docs/Installing-xcuitest-driver.md delete mode 100644 src/main/java/io/appium/java_client/FindsByIosNsPredicate.java delete mode 100644 src/test/java/io/appium/java_client/ios/XCUIDriverTest.java diff --git a/README.md b/README.md index 05ebf0798..542a8ce4a 100644 --- a/README.md +++ b/README.md @@ -104,8 +104,6 @@ Locators: - findElementsByIosUIAutomation() - findElementByAndroidUIAutomator() - findElementsByAndroidUIAutomator() -- findElementByIosNsPredicate() -- findElementsByIosNsPredicate() ## Note to developers! ## If you are working on this project and use Intellij Idea, you need to change the compiler to the Eclipse compilers instead of the default. @@ -115,7 +113,6 @@ If you are using the Eclipse IDE, make sure you are using version Luna or later. *4.0.0 (under construction yet)* - 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. @@ -123,7 +120,6 @@ was added to `AndroidDriver`. Thanks to [@saikrishna321](https://github.com/saik - 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` - The refactoring of `io.appium.java_client.internal.JsonToMobileElementConverter`. Now it accepts `org.openqa.selenium.remote.RemoteWebDriver` as the constructor parameter. It is possible to re-use diff --git a/docs/Installing-xcuitest-driver.md b/docs/Installing-xcuitest-driver.md deleted file mode 100644 index 9f3f7d158..000000000 --- a/docs/Installing-xcuitest-driver.md +++ /dev/null @@ -1,19 +0,0 @@ -## 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 . -``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index 979ef538d..d11788342 100644 --- a/pom.xml +++ b/pom.xml @@ -64,17 +64,6 @@ commons-lang3 3.4 - - net.lingala.zip4j - zip4j - 1.3.2 - test - - - commons-io - commons-io - 2.5 - jar java-client diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 35be780b2..784bad5c6 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -224,6 +224,10 @@ private static CommandInfo deleteC(String url) { return super.findElements(by); } + @Override public List findElements(String by, String using) { + return super.findElements(by, using); + } + @Override public List findElementsById(String id) { return super.findElementsById(id); } diff --git a/src/main/java/io/appium/java_client/DefaultGenericMobileDriver.java b/src/main/java/io/appium/java_client/DefaultGenericMobileDriver.java index 686610465..24d79ae6c 100644 --- a/src/main/java/io/appium/java_client/DefaultGenericMobileDriver.java +++ b/src/main/java/io/appium/java_client/DefaultGenericMobileDriver.java @@ -55,10 +55,18 @@ 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); } diff --git a/src/main/java/io/appium/java_client/FindsByIosNsPredicate.java b/src/main/java/io/appium/java_client/FindsByIosNsPredicate.java deleted file mode 100644 index 3772421c6..000000000 --- a/src/main/java/io/appium/java_client/FindsByIosNsPredicate.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.appium.java_client; - -import org.openqa.selenium.WebElement; - -import java.util.List; - -public interface FindsByIosNsPredicate { - T findElementByIosNsPredicate(String using); - - List findElementsByIosNsPredicate(String using); -} diff --git a/src/main/java/io/appium/java_client/MobileBy.java b/src/main/java/io/appium/java_client/MobileBy.java index 17d8f58d1..7ece7110c 100644 --- a/src/main/java/io/appium/java_client/MobileBy.java +++ b/src/main/java/io/appium/java_client/MobileBy.java @@ -73,15 +73,6 @@ 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 { @@ -106,28 +97,6 @@ public List findElements(SearchContext context) { } } - public static class ByIosNsPredicate extends MobileBy implements Serializable { - - public ByIosNsPredicate(String iOSNsPredicate) { - super(iOSNsPredicate); - } - - @SuppressWarnings("unchecked") - @Override public List findElements(SearchContext context) { - return (List) ((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 { diff --git a/src/main/java/io/appium/java_client/ios/IOSDriver.java b/src/main/java/io/appium/java_client/ios/IOSDriver.java index 7fc90b688..a51805bec 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDriver.java +++ b/src/main/java/io/appium/java_client/ios/IOSDriver.java @@ -24,7 +24,6 @@ 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.ScrollsTo; import io.appium.java_client.SwipeElementDirection; @@ -56,7 +55,7 @@ public class IOSDriver extends AppiumDriver implements IOSDeviceActionShortcuts, GetsNamedTextField, - FindsByIosUIAutomation, FindsByIosNsPredicate { + FindsByIosUIAutomation { private static final String IOS_PLATFORM = MobilePlatform.IOS; @@ -267,28 +266,6 @@ public List findElementsByIosUIAutomation(String using) throws WebDriverException { return (List) 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 findElementsByIosNsPredicate(String using) - throws WebDriverException { - return (List) findElements("-ios predicate string", using); - } /** * Lock the device (bring it to the lock screen) for a given number of diff --git a/src/main/java/io/appium/java_client/ios/IOSElement.java b/src/main/java/io/appium/java_client/ios/IOSElement.java index 5e1fd5de3..6649bac03 100644 --- a/src/main/java/io/appium/java_client/ios/IOSElement.java +++ b/src/main/java/io/appium/java_client/ios/IOSElement.java @@ -18,7 +18,6 @@ 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; @@ -31,8 +30,7 @@ import java.util.List; public class IOSElement extends MobileElement - implements FindsByIosUIAutomation, ScrollsTo, - FindsByIosNsPredicate { + implements FindsByIosUIAutomation, ScrollsTo { /** * @throws WebDriverException * This method is not applicable with browser/webview UI. @@ -55,28 +53,6 @@ public class IOSElement extends MobileElement } return result; } - - /** - * @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 findElementsByIosNsPredicate(String using) - throws WebDriverException { - List result = new ArrayList(); - List found = findElements("-ios predicate string", using); - for (WebElement e : found) { - result.add((IOSElement) e); - } - return result; - } /** * This method is deprecated because it is not consistent and it is going to be removed. diff --git a/src/main/java/io/appium/java_client/pagefactory/bys/builder/Strategies.java b/src/main/java/io/appium/java_client/pagefactory/bys/builder/Strategies.java index 83cee6080..b4f375cd0 100644 --- a/src/main/java/io/appium/java_client/pagefactory/bys/builder/Strategies.java +++ b/src/main/java/io/appium/java_client/pagefactory/bys/builder/Strategies.java @@ -84,14 +84,7 @@ 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; diff --git a/src/main/java/io/appium/java_client/pagefactory/iOSFindBy.java b/src/main/java/io/appium/java_client/pagefactory/iOSFindBy.java index dd6ac14a5..0686cf9ef 100644 --- a/src/main/java/io/appium/java_client/pagefactory/iOSFindBy.java +++ b/src/main/java/io/appium/java_client/pagefactory/iOSFindBy.java @@ -65,15 +65,4 @@ * 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 ""; } diff --git a/src/test/java/io/appium/java_client/ios/XCUIDriverTest.java b/src/test/java/io/appium/java_client/ios/XCUIDriverTest.java deleted file mode 100644 index 022ee7843..000000000 --- a/src/test/java/io/appium/java_client/ios/XCUIDriverTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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.ios; - -import static org.junit.Assert.assertTrue; - -import io.appium.java_client.MobileBy; -import io.appium.java_client.MobileElement; -import io.appium.java_client.remote.IOSMobileCapabilityType; -import io.appium.java_client.remote.MobileCapabilityType; -import io.appium.java_client.service.local.AppiumDriverLocalService; -import net.lingala.zip4j.core.ZipFile; -import net.lingala.zip4j.exception.ZipException; -import org.apache.commons.io.FileUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openqa.selenium.remote.DesiredCapabilities; - -import java.io.File; -import java.io.IOException; - -public class XCUIDriverTest { - - private static final String SOURCE = "src/test/java/io/appium/java_client/"; - private static AppiumDriverLocalService service; - protected static IOSDriver driver; - - /** - * initialization. - */ - @BeforeClass - public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); - - if (service == null || !service.isRunning()) { - throw new RuntimeException("An appium server node is not started!"); - } - - String source = SOURCE + "UICatalog.app.zip"; - - try { - ZipFile zipFile = new ZipFile(source); - zipFile.extractAll(SOURCE); - } catch (ZipException e) { - String msg = "Could not extract file"; - throw new ZipException(msg, e); - } - - File appDir = new File(SOURCE); - File app = new File(appDir, "UICatalog.app"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.3"); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6"); - //sometimes environment has performance problems - capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new IOSDriver<>(service.getUrl(), capabilities); - } - - /** - * finishing. - */ - @AfterClass - public static void afterClass() throws IOException { - if (driver != null) { - driver.quit(); - } - if (service != null) { - service.stop(); - } - try { - FileUtils.deleteDirectory(new File(SOURCE + "/UICatalog.app")); - } catch (IOException e) { - throw e; - } - - } - - //TODO There is no ability to check this function usibg simulators. - // When CI will have been set up then this test will be returned - public void getDeviceTimeTest() { - String time = driver.getDeviceTime(); - assertTrue(time.length() == 28); - } - - /** - * Verifies UICatalog element is present in view. - */ - @Test - public void getiOSElementByPredicate() { - //Needs to run on the XCUITest ios Driver (https://github.com/appium/appium-xcuitest-driver.git). - driver.findElement(MobileBy.IosNsPredicateString("identifier == \"UICatalog\"")); - } - -}