From 34d9bf6d44873312dc65fc165b71a0a184232e27 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Mon, 2 May 2016 00:10:00 +0300 Subject: [PATCH] addition to the PR #352 #352. Codestyle issues fix --- pom.xml | 13 +++-- .../java/io/appium/java_client/MobileBy.java | 26 +++++---- .../io/appium/java_client/ios/IOSDriver.java | 5 +- .../java_client/ios/XCUIDriverTest.java | 55 +++++++++---------- 4 files changed, 50 insertions(+), 49 deletions(-) diff --git a/pom.xml b/pom.xml index d7d22f6d3..6aa789404 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,8 @@ ~ limitations under the License. --> - + 4.0.0 io.appium @@ -64,11 +65,11 @@ 3.4 - net.lingala.zip4j - zip4j - 1.3.2 - - + net.lingala.zip4j + zip4j + 1.3.2 + + commons-io commons-io 2.1 diff --git a/src/main/java/io/appium/java_client/MobileBy.java b/src/main/java/io/appium/java_client/MobileBy.java index 9cf0264af..69d97f6c3 100644 --- a/src/main/java/io/appium/java_client/MobileBy.java +++ b/src/main/java/io/appium/java_client/MobileBy.java @@ -71,12 +71,17 @@ public static By AccessibilityId(final String id) { return new ByAccessibilityId(id); } - + + /** + * 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) { - if (iOSNsPredicateString == null) { - throw new IllegalArgumentException("Must supply an iOS NsPredicate String"); + if (iOSNsPredicateString == null) { + throw new IllegalArgumentException("Must supply an iOS NsPredicate String"); } - + return new ByIosNsPredicate(iOSNsPredicateString); } @@ -104,6 +109,7 @@ public List findElements(SearchContext context) { return "By.IosUIAutomation: " + automationText; } } + public static class ByIosNsPredicate extends By implements Serializable { private final String automationText; @@ -112,21 +118,21 @@ public ByIosNsPredicate(String uiautomationText) { automationText = uiautomationText; } - @SuppressWarnings("unchecked") @Override - public List findElements(SearchContext context) { - return (List) ((FindsByIosNsPredicate) context). - findElementsByIosNsPredicate(automationText); + @SuppressWarnings("unchecked") + @Override public List findElements(SearchContext context) { + return (List) ((FindsByIosNsPredicate) context) + .findElementsByIosNsPredicate(automationText); } @Override public WebElement findElement(SearchContext context) { return ((FindsByIosNsPredicate) context) - .findElementByIosNsPredicate(automationText); + .findElementByIosNsPredicate(automationText); } @Override public String toString() { return "By.IosNsPredicate: " + automationText; } - } + } public static class ByAndroidUIAutomator extends By 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 a8ec97019..57fda00e3 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDriver.java +++ b/src/main/java/io/appium/java_client/ios/IOSDriver.java @@ -54,7 +54,8 @@ public class IOSDriver extends AppiumDriver implements IOSDeviceActionShortcuts, GetsNamedTextField, - FindsByIosUIAutomation, FindsByIosNsPredicate{ + FindsByIosUIAutomation, FindsByIosNsPredicate { + private static final String IOS_PLATFORM = MobilePlatform.IOS; /** @@ -68,8 +69,6 @@ public IOSDriver(URL remoteAddress, Capabilities desiredCapabilities) { JsonToIOSElementConverter.class); } - } - /** * @param remoteAddress is the address * of remotely/locally started Appium server diff --git a/src/test/java/io/appium/java_client/ios/XCUIDriverTest.java b/src/test/java/io/appium/java_client/ios/XCUIDriverTest.java index 3ebce8433..022ee7843 100644 --- a/src/test/java/io/appium/java_client/ios/XCUIDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/XCUIDriverTest.java @@ -16,34 +16,26 @@ package io.appium.java_client.ios; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.openqa.selenium.remote.DesiredCapabilities; - -import java.io.File; -import java.io.IOException; - -import net.lingala.zip4j.exception.ZipException; -import net.lingala.zip4j.core.ZipFile; -import org.apache.commons.io.FileUtils; -import io.appium.java_client.remote.HideKeyboardStrategy; +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 io.appium.java_client.MobileBy; -import io.appium.java_client.MobileElement; +import java.io.File; +import java.io.IOException; -import org.junit.*; -import org.openqa.selenium.Point; -import org.openqa.selenium.ScreenOrientation; -import org.openqa.selenium.html5.Location; - public class XCUIDriverTest { - + private static final String SOURCE = "src/test/java/io/appium/java_client/"; private static AppiumDriverLocalService service; protected static IOSDriver driver; @@ -51,7 +43,8 @@ public class XCUIDriverTest { /** * initialization. */ - @BeforeClass public static void beforeClass() throws Exception { + @BeforeClass + public static void beforeClass() throws Exception { service = AppiumDriverLocalService.buildDefaultService(); service.start(); @@ -62,11 +55,11 @@ public class XCUIDriverTest { String source = SOURCE + "UICatalog.app.zip"; try { - ZipFile zipFile = new ZipFile(source); - zipFile.extractAll(SOURCE); + ZipFile zipFile = new ZipFile(source); + zipFile.extractAll(SOURCE); } catch (ZipException e) { - String msg = "Could not extract file"; - throw new ZipException(msg, e); + String msg = "Could not extract file"; + throw new ZipException(msg, e); } File appDir = new File(SOURCE); @@ -84,7 +77,8 @@ public class XCUIDriverTest { /** * finishing. */ - @AfterClass public static void afterClass() { + @AfterClass + public static void afterClass() throws IOException { if (driver != null) { driver.quit(); } @@ -92,9 +86,9 @@ public class XCUIDriverTest { service.stop(); } try { - FileUtils.deleteDirectory(new File(SOURCE + "/UICatalog.app")); + FileUtils.deleteDirectory(new File(SOURCE + "/UICatalog.app")); } catch (IOException e) { - e.printStackTrace(); + throw e; } } @@ -109,9 +103,10 @@ public void getDeviceTimeTest() { /** * 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\"")); + @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\"")); } }