Skip to content

Commit

Permalink
Merge pull request #669 from TikhomirovSergey/master
Browse files Browse the repository at this point in the history
Finalization of the Widget feature
  • Loading branch information
TikhomirovSergey authored Jul 20, 2017
2 parents 85be19e + 94660c7 commit 8340d5c
Show file tree
Hide file tree
Showing 103 changed files with 1,771 additions and 18,126 deletions.
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 @@ -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);
}

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())
.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

0 comments on commit 8340d5c

Please sign in to comment.