diff --git a/src/main/java/io/appium/java_client/ios/PerformsTouchID.java b/src/main/java/io/appium/java_client/ios/PerformsTouchID.java index 5b0b422f2..53a3d1bf1 100644 --- a/src/main/java/io/appium/java_client/ios/PerformsTouchID.java +++ b/src/main/java/io/appium/java_client/ios/PerformsTouchID.java @@ -16,8 +16,8 @@ package io.appium.java_client.ios; -import static io.appium.java_client.ios.IOSMobileCommandHelper.touchIdCommand; import static io.appium.java_client.ios.IOSMobileCommandHelper.toggleTouchIdEnrollmentCommand; +import static io.appium.java_client.ios.IOSMobileCommandHelper.touchIdCommand; import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.ExecutesMethod; diff --git a/src/main/java/io/appium/java_client/pagefactory/OverrideWidget.java b/src/main/java/io/appium/java_client/pagefactory/OverrideWidget.java index 9efff1e6e..d4d8870d0 100644 --- a/src/main/java/io/appium/java_client/pagefactory/OverrideWidget.java +++ b/src/main/java/io/appium/java_client/pagefactory/OverrideWidget.java @@ -59,11 +59,31 @@ Class extends Widget> iOSUIAutomation() default Widget.class; /** - * This property is designed for Android native content when Selendroid automation is used. + * This property is designed for Android native content when + * {@link io.appium.java_client.remote.AutomationName#SELENDROID} automation is used. * A declared class should not be abstract. Declared class also should be a subclass * of an annotated class/class which is declared by an annotated field. * * @return a class which extends {@link io.appium.java_client.pagefactory.Widget} */ Class extends Widget> selendroid() default Widget.class; + + /** + * This property is designed for iOS native content when + * {@link io.appium.java_client.remote.AutomationName#IOS_XCUI_TEST} automation is used. + * A declared class should not be abstract. Declared class also should be a subclass + * of an annotated class/class which is declared by an annotated field. + * + * @return a class which extends {@link io.appium.java_client.pagefactory.Widget} + */ + Class extends Widget> iOSXCUITAutomation() default Widget.class; + + /** + * This property is designed for Windows native content. + * A declared class should not be abstract. Declared class also should be a subclass + * of an annotated class/class which is declared by an annotated field. + * + * @return a class which extends {@link io.appium.java_client.pagefactory.Widget} + */ + Class extends Widget> windowsAutomation() default Widget.class; } diff --git a/src/main/java/io/appium/java_client/pagefactory/OverrideWidgetReader.java b/src/main/java/io/appium/java_client/pagefactory/OverrideWidgetReader.java index b433cb6b4..e814b807b 100644 --- a/src/main/java/io/appium/java_client/pagefactory/OverrideWidgetReader.java +++ b/src/main/java/io/appium/java_client/pagefactory/OverrideWidgetReader.java @@ -19,6 +19,7 @@ import static io.appium.java_client.pagefactory.WidgetConstructorUtil.findConvenientConstructor; import static io.appium.java_client.remote.MobilePlatform.ANDROID; import static io.appium.java_client.remote.MobilePlatform.IOS; +import static io.appium.java_client.remote.MobilePlatform.WINDOWS; import io.appium.java_client.pagefactory.bys.ContentType; import io.appium.java_client.remote.AutomationName; @@ -35,6 +36,8 @@ class OverrideWidgetReader { private static final String ANDROID_UI_AUTOMATOR = "androidUIAutomator"; private static final String IOS_UI_AUTOMATION = "iOSUIAutomation"; private static final String SELENDROID = "selendroid"; + private static final String IOS_XCUIT_AUTOMATION = "iOSXCUITAutomation"; + private static final String WINDOWS_AUTOMATION = "windowsAutomation"; @SuppressWarnings("unchecked") private static Class extends Widget> getConvenientClass(Class extends Widget> declaredClass, @@ -74,19 +77,26 @@ static Class extends Widget> getMobileNativeWidgetClass(Class extends Widget String transformedPlatform = String.valueOf(platform).toUpperCase().trim(); String transformedAutomation = String.valueOf(automation).toUpperCase().trim(); - if (ANDROID.equalsIgnoreCase(transformedPlatform) && AutomationName.SELENDROID - .equalsIgnoreCase(transformedAutomation)) { - return getConvenientClass(declaredClass, annotatedElement, SELENDROID); - } - if (ANDROID.equalsIgnoreCase(transformedPlatform)) { + if (AutomationName.SELENDROID.equalsIgnoreCase(transformedAutomation)) { + return getConvenientClass(declaredClass, annotatedElement, SELENDROID); + } + return getConvenientClass(declaredClass, annotatedElement, ANDROID_UI_AUTOMATOR); } if (IOS.equalsIgnoreCase(transformedPlatform)) { + if (AutomationName.IOS_XCUI_TEST.equalsIgnoreCase(transformedAutomation)) { + return getConvenientClass(declaredClass, annotatedElement, IOS_XCUIT_AUTOMATION); + } + return getConvenientClass(declaredClass, annotatedElement, IOS_UI_AUTOMATION); } + if (WINDOWS.equalsIgnoreCase(transformedPlatform)) { + return getConvenientClass(declaredClass, annotatedElement, WINDOWS_AUTOMATION); + } + return getDefaultOrHTMLWidgetClass(declaredClass, annotatedElement); } diff --git a/src/main/java/io/appium/java_client/pagefactory/WidgetByBuilder.java b/src/main/java/io/appium/java_client/pagefactory/WidgetByBuilder.java index a59493cc1..978e4fbaf 100644 --- a/src/main/java/io/appium/java_client/pagefactory/WidgetByBuilder.java +++ b/src/main/java/io/appium/java_client/pagefactory/WidgetByBuilder.java @@ -18,6 +18,7 @@ import static io.appium.java_client.pagefactory.OverrideWidgetReader.getDefaultOrHTMLWidgetClass; import static io.appium.java_client.pagefactory.OverrideWidgetReader.getMobileNativeWidgetClass; +import static java.util.Optional.ofNullable; import org.openqa.selenium.By; @@ -26,7 +27,6 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.List; -import java.util.Optional; public class WidgetByBuilder extends DefaultElementByBuilder { @@ -92,12 +92,12 @@ private By getByFromDeclaredClass(WhatIsNeeded whatIsNeeded) { } @Override protected By buildDefaultBy() { - return Optional.ofNullable(super.buildDefaultBy()) + return ofNullable(super.buildDefaultBy()) .orElse(getByFromDeclaredClass(WhatIsNeeded.DEFAULT_OR_HTML)); } @Override protected By buildMobileNativeBy() { - return Optional.ofNullable(super.buildMobileNativeBy()) + return ofNullable(super.buildMobileNativeBy()) .orElse(getByFromDeclaredClass(WhatIsNeeded.MOBILE_NATIVE)); } diff --git a/src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java b/src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java index 246ae06cf..279ba4f05 100644 --- a/src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java +++ b/src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java @@ -16,6 +16,11 @@ package io.appium.java_client.pagefactory.utils; +import static io.appium.java_client.pagefactory.bys.ContentType.HTML_OR_DEFAULT; +import static io.appium.java_client.pagefactory.bys.ContentType.NATIVE_MOBILE_SPECIFIC; +import static java.util.Optional.ofNullable; + +import io.appium.java_client.HasSessionDetails; import io.appium.java_client.pagefactory.bys.ContentType; import org.openqa.selenium.ContextAware; import org.openqa.selenium.SearchContext; @@ -84,17 +89,27 @@ public static WebDriver unpackWebDriverFromSearchContext(SearchContext searchCon * {@link org.openqa.selenium.ContextAware} and {@link org.openqa.selenium.internal.WrapsDriver} */ public static ContentType getCurrentContentType(SearchContext context) { - WebDriver driver = WebDriverUnpackUtility.unpackWebDriverFromSearchContext(context); - if (!ContextAware.class.isAssignableFrom(driver.getClass())) { //it is desktop browser - return ContentType.HTML_OR_DEFAULT; - } + return ofNullable(unpackWebDriverFromSearchContext(context)).map(driver -> { + if (HasSessionDetails.class.isAssignableFrom(driver.getClass())) { + HasSessionDetails hasSessionDetails = HasSessionDetails.class.cast(driver); - ContextAware contextAware = ContextAware.class.cast(driver); - String currentContext = contextAware.getContext(); - if (currentContext.contains(NATIVE_APP_PATTERN)) { - return ContentType.NATIVE_MOBILE_SPECIFIC; - } + if (hasSessionDetails.isBrowser()) { + return HTML_OR_DEFAULT; + } + return NATIVE_MOBILE_SPECIFIC; + } + + if (!ContextAware.class.isAssignableFrom(driver.getClass())) { //it is desktop browser + return HTML_OR_DEFAULT; + } + + ContextAware contextAware = ContextAware.class.cast(driver); + String currentContext = contextAware.getContext(); + if (currentContext.contains(NATIVE_APP_PATTERN)) { + return NATIVE_MOBILE_SPECIFIC; + } - return ContentType.HTML_OR_DEFAULT; + return HTML_OR_DEFAULT; + }).orElse(HTML_OR_DEFAULT); } } diff --git a/src/test/java/io/appium/java_client/RottenTomatoes.zip b/src/test/java/io/appium/java_client/RottenTomatoes.zip deleted file mode 100644 index e215950e1..000000000 Binary files a/src/test/java/io/appium/java_client/RottenTomatoes.zip and /dev/null differ diff --git a/src/test/java/io/appium/java_client/RottenTomatoesPageSnapshot.html b/src/test/java/io/appium/java_client/RottenTomatoesPageSnapshot.html deleted file mode 100644 index e64e03732..000000000 --- a/src/test/java/io/appium/java_client/RottenTomatoesPageSnapshot.html +++ /dev/null @@ -1,9304 +0,0 @@ - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -