Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -83,10 +86,19 @@ static Class<? extends Widget> getMobileNativeWidgetClass(Class<? extends Widget
return getConvenientClass(declaredClass, annotatedElement, ANDROID_UI_AUTOMATOR);
}

if (IOS.equalsIgnoreCase(transformedPlatform) && AutomationName.IOS_XCUI_TEST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather added this condition under single IOS.equalsIgnoreCase(transformedPlatform) condition. One might forget about the fact, that conditions order matters here, having the current implementation.

.equalsIgnoreCase(transformedAutomation)) {
return getConvenientClass(declaredClass, annotatedElement, IOS_XCUIT_AUTOMATION);
}

if (IOS.equalsIgnoreCase(transformedPlatform)) {
return getConvenientClass(declaredClass, annotatedElement, IOS_UI_AUTOMATION);
}

if (WINDOWS.equalsIgnoreCase(transformedPlatform)) {
return getConvenientClass(declaredClass, annotatedElement, WINDOWS_AUTOMATION);
}

return getDefaultOrHTMLWidgetClass(declaredClass, annotatedElement);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {

Expand Down Expand Up @@ -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())
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Jul 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the super.buildMobileNativeBy marked as Nullable?

.orElse(getByFromDeclaredClass(WhatIsNeeded.MOBILE_NATIVE));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Binary file not shown.
Loading