Skip to content

Commit 9e59b56

Browse files
fix: Parse platformName if it is passed as enum item (#1369)
1 parent b31a6d8 commit 9e59b56

File tree

6 files changed

+36
-51
lines changed

6 files changed

+36
-51
lines changed

azure-pipelines.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
55

66
pool:
7-
vmImage: 'macOS 10.14'
7+
vmImage: 'macOS-10.15'
88

99
variables:
1010
ANDROID_EMU_NAME: test
1111
ANDROID_EMU_ABI: x86
1212
ANDROID_EMU_TARGET: android-27
1313
ANDROID_EMU_TAG: google_apis
14-
XCODE_VERSION: 10.2
15-
IOS_PLATFORM_VERSION: 12.2
14+
XCODE_VERSION: 11.5
15+
IOS_PLATFORM_VERSION: 13.5
1616
IOS_DEVICE_NAME: iPhone X
1717

1818
jobs:
1919
- job: E2E_Tests
20-
timeoutInMinutes: 60
20+
timeoutInMinutes: '60'
2121
steps:
2222
- task: NodeTool@0
2323
inputs:
24-
versionSpec: '11.x'
24+
versionSpec: '12.x'
2525

2626
- script: |
2727
echo "Configuring Environment"

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.openqa.selenium.WebElement;
4141
import org.openqa.selenium.html5.Location;
4242

43+
import org.openqa.selenium.remote.CapabilityType;
4344
import org.openqa.selenium.remote.DesiredCapabilities;
4445
import org.openqa.selenium.remote.DriverCommand;
4546
import org.openqa.selenium.remote.ErrorHandler;
@@ -316,7 +317,8 @@ public URL getRemoteAddress() {
316317

317318
@Override
318319
public boolean isBrowser() {
319-
String browserName = CapabilityHelpers.getCapability(getCapabilities(), "browserName", String.class);
320+
String browserName = CapabilityHelpers.getCapability(getCapabilities(),
321+
CapabilityType.BROWSER_NAME, String.class);
320322
if (!isBlank(browserName)) {
321323
try {
322324
return (boolean) executeScript("return !!window.navigator;");

src/main/java/io/appium/java_client/internal/CapabilityHelpers.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ public static <T> T getCapability(Capabilities caps, String name, Class<T> expec
4343
possibleNames.add(APPIUM_PREFIX + name);
4444
}
4545
for (String capName : possibleNames) {
46-
if (caps.getCapability(capName) != null
47-
&& expectedType.isAssignableFrom(caps.getCapability(capName).getClass())) {
46+
if (caps.getCapability(capName) == null) {
47+
continue;
48+
}
49+
50+
if (expectedType == String.class) {
51+
return expectedType.cast(String.valueOf(caps.getCapability(capName)));
52+
}
53+
if (expectedType.isAssignableFrom(caps.getCapability(capName).getClass())) {
4854
return expectedType.cast(caps.getCapability(capName));
4955
}
5056
}

src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
import static io.appium.java_client.internal.ElementMap.getElementClass;
2020

21+
import io.appium.java_client.remote.MobileCapabilityType;
2122
import org.openqa.selenium.Capabilities;
2223
import org.openqa.selenium.WebDriverException;
24+
import org.openqa.selenium.remote.CapabilityType;
2325
import org.openqa.selenium.remote.RemoteWebDriver;
2426
import org.openqa.selenium.remote.RemoteWebElement;
2527
import org.openqa.selenium.remote.internal.JsonToWebElementConverter;
@@ -46,8 +48,8 @@ public JsonToMobileElementConverter(RemoteWebDriver driver) {
4648
super(driver);
4749
this.driver = driver;
4850
Capabilities caps = driver.getCapabilities();
49-
this.platform = CapabilityHelpers.getCapability(caps, "platformName", String.class);
50-
this.automation = CapabilityHelpers.getCapability(caps, "automationName", String.class);
51+
this.platform = CapabilityHelpers.getCapability(caps, CapabilityType.PLATFORM_NAME, String.class);
52+
this.automation = CapabilityHelpers.getCapability(caps, MobileCapabilityType.AUTOMATION_NAME, String.class);
5153
}
5254

5355
@Override

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
import io.appium.java_client.ios.IOSElement;
3030
import io.appium.java_client.pagefactory.bys.ContentType;
3131
import io.appium.java_client.pagefactory.locator.CacheableLocator;
32+
import io.appium.java_client.remote.MobileCapabilityType;
3233
import io.appium.java_client.windows.WindowsElement;
3334
import org.openqa.selenium.Capabilities;
3435
import org.openqa.selenium.HasCapabilities;
3536
import org.openqa.selenium.SearchContext;
3637
import org.openqa.selenium.WebDriver;
3738
import org.openqa.selenium.WebElement;
38-
import org.openqa.selenium.remote.RemoteWebDriver;
39+
import org.openqa.selenium.remote.CapabilityType;
3940
import org.openqa.selenium.remote.RemoteWebElement;
4041
import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator;
4142
import org.openqa.selenium.support.pagefactory.ElementLocator;
@@ -49,6 +50,7 @@
4950
import java.time.Duration;
5051
import java.util.ArrayList;
5152
import java.util.Arrays;
53+
import java.util.Collections;
5254
import java.util.List;
5355
import java.util.Map;
5456

@@ -88,8 +90,8 @@ public AppiumFieldDecorator(SearchContext context, Duration duration) {
8890

8991
if (this.webDriver instanceof HasCapabilities) {
9092
Capabilities caps = ((HasCapabilities) this.webDriver).getCapabilities();
91-
this.platform = CapabilityHelpers.getCapability(caps, "platformName", String.class);
92-
this.automation = CapabilityHelpers.getCapability(caps, "automationName", String.class);
93+
this.platform = CapabilityHelpers.getCapability(caps, CapabilityType.PLATFORM_NAME, String.class);
94+
this.automation = CapabilityHelpers.getCapability(caps, MobileCapabilityType.AUTOMATION_NAME, String.class);
9395
} else {
9496
this.platform = null;
9597
this.automation = null;
@@ -107,8 +109,7 @@ protected WebElement proxyForLocator(ClassLoader ignored, ElementLocator locator
107109

108110
@Override
109111
@SuppressWarnings("unchecked")
110-
protected List<WebElement> proxyForListLocator(ClassLoader ignored,
111-
ElementLocator locator) {
112+
protected List<WebElement> proxyForListLocator(ClassLoader ignored, ElementLocator locator) {
112113
ElementListInterceptor elementInterceptor = new ElementListInterceptor(locator);
113114
return getEnhancedProxy(ArrayList.class, elementInterceptor);
114115
}
@@ -125,19 +126,12 @@ protected boolean isDecoratableList(Field field) {
125126
}
126127

127128
Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];
129+
List<Type> bounds = (listType instanceof TypeVariable)
130+
? Arrays.asList(((TypeVariable<?>) listType).getBounds())
131+
: Collections.emptyList();
128132

129-
for (Class<? extends WebElement> webElementClass : availableElementClasses) {
130-
if (webElementClass.equals(listType)) {
131-
return true;
132-
}
133-
}
134-
135-
if ((listType instanceof TypeVariable)
136-
&& Arrays.asList(((TypeVariable<?>) listType).getBounds())
137-
.stream().anyMatch(item -> availableElementClasses.contains(item))) {
138-
return true;
139-
}
140-
return false;
133+
return availableElementClasses.stream()
134+
.anyMatch((webElClass) -> webElClass.equals(listType) || bounds.contains(webElClass));
141135
}
142136
};
143137

@@ -188,10 +182,10 @@ private Object decorateWidget(Field field) {
188182
}
189183

190184
if (listType instanceof Class) {
191-
if (!Widget.class.isAssignableFrom((Class) listType)) {
185+
if (!Widget.class.isAssignableFrom((Class<?>) listType)) {
192186
return null;
193187
}
194-
widgetType = Class.class.cast(listType);
188+
widgetType = (Class<? extends Widget>) listType;
195189
} else {
196190
return null;
197191
}

src/test/java/io/appium/java_client/ios/IOSTouchTest.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55
import static io.appium.java_client.touch.WaitOptions.waitOptions;
66
import static io.appium.java_client.touch.offset.ElementOption.element;
77
import static java.time.Duration.ofMillis;
8-
import static java.time.Duration.ofSeconds;
98
import static org.junit.Assert.assertEquals;
109
import static org.junit.Assert.assertNotNull;
1110
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
1211

1312
import io.appium.java_client.MobileElement;
1413
import io.appium.java_client.MultiTouchAction;
1514
import io.appium.java_client.TouchAction;
16-
import io.appium.java_client.touch.offset.ElementOption;
1715
import org.junit.FixMethodOrder;
1816
import org.junit.Test;
1917
import org.junit.runners.MethodSorters;
20-
import org.openqa.selenium.Dimension;
2118
import org.openqa.selenium.support.ui.WebDriverWait;
2219

2320
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -33,7 +30,7 @@ public void tapTest() {
3330
intB.sendKeys("4");
3431

3532
MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton");
36-
new TouchAction(driver).tap(tapOptions().withElement(element(e))).perform();
33+
new IOSTouchAction(driver).tap(tapOptions().withElement(element(e))).perform();
3734
assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6");
3835
}
3936

@@ -57,28 +54,12 @@ public void touchWithPressureTest() {
5754
assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6");
5855
}
5956

60-
@Test public void swipeTest() {
61-
WebDriverWait webDriverWait = new WebDriverWait(driver, 30);
62-
IOSElement slider = webDriverWait.until(driver1 -> driver.findElementByClassName("XCUIElementTypeSlider"));
63-
Dimension size = slider.getSize();
64-
65-
ElementOption press = element(slider, size.width / 2 + 2, size.height / 2);
66-
ElementOption move = element(slider, 1, size.height / 2);
67-
68-
TouchAction swipe = new TouchAction(driver).press(press)
69-
.waitAction(waitOptions(ofSeconds(2)))
70-
.moveTo(move).release();
71-
72-
swipe.perform();
73-
assertEquals("0%", slider.getAttribute("value"));
74-
}
75-
7657
@Test public void multiTouchTest() {
7758
MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton");
7859
MobileElement e2 = driver.findElementByAccessibilityId("show alert");
7960

80-
TouchAction tap1 = new TouchAction(driver).tap(tapOptions().withElement(element(e)));
81-
TouchAction tap2 = new TouchAction(driver).tap(tapOptions().withElement(element(e2)));
61+
IOSTouchAction tap1 = new IOSTouchAction(driver).tap(tapOptions().withElement(element(e)));
62+
IOSTouchAction tap2 = new IOSTouchAction(driver).tap(tapOptions().withElement(element(e2)));
8263

8364
new MultiTouchAction(driver).add(tap1).add(tap2).perform();
8465

0 commit comments

Comments
 (0)