From c0c465907057e64faa47d3b07d864f48f36bef5a Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Tue, 20 Dec 2016 23:55:01 +0530 Subject: [PATCH 1/9] Gradle Publish --- build.gradle | 131 ++++++++++++++++++++++++---------------------- gradle.properties | 7 +++ 2 files changed, 76 insertions(+), 62 deletions(-) diff --git a/build.gradle b/build.gradle index 8b307b23e..2e0991e1f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,8 +2,8 @@ apply plugin: 'java' apply plugin: 'maven' apply plugin: 'eclipse' apply plugin: 'jacoco' -apply plugin: 'maven-publish' apply plugin: 'checkstyle' +apply plugin: 'signing' group 'io.appium' version '5.0.0-SNAPSHOT' @@ -122,73 +122,80 @@ tasks.withType(Checkstyle) { exclude '**/org/openqa/selenium/**' } -task javadocs(type: Javadoc) { - source = sourceSets.main.java -} - -publishing { - publications { - mavenJava(MavenPublication) { - pom.withXml { - asNode().children().last() + { - resolveStrategy = Closure.DELEGATE_FIRST - name 'java-client' - description 'Java client for Appium Mobile Webdriver' - url 'http://appium.io' - developers { - developer { - name 'Jonah Stiennon' - email 'jonahss@gmail.com' - url 'https://github.com/jonahss' - id 'jonahss' - }; - developer { - name 'Sergey Tikhomirov' - email 'tichomirovsergey@gmail.com' - url 'https://github.com/TikhomirovSergey' - id 'TikhomirovSergey' - }; - developer { - name 'Srinivasan Sekar' - email 'srinivasan.sekar1990@gmail.com' - url 'https://github.com/SrinivasanTarget' - id 'SrinivasanTarget' - }; - } - licenses { - license { - name 'Apache License, Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - scm { - url 'https://github.com/appium/java-client' - connection 'scm:git:ssh://git@github.com/appium/java-client.git' - developerConnection 'scm:git:ssh://git@github.com/appium/java-client.git' - tag 'HEAD' - } - } +task javadocJar(type: Jar) { + classifier = 'javadoc' + from javadoc +} + +task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource +} + +artifacts { + archives javadocJar, sourcesJar +} + +signing { + sign configurations.archives +} + +uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: ossrhUsername, password: ossrhPassword) } - from components.java - artifact sourceJar { - classifier 'sources' + + snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { + authentication(userName: ossrhUsername, password: ossrhPassword) } - artifact javadocJar { - classifier 'javadoc' + + pom.project { + packaging 'jar' + name 'java-client' + description 'Java client for Appium Mobile Webdriver' + url 'http://appium.io' + developers { + developer { + name 'Jonah Stiennon' + email 'jonahss@gmail.com' + url 'https://github.com/jonahss' + id 'jonahss' + }; + developer { + name 'Sergey Tikhomirov' + email 'tichomirovsergey@gmail.com' + url 'https://github.com/TikhomirovSergey' + id 'TikhomirovSergey' + }; + developer { + name 'Srinivasan Sekar' + email 'srinivasan.sekar1990@gmail.com' + url 'https://github.com/SrinivasanTarget' + id 'SrinivasanTarget' + }; + } + licenses { + license { + name 'Apache License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution 'repo' + } + } + scm { + url 'https://github.com/appium/java-client' + connection 'scm:git:ssh://git@github.com/appium/java-client.git' + developerConnection 'scm:git:ssh://git@github.com/appium/java-client.git' + tag 'HEAD' + } } } } } -task sourceJar(type: Jar) { - from sourceSets.main.java -} - -task javadocJar (type: Jar, dependsOn: javadoc) { - from javadoc -} - task wrapper(type: Wrapper) { gradleVersion = '2.14.1' description 'Generates the Gradle wrapper scripts.' @@ -196,4 +203,4 @@ task wrapper(type: Wrapper) { test { useJUnit() -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index 1a644c77f..34d114d1c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,8 @@ org.gradle.daemon=true + +signing.keyId=YourKeyId +signing.password=YourPublicKeyPassword +signing.secretKeyRingFile=PathToYourKeyRingFile + +ossrhUsername=your-jira-id +ossrhPassword=your-jira-password From 5177f5238f63493e10f450b99c9ff91a77d8c4a3 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Wed, 21 Dec 2016 22:26:15 +0300 Subject: [PATCH 2/9] Update Page object tools to XCUIT mode - new annotations were provided - supporting tools were actualized --- .../pagefactory/DefaultElementByBuilder.java | 8 +++ .../bys/builder/AppiumByBuilder.java | 5 ++ .../pagefactory/bys/builder/Strategies.java | 6 ++ .../pagefactory/iOSXcuitFindBy.java | 62 +++++++++++++++++++ .../pagefactory/iOSXcuitFindBySet.java | 31 ++++++++++ 5 files changed, 112 insertions(+) create mode 100644 src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBy.java create mode 100644 src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBySet.java diff --git a/src/main/java/io/appium/java_client/pagefactory/DefaultElementByBuilder.java b/src/main/java/io/appium/java_client/pagefactory/DefaultElementByBuilder.java index 217ae2b3a..c53aa8f6c 100644 --- a/src/main/java/io/appium/java_client/pagefactory/DefaultElementByBuilder.java +++ b/src/main/java/io/appium/java_client/pagefactory/DefaultElementByBuilder.java @@ -176,6 +176,14 @@ private static By buildMobileBy(LocatorGroupStrategy locatorGroupStrategy, Annot } } + if (isIOSXcuit()) { + iOSXcuitFindBy[] xCuitFindByArray = annotatedElement.getAnnotationsByType(iOSXcuitFindBy.class); + if (xCuitFindByArray != null && xCuitFindByArray.length > 0) { + return buildMobileBy(howToUseLocators != null ? howToUseLocators.windowsAutomation() : null, + xCuitFindByArray); + } + } + if (isIOS()) { iOSFindBy[] iOSFindByArray = annotatedElement.getAnnotationsByType(iOSFindBy.class); //should be kept for some time diff --git a/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java b/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java index 2c4f84f99..d2b34c64e 100644 --- a/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java +++ b/src/main/java/io/appium/java_client/pagefactory/bys/builder/AppiumByBuilder.java @@ -16,6 +16,7 @@ package io.appium.java_client.pagefactory.bys.builder; +import static io.appium.java_client.remote.AutomationName.IOS_XCUI_TEST; import static io.appium.java_client.remote.AutomationName.SELENDROID; import static io.appium.java_client.remote.MobilePlatform.ANDROID; import static io.appium.java_client.remote.MobilePlatform.IOS; @@ -180,6 +181,10 @@ protected boolean isIOS() { return IOS.equalsIgnoreCase(platform); } + protected boolean isIOSXcuit() { + return isIOS() && IOS_XCUI_TEST.equalsIgnoreCase(automation); + } + protected boolean isWindows() { return WINDOWS.equalsIgnoreCase(platform); } 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 9489311d2..923779511 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 @@ -90,6 +90,12 @@ enum Strategies { return MobileBy .windowsAutomation(getValue(annotation, this)); } + }, + BY_NS_PREDICATE("iOSNsPredicate") { + @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/iOSXcuitFindBy.java b/src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBy.java new file mode 100644 index 000000000..9d12d895c --- /dev/null +++ b/src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBy.java @@ -0,0 +1,62 @@ +/* + * 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.pagefactory; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE}) +@Repeatable(iOSXcuitFindBySet.class) +public @interface iOSXcuitFindBy { + + /** + * The NSPredicate class is used to define logical conditions used to constrain + * a search either for a fetch or for in-memory filtering. + */ + String iOSNsPredicate() default ""; + + /** + * It an UI automation accessibility Id which is a convenient to iOS. + * About iOS accessibility + * {@link "https://developer.apple.com/library/ios/documentation/UIKit/Reference/ + * UIAccessibilityIdentification_Protocol/index.html"} + */ + String accessibility() default ""; + + /** + * It is an id of the target element. + */ + String id() default ""; + + /** + * It is a name of a type/class of the target element. + */ + String className() default ""; + + /** + * It is a desired element tag. + */ + String tagName() default ""; + + /** + * It is a xpath to the target element. + */ + String xpath() default ""; +} diff --git a/src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBySet.java b/src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBySet.java new file mode 100644 index 000000000..195d9f68c --- /dev/null +++ b/src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBySet.java @@ -0,0 +1,31 @@ +/* + * 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.pagefactory; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE}) +public @interface iOSXcuitFindBySet { + /** + * @return an array of {@link io.appium.java_client.pagefactory.iOSXcuitFindBy} which builds a sequence of + * the chained searching for elements or a set of possible locators + */ + iOSXcuitFindBy[] value(); +} From 028dbd6acc3931c15ec4e1f1bc70265bc6391b68 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Sat, 24 Dec 2016 16:57:15 +0300 Subject: [PATCH 3/9] naming was fixed + bugfix --- google-style.xml | 2 +- .../pagefactory/AppiumFieldDecorator.java | 21 +++++-------------- .../pagefactory/DefaultElementByBuilder.java | 4 ++-- .../pagefactory/HowToUseLocators.java | 7 +++++++ ...OSXcuitFindBy.java => iOSXCUITFindBy.java} | 4 ++-- ...tFindBySet.java => iOSXCUITFindBySet.java} | 6 +++--- 6 files changed, 20 insertions(+), 24 deletions(-) rename src/main/java/io/appium/java_client/pagefactory/{iOSXcuitFindBy.java => iOSXCUITFindBy.java} (96%) rename src/main/java/io/appium/java_client/pagefactory/{iOSXcuitFindBySet.java => iOSXCUITFindBySet.java} (85%) diff --git a/google-style.xml b/google-style.xml index dd40c8a90..6f3440428 100755 --- a/google-style.xml +++ b/google-style.xml @@ -158,7 +158,7 @@ - + diff --git a/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java b/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java index abd3e8773..ad07603e3 100644 --- a/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java +++ b/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java @@ -21,6 +21,8 @@ import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility .unpackWebDriverFromSearchContext; +import com.google.common.collect.ImmutableList; + import io.appium.java_client.HasSessionDetails; import io.appium.java_client.MobileElement; import io.appium.java_client.TouchableElement; @@ -58,22 +60,9 @@ */ public class AppiumFieldDecorator implements FieldDecorator { - private static final List> availableElementClasses = - new ArrayList>() { - private static final long serialVersionUID = 1L; - - { - add(WebElement.class); - add(RemoteWebElement.class); - add(MobileElement.class); - add(TouchableElement.class); - add(AndroidElement.class); - add(IOSElement.class); - add(WindowsElement.class); - } - - }; - + private static final List> availableElementClasses = ImmutableList.of(WebElement.class, + RemoteWebElement.class, MobileElement.class, TouchableElement.class, AndroidElement.class, + IOSElement.class, WindowsElement.class); public static long DEFAULT_IMPLICITLY_WAIT_TIMEOUT = 1; public static TimeUnit DEFAULT_TIMEUNIT = TimeUnit.SECONDS; private final WebDriver originalDriver; diff --git a/src/main/java/io/appium/java_client/pagefactory/DefaultElementByBuilder.java b/src/main/java/io/appium/java_client/pagefactory/DefaultElementByBuilder.java index c53aa8f6c..77ca9b614 100644 --- a/src/main/java/io/appium/java_client/pagefactory/DefaultElementByBuilder.java +++ b/src/main/java/io/appium/java_client/pagefactory/DefaultElementByBuilder.java @@ -177,9 +177,9 @@ private static By buildMobileBy(LocatorGroupStrategy locatorGroupStrategy, Annot } if (isIOSXcuit()) { - iOSXcuitFindBy[] xCuitFindByArray = annotatedElement.getAnnotationsByType(iOSXcuitFindBy.class); + iOSXCUITFindBy[] xCuitFindByArray = annotatedElement.getAnnotationsByType(iOSXCUITFindBy.class); if (xCuitFindByArray != null && xCuitFindByArray.length > 0) { - return buildMobileBy(howToUseLocators != null ? howToUseLocators.windowsAutomation() : null, + return buildMobileBy(howToUseLocators != null ? howToUseLocators.iOSXCUITAutomation() : null, xCuitFindByArray); } } diff --git a/src/main/java/io/appium/java_client/pagefactory/HowToUseLocators.java b/src/main/java/io/appium/java_client/pagefactory/HowToUseLocators.java index 5b8affe94..5208367b7 100644 --- a/src/main/java/io/appium/java_client/pagefactory/HowToUseLocators.java +++ b/src/main/java/io/appium/java_client/pagefactory/HowToUseLocators.java @@ -50,4 +50,11 @@ * or the searching by all possible locators. */ LocatorGroupStrategy windowsAutomation() default LocatorGroupStrategy.CHAIN; + + /** + * @return the strategy which defines how to use locators which are described by + * the {@link iOSXCUITFindBy} annotation. These annotations can define the chained searching + * or the searching by all possible locators. + */ + LocatorGroupStrategy iOSXCUITAutomation() default LocatorGroupStrategy.CHAIN; } diff --git a/src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBy.java b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBy.java similarity index 96% rename from src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBy.java rename to src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBy.java index 9d12d895c..aa1910ec8 100644 --- a/src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBy.java +++ b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBy.java @@ -23,8 +23,8 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE}) -@Repeatable(iOSXcuitFindBySet.class) -public @interface iOSXcuitFindBy { +@Repeatable(iOSXCUITFindBySet.class) +public @interface iOSXCUITFindBy { /** * The NSPredicate class is used to define logical conditions used to constrain diff --git a/src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBySet.java b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBySet.java similarity index 85% rename from src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBySet.java rename to src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBySet.java index 195d9f68c..f2f43e7b8 100644 --- a/src/main/java/io/appium/java_client/pagefactory/iOSXcuitFindBySet.java +++ b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBySet.java @@ -22,10 +22,10 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE}) -public @interface iOSXcuitFindBySet { +public @interface iOSXCUITFindBySet { /** - * @return an array of {@link io.appium.java_client.pagefactory.iOSXcuitFindBy} which builds a sequence of + * @return an array of {@link iOSXCUITFindBy} which builds a sequence of * the chained searching for elements or a set of possible locators */ - iOSXcuitFindBy[] value(); + iOSXCUITFindBy[] value(); } From a6b4dbe4acc68345bb6cff2a86de6237b4185e0e Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 25 Dec 2016 16:31:25 +0530 Subject: [PATCH 4/9] Addition to #545 --- .../appium/java_client/ios/AppXCUITTest.java | 39 ++++++ .../java_client/ios/XCUIAutomationTest.java | 58 +-------- .../pagefactory_tests/XCUITModeTest.java | 120 ++++++++++++++++++ 3 files changed, 162 insertions(+), 55 deletions(-) create mode 100644 src/test/java/io/appium/java_client/ios/AppXCUITTest.java create mode 100644 src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java diff --git a/src/test/java/io/appium/java_client/ios/AppXCUITTest.java b/src/test/java/io/appium/java_client/ios/AppXCUITTest.java new file mode 100644 index 000000000..8eda617d5 --- /dev/null +++ b/src/test/java/io/appium/java_client/ios/AppXCUITTest.java @@ -0,0 +1,39 @@ +package io.appium.java_client.ios; + +import io.appium.java_client.remote.AutomationName; +import io.appium.java_client.remote.IOSMobileCapabilityType; +import io.appium.java_client.remote.MobileCapabilityType; +import io.appium.java_client.service.local.AppiumDriverLocalService; +import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; +import org.junit.BeforeClass; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.io.File; + +public class AppXCUITTest extends BaseIOSTest { + + /** + * initialization. + */ + @BeforeClass public static void beforeClass() throws Exception { + service = AppiumDriverLocalService.buildDefaultService(); + service.start(); + + if (service == null || !service.isRunning()) { + throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!"); + } + + File appDir = new File("src/test/java/io/appium/java_client"); + File app = new File(appDir, "TestApp.app.zip"); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); + capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6"); + //sometimes environment has performance problems + capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); + capabilities + .setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST); + capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + driver = new IOSDriver<>(service.getUrl(), capabilities); + } +} diff --git a/src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java b/src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java index 1cb7511b5..e0be4ebea 100644 --- a/src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java +++ b/src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java @@ -19,63 +19,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import io.appium.java_client.MobileElement; -import io.appium.java_client.remote.AutomationName; -import io.appium.java_client.remote.IOSMobileCapabilityType; -import io.appium.java_client.remote.MobileCapabilityType; -import io.appium.java_client.service.local.AppiumDriverLocalService; -import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.DeviceRotation; -import org.openqa.selenium.remote.DesiredCapabilities; -import java.io.File; - -public class XCUIAutomationTest { - - protected static IOSDriver driver; - private static AppiumDriverLocalService service; - - /** - * initialization. - */ - @BeforeClass public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); - - if (service == null || !service.isRunning()) { - throw new AppiumServerHasNotBeenStartedLocallyException( - "An appium server node is not started!"); - } - - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "TestApp.app.zip"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.0"); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6"); - //sometimes environment has performance problems - capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); - capabilities - .setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new IOSDriver<>(service.getUrl(), capabilities); - } - - /** - * finishing. - */ - @AfterClass public static void afterClass() { - if (driver != null) { - driver.quit(); - } - if (service != null) { - service.stop(); - } - } +public class XCUIAutomationTest extends AppXCUITTest { @After public void afterMethod() { driver.rotate(new DeviceRotation(0, 0, 0)); @@ -104,12 +52,12 @@ public class XCUIAutomationTest { } @Test public void doubleTapTest() { - IOSElement firstField = (IOSElement) driver.findElementById("IntegerA"); + IOSElement firstField = driver.findElementById("IntegerA"); firstField.sendKeys("2"); IOSTouchAction iosTouchAction = new IOSTouchAction(driver); iosTouchAction.doubleTap(firstField); - IOSElement editingMenu = (IOSElement) driver.findElementByClassName("UIAEditingMenu"); + IOSElement editingMenu = driver.findElementByClassName("UIAEditingMenu"); assertNotNull(editingMenu); } } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java new file mode 100644 index 000000000..d9438550b --- /dev/null +++ b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java @@ -0,0 +1,120 @@ +/* + * 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.pagefactory_tests; + +import static io.appium.java_client.pagefactory.LocatorGroupStrategy.ALL_POSSIBLE; +import static io.appium.java_client.pagefactory.LocatorGroupStrategy.CHAIN; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent; + +import io.appium.java_client.MobileBy; +import io.appium.java_client.MobileElement; +import io.appium.java_client.ios.AppXCUITTest; +import io.appium.java_client.pagefactory.AppiumFieldDecorator; +import io.appium.java_client.pagefactory.HowToUseLocators; +import io.appium.java_client.pagefactory.iOSXCUITFindBy; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.util.function.Supplier; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class XCUITModeTest extends AppXCUITTest { + + private boolean populated = false; + private WebDriverWait waiting = new WebDriverWait(driver, 10000); + + @HowToUseLocators(iOSAutomation = ALL_POSSIBLE) + @iOSXCUITFindBy(iOSNsPredicate = "label contains 'Compute'") + @iOSXCUITFindBy(className = "XCUIElementTypeButton") + private MobileElement computeButton; + + @HowToUseLocators(iOSAutomation = CHAIN) + @iOSXCUITFindBy(className = "XCUIElementTypeOther") + @iOSXCUITFindBy(iOSNsPredicate = "name like 'Answer'") + private WebElement answer; + + @iOSXCUITFindBy(iOSNsPredicate = "name = 'IntegerA'") + private MobileElement textField1; + + @HowToUseLocators(iOSAutomation = ALL_POSSIBLE) + @iOSXCUITFindBy(iOSNsPredicate = "name = 'IntegerB'") + @iOSXCUITFindBy(accessibility = "IntegerB") + private MobileElement textField2; + + @iOSXCUITFindBy(iOSNsPredicate = "name ENDSWITH 'Gesture'") + private MobileElement gesture; + + @iOSXCUITFindBy(className = "XCUIElementTypeSlider") + private MobileElement slider; + + /** + * The setting up. + */ + @Before public void setUp() throws Exception { + if (!populated) { + PageFactory.initElements(new AppiumFieldDecorator(driver), this); + } + + populated = true; + } + + @Test public void dismissAlertTest() { + Supplier dismissAlert = () -> { + driver.findElement(MobileBy + .iOSNsPredicateString("name CONTAINS 'Slow Down'")).click(); + waiting.until(alertIsPresent()); + driver.switchTo().alert().dismiss(); + return true; + }; + assertTrue(dismissAlert.get()); + } + + @Test public void findByXCUITSelectorTest() { + assertNotEquals(null, computeButton.getText()); + } + + @Test public void findElementByNameTest() { + assertNull(textField1.getText()); + } + + @Test public void findElementByClassNameTest() { + assertEquals("50%", slider.getAttribute("Value")); + } + + @Test public void findElementByXUISelectorTest() { + assertNotNull(gesture.getText()); + } + + @Test public void setValueTest() { + textField1.setValue("2"); + textField2.setValue("4"); + driver.hideKeyboard(); + computeButton.click(); + assertEquals("6", answer.getText()); + } +} From 8bb5d232af35b699d35de575b5e91c45ffbb7065 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 25 Dec 2016 16:45:41 +0530 Subject: [PATCH 5/9] Fixed javaDoc errors --- .../java/io/appium/java_client/pagefactory/iOSXCUITFindBy.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBy.java b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBy.java index aa1910ec8..70c241bdb 100644 --- a/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBy.java +++ b/src/main/java/io/appium/java_client/pagefactory/iOSXCUITFindBy.java @@ -35,8 +35,7 @@ /** * It an UI automation accessibility Id which is a convenient to iOS. * About iOS accessibility - * {@link "https://developer.apple.com/library/ios/documentation/UIKit/Reference/ - * UIAccessibilityIdentification_Protocol/index.html"} + * See UIAccessibilityIdentification */ String accessibility() default ""; From 1d86df0c87e47bb09f3d00f02d40a5bece29ed2d Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 25 Dec 2016 16:59:50 +0530 Subject: [PATCH 6/9] Exclude signing in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 03ebc6da9..d067d5cc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,4 +12,4 @@ cache: - $HOME/.gradle/wrapper/ script: - - ./gradlew clean build -x test + - ./gradlew clean build -x test -x signArchives From befa1153b0edb6c15ddd4b06e57182bc11d078ef Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Sun, 25 Dec 2016 23:26:03 +0530 Subject: [PATCH 7/9] Increased test coverage --- .../pagefactory_tests/XCUITModeTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java index d9438550b..1b181524d 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/XCUITModeTest.java @@ -31,6 +31,7 @@ import io.appium.java_client.ios.AppXCUITTest; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.HowToUseLocators; +import io.appium.java_client.pagefactory.iOSFindBy; import io.appium.java_client.pagefactory.iOSXCUITFindBy; import org.junit.Before; import org.junit.FixMethodOrder; @@ -72,6 +73,20 @@ public class XCUITModeTest extends AppXCUITTest { @iOSXCUITFindBy(className = "XCUIElementTypeSlider") private MobileElement slider; + @iOSFindBy(id = "locationStatus") + private MobileElement locationStatus; + + @HowToUseLocators(iOSAutomation = CHAIN) + @iOSFindBy(id = "TestApp") @iOSXCUITFindBy(iOSNsPredicate = "name BEGINSWITH 'contact'") + private MobileElement contactAlert; + + @HowToUseLocators(iOSAutomation = ALL_POSSIBLE) + @iOSFindBy(uiAutomator = ".elements()[0]") + @iOSXCUITFindBy(iOSNsPredicate = "name BEGINSWITH 'location'") + private MobileElement locationAlert; + + + /** * The setting up. */ @@ -106,6 +121,18 @@ public class XCUITModeTest extends AppXCUITTest { assertEquals("50%", slider.getAttribute("Value")); } + @Test public void pageObjectChainingTest() { + assertTrue(contactAlert.isDisplayed()); + } + + @Test public void findElementByIdTest() { + assertTrue(locationStatus.isDisplayed()); + } + + @Test public void nativeSelectorTest() { + assertTrue(locationAlert.isDisplayed()); + } + @Test public void findElementByXUISelectorTest() { assertNotNull(gesture.getText()); } From e345ba36789d47b40a018507ed3f8e9e1cb68626 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Mon, 26 Dec 2016 15:18:42 +0530 Subject: [PATCH 8/9] added travis config --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d067d5cc5..58a6165e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,10 @@ jdk: before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ -cache: - directories: - - $HOME/.gradle/caches/ - - $HOME/.gradle/wrapper/ +#cache: +# directories: +# - $HOME/.gradle/caches/ +# - $HOME/.gradle/wrapper/ script: - ./gradlew clean build -x test -x signArchives From 6bd6184c911300a0f349c4e466188cb093e21509 Mon Sep 17 00:00:00 2001 From: Srinivasan Sekar Date: Mon, 26 Dec 2016 15:33:37 +0530 Subject: [PATCH 9/9] added travis config --- .travis.yml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 58a6165e7..d902f762e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,8 @@ language: java jdk: - oraclejdk8 -before_cache: - - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ -#cache: -# directories: -# - $HOME/.gradle/caches/ -# - $HOME/.gradle/wrapper/ - -script: - - ./gradlew clean build -x test -x signArchives +sudo: required + +install: true + +script: ./gradlew clean build -x test -x signArchives