Skip to content

Commit 8340d5c

Browse files
Merge pull request #669 from TikhomirovSergey/master
Finalization of the Widget feature
2 parents 85be19e + 94660c7 commit 8340d5c

File tree

103 files changed

+1771
-18126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1771
-18126
lines changed

src/main/java/io/appium/java_client/ios/PerformsTouchID.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package io.appium.java_client.ios;
1818

19-
import static io.appium.java_client.ios.IOSMobileCommandHelper.touchIdCommand;
2019
import static io.appium.java_client.ios.IOSMobileCommandHelper.toggleTouchIdEnrollmentCommand;
20+
import static io.appium.java_client.ios.IOSMobileCommandHelper.touchIdCommand;
2121

2222
import io.appium.java_client.CommandExecutionHelper;
2323
import io.appium.java_client.ExecutesMethod;

src/main/java/io/appium/java_client/pagefactory/OverrideWidget.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,31 @@
5959
Class<? extends Widget> iOSUIAutomation() default Widget.class;
6060

6161
/**
62-
* This property is designed for Android native content when Selendroid automation is used.
62+
* This property is designed for Android native content when
63+
* {@link io.appium.java_client.remote.AutomationName#SELENDROID} automation is used.
6364
* A declared class should not be abstract. Declared class also should be a subclass
6465
* of an annotated class/class which is declared by an annotated field.
6566
*
6667
* @return a class which extends {@link io.appium.java_client.pagefactory.Widget}
6768
*/
6869
Class<? extends Widget> selendroid() default Widget.class;
70+
71+
/**
72+
* This property is designed for iOS native content when
73+
* {@link io.appium.java_client.remote.AutomationName#IOS_XCUI_TEST} automation is used.
74+
* A declared class should not be abstract. Declared class also should be a subclass
75+
* of an annotated class/class which is declared by an annotated field.
76+
*
77+
* @return a class which extends {@link io.appium.java_client.pagefactory.Widget}
78+
*/
79+
Class<? extends Widget> iOSXCUITAutomation() default Widget.class;
80+
81+
/**
82+
* This property is designed for Windows native content.
83+
* A declared class should not be abstract. Declared class also should be a subclass
84+
* of an annotated class/class which is declared by an annotated field.
85+
*
86+
* @return a class which extends {@link io.appium.java_client.pagefactory.Widget}
87+
*/
88+
Class<? extends Widget> windowsAutomation() default Widget.class;
6989
}

src/main/java/io/appium/java_client/pagefactory/OverrideWidgetReader.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static io.appium.java_client.pagefactory.WidgetConstructorUtil.findConvenientConstructor;
2020
import static io.appium.java_client.remote.MobilePlatform.ANDROID;
2121
import static io.appium.java_client.remote.MobilePlatform.IOS;
22+
import static io.appium.java_client.remote.MobilePlatform.WINDOWS;
2223

2324
import io.appium.java_client.pagefactory.bys.ContentType;
2425
import io.appium.java_client.remote.AutomationName;
@@ -35,6 +36,8 @@ class OverrideWidgetReader {
3536
private static final String ANDROID_UI_AUTOMATOR = "androidUIAutomator";
3637
private static final String IOS_UI_AUTOMATION = "iOSUIAutomation";
3738
private static final String SELENDROID = "selendroid";
39+
private static final String IOS_XCUIT_AUTOMATION = "iOSXCUITAutomation";
40+
private static final String WINDOWS_AUTOMATION = "windowsAutomation";
3841

3942
@SuppressWarnings("unchecked")
4043
private static Class<? extends Widget> getConvenientClass(Class<? extends Widget> declaredClass,
@@ -74,19 +77,26 @@ static Class<? extends Widget> getMobileNativeWidgetClass(Class<? extends Widget
7477
String transformedPlatform = String.valueOf(platform).toUpperCase().trim();
7578
String transformedAutomation = String.valueOf(automation).toUpperCase().trim();
7679

77-
if (ANDROID.equalsIgnoreCase(transformedPlatform) && AutomationName.SELENDROID
78-
.equalsIgnoreCase(transformedAutomation)) {
79-
return getConvenientClass(declaredClass, annotatedElement, SELENDROID);
80-
}
81-
8280
if (ANDROID.equalsIgnoreCase(transformedPlatform)) {
81+
if (AutomationName.SELENDROID.equalsIgnoreCase(transformedAutomation)) {
82+
return getConvenientClass(declaredClass, annotatedElement, SELENDROID);
83+
}
84+
8385
return getConvenientClass(declaredClass, annotatedElement, ANDROID_UI_AUTOMATOR);
8486
}
8587

8688
if (IOS.equalsIgnoreCase(transformedPlatform)) {
89+
if (AutomationName.IOS_XCUI_TEST.equalsIgnoreCase(transformedAutomation)) {
90+
return getConvenientClass(declaredClass, annotatedElement, IOS_XCUIT_AUTOMATION);
91+
}
92+
8793
return getConvenientClass(declaredClass, annotatedElement, IOS_UI_AUTOMATION);
8894
}
8995

96+
if (WINDOWS.equalsIgnoreCase(transformedPlatform)) {
97+
return getConvenientClass(declaredClass, annotatedElement, WINDOWS_AUTOMATION);
98+
}
99+
90100
return getDefaultOrHTMLWidgetClass(declaredClass, annotatedElement);
91101
}
92102

src/main/java/io/appium/java_client/pagefactory/WidgetByBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static io.appium.java_client.pagefactory.OverrideWidgetReader.getDefaultOrHTMLWidgetClass;
2020
import static io.appium.java_client.pagefactory.OverrideWidgetReader.getMobileNativeWidgetClass;
21+
import static java.util.Optional.ofNullable;
2122

2223
import org.openqa.selenium.By;
2324

@@ -26,7 +27,6 @@
2627
import java.lang.reflect.ParameterizedType;
2728
import java.lang.reflect.Type;
2829
import java.util.List;
29-
import java.util.Optional;
3030

3131
public class WidgetByBuilder extends DefaultElementByBuilder {
3232

@@ -92,12 +92,12 @@ private By getByFromDeclaredClass(WhatIsNeeded whatIsNeeded) {
9292
}
9393

9494
@Override protected By buildDefaultBy() {
95-
return Optional.ofNullable(super.buildDefaultBy())
95+
return ofNullable(super.buildDefaultBy())
9696
.orElse(getByFromDeclaredClass(WhatIsNeeded.DEFAULT_OR_HTML));
9797
}
9898

9999
@Override protected By buildMobileNativeBy() {
100-
return Optional.ofNullable(super.buildMobileNativeBy())
100+
return ofNullable(super.buildMobileNativeBy())
101101
.orElse(getByFromDeclaredClass(WhatIsNeeded.MOBILE_NATIVE));
102102
}
103103

src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
package io.appium.java_client.pagefactory.utils;
1818

19+
import static io.appium.java_client.pagefactory.bys.ContentType.HTML_OR_DEFAULT;
20+
import static io.appium.java_client.pagefactory.bys.ContentType.NATIVE_MOBILE_SPECIFIC;
21+
import static java.util.Optional.ofNullable;
22+
23+
import io.appium.java_client.HasSessionDetails;
1924
import io.appium.java_client.pagefactory.bys.ContentType;
2025
import org.openqa.selenium.ContextAware;
2126
import org.openqa.selenium.SearchContext;
@@ -84,17 +89,27 @@ public static WebDriver unpackWebDriverFromSearchContext(SearchContext searchCon
8489
* {@link org.openqa.selenium.ContextAware} and {@link org.openqa.selenium.internal.WrapsDriver}
8590
*/
8691
public static ContentType getCurrentContentType(SearchContext context) {
87-
WebDriver driver = WebDriverUnpackUtility.unpackWebDriverFromSearchContext(context);
88-
if (!ContextAware.class.isAssignableFrom(driver.getClass())) { //it is desktop browser
89-
return ContentType.HTML_OR_DEFAULT;
90-
}
92+
return ofNullable(unpackWebDriverFromSearchContext(context)).map(driver -> {
93+
if (HasSessionDetails.class.isAssignableFrom(driver.getClass())) {
94+
HasSessionDetails hasSessionDetails = HasSessionDetails.class.cast(driver);
9195

92-
ContextAware contextAware = ContextAware.class.cast(driver);
93-
String currentContext = contextAware.getContext();
94-
if (currentContext.contains(NATIVE_APP_PATTERN)) {
95-
return ContentType.NATIVE_MOBILE_SPECIFIC;
96-
}
96+
if (hasSessionDetails.isBrowser()) {
97+
return HTML_OR_DEFAULT;
98+
}
99+
return NATIVE_MOBILE_SPECIFIC;
100+
}
101+
102+
if (!ContextAware.class.isAssignableFrom(driver.getClass())) { //it is desktop browser
103+
return HTML_OR_DEFAULT;
104+
}
105+
106+
ContextAware contextAware = ContextAware.class.cast(driver);
107+
String currentContext = contextAware.getContext();
108+
if (currentContext.contains(NATIVE_APP_PATTERN)) {
109+
return NATIVE_MOBILE_SPECIFIC;
110+
}
97111

98-
return ContentType.HTML_OR_DEFAULT;
112+
return HTML_OR_DEFAULT;
113+
}).orElse(HTML_OR_DEFAULT);
99114
}
100115
}
Binary file not shown.

0 commit comments

Comments
 (0)