未验证 提交 9e59b56b 编写于 作者: M Mykola Mokhnach 提交者: GitHub

fix: Parse platformName if it is passed as enum item (#1369)

上级 b31a6d8d
...@@ -4,24 +4,24 @@ ...@@ -4,24 +4,24 @@
# https://docs.microsoft.com/azure/devops/pipelines/languages/java # https://docs.microsoft.com/azure/devops/pipelines/languages/java
pool: pool:
vmImage: 'macOS 10.14' vmImage: 'macOS-10.15'
variables: variables:
ANDROID_EMU_NAME: test ANDROID_EMU_NAME: test
ANDROID_EMU_ABI: x86 ANDROID_EMU_ABI: x86
ANDROID_EMU_TARGET: android-27 ANDROID_EMU_TARGET: android-27
ANDROID_EMU_TAG: google_apis ANDROID_EMU_TAG: google_apis
XCODE_VERSION: 10.2 XCODE_VERSION: 11.5
IOS_PLATFORM_VERSION: 12.2 IOS_PLATFORM_VERSION: 13.5
IOS_DEVICE_NAME: iPhone X IOS_DEVICE_NAME: iPhone X
jobs: jobs:
- job: E2E_Tests - job: E2E_Tests
timeoutInMinutes: 60 timeoutInMinutes: '60'
steps: steps:
- task: NodeTool@0 - task: NodeTool@0
inputs: inputs:
versionSpec: '11.x' versionSpec: '12.x'
- script: | - script: |
echo "Configuring Environment" echo "Configuring Environment"
......
...@@ -40,6 +40,7 @@ import org.openqa.selenium.WebDriverException; ...@@ -40,6 +40,7 @@ import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.html5.Location; import org.openqa.selenium.html5.Location;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.DriverCommand; import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.ErrorHandler; import org.openqa.selenium.remote.ErrorHandler;
...@@ -316,7 +317,8 @@ public class AppiumDriver<T extends WebElement> ...@@ -316,7 +317,8 @@ public class AppiumDriver<T extends WebElement>
@Override @Override
public boolean isBrowser() { public boolean isBrowser() {
String browserName = CapabilityHelpers.getCapability(getCapabilities(), "browserName", String.class); String browserName = CapabilityHelpers.getCapability(getCapabilities(),
CapabilityType.BROWSER_NAME, String.class);
if (!isBlank(browserName)) { if (!isBlank(browserName)) {
try { try {
return (boolean) executeScript("return !!window.navigator;"); return (boolean) executeScript("return !!window.navigator;");
......
...@@ -43,8 +43,14 @@ public class CapabilityHelpers { ...@@ -43,8 +43,14 @@ public class CapabilityHelpers {
possibleNames.add(APPIUM_PREFIX + name); possibleNames.add(APPIUM_PREFIX + name);
} }
for (String capName : possibleNames) { for (String capName : possibleNames) {
if (caps.getCapability(capName) != null if (caps.getCapability(capName) == null) {
&& expectedType.isAssignableFrom(caps.getCapability(capName).getClass())) { continue;
}
if (expectedType == String.class) {
return expectedType.cast(String.valueOf(caps.getCapability(capName)));
}
if (expectedType.isAssignableFrom(caps.getCapability(capName).getClass())) {
return expectedType.cast(caps.getCapability(capName)); return expectedType.cast(caps.getCapability(capName));
} }
} }
......
...@@ -18,8 +18,10 @@ package io.appium.java_client.internal; ...@@ -18,8 +18,10 @@ package io.appium.java_client.internal;
import static io.appium.java_client.internal.ElementMap.getElementClass; import static io.appium.java_client.internal.ElementMap.getElementClass;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.Capabilities; import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.RemoteWebElement; import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.remote.internal.JsonToWebElementConverter; import org.openqa.selenium.remote.internal.JsonToWebElementConverter;
...@@ -46,8 +48,8 @@ public class JsonToMobileElementConverter extends JsonToWebElementConverter { ...@@ -46,8 +48,8 @@ public class JsonToMobileElementConverter extends JsonToWebElementConverter {
super(driver); super(driver);
this.driver = driver; this.driver = driver;
Capabilities caps = driver.getCapabilities(); Capabilities caps = driver.getCapabilities();
this.platform = CapabilityHelpers.getCapability(caps, "platformName", String.class); this.platform = CapabilityHelpers.getCapability(caps, CapabilityType.PLATFORM_NAME, String.class);
this.automation = CapabilityHelpers.getCapability(caps, "automationName", String.class); this.automation = CapabilityHelpers.getCapability(caps, MobileCapabilityType.AUTOMATION_NAME, String.class);
} }
@Override @Override
......
...@@ -29,13 +29,14 @@ import io.appium.java_client.internal.CapabilityHelpers; ...@@ -29,13 +29,14 @@ import io.appium.java_client.internal.CapabilityHelpers;
import io.appium.java_client.ios.IOSElement; import io.appium.java_client.ios.IOSElement;
import io.appium.java_client.pagefactory.bys.ContentType; import io.appium.java_client.pagefactory.bys.ContentType;
import io.appium.java_client.pagefactory.locator.CacheableLocator; import io.appium.java_client.pagefactory.locator.CacheableLocator;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.windows.WindowsElement; import io.appium.java_client.windows.WindowsElement;
import org.openqa.selenium.Capabilities; import org.openqa.selenium.Capabilities;
import org.openqa.selenium.HasCapabilities; import org.openqa.selenium.HasCapabilities;
import org.openqa.selenium.SearchContext; import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.RemoteWebElement; import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator; import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator;
import org.openqa.selenium.support.pagefactory.ElementLocator; import org.openqa.selenium.support.pagefactory.ElementLocator;
...@@ -49,6 +50,7 @@ import java.lang.reflect.TypeVariable; ...@@ -49,6 +50,7 @@ import java.lang.reflect.TypeVariable;
import java.time.Duration; import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -88,8 +90,8 @@ public class AppiumFieldDecorator implements FieldDecorator { ...@@ -88,8 +90,8 @@ public class AppiumFieldDecorator implements FieldDecorator {
if (this.webDriver instanceof HasCapabilities) { if (this.webDriver instanceof HasCapabilities) {
Capabilities caps = ((HasCapabilities) this.webDriver).getCapabilities(); Capabilities caps = ((HasCapabilities) this.webDriver).getCapabilities();
this.platform = CapabilityHelpers.getCapability(caps, "platformName", String.class); this.platform = CapabilityHelpers.getCapability(caps, CapabilityType.PLATFORM_NAME, String.class);
this.automation = CapabilityHelpers.getCapability(caps, "automationName", String.class); this.automation = CapabilityHelpers.getCapability(caps, MobileCapabilityType.AUTOMATION_NAME, String.class);
} else { } else {
this.platform = null; this.platform = null;
this.automation = null; this.automation = null;
...@@ -107,8 +109,7 @@ public class AppiumFieldDecorator implements FieldDecorator { ...@@ -107,8 +109,7 @@ public class AppiumFieldDecorator implements FieldDecorator {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected List<WebElement> proxyForListLocator(ClassLoader ignored, protected List<WebElement> proxyForListLocator(ClassLoader ignored, ElementLocator locator) {
ElementLocator locator) {
ElementListInterceptor elementInterceptor = new ElementListInterceptor(locator); ElementListInterceptor elementInterceptor = new ElementListInterceptor(locator);
return getEnhancedProxy(ArrayList.class, elementInterceptor); return getEnhancedProxy(ArrayList.class, elementInterceptor);
} }
...@@ -125,19 +126,12 @@ public class AppiumFieldDecorator implements FieldDecorator { ...@@ -125,19 +126,12 @@ public class AppiumFieldDecorator implements FieldDecorator {
} }
Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0]; Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];
List<Type> bounds = (listType instanceof TypeVariable)
? Arrays.asList(((TypeVariable<?>) listType).getBounds())
: Collections.emptyList();
for (Class<? extends WebElement> webElementClass : availableElementClasses) { return availableElementClasses.stream()
if (webElementClass.equals(listType)) { .anyMatch((webElClass) -> webElClass.equals(listType) || bounds.contains(webElClass));
return true;
}
}
if ((listType instanceof TypeVariable)
&& Arrays.asList(((TypeVariable<?>) listType).getBounds())
.stream().anyMatch(item -> availableElementClasses.contains(item))) {
return true;
}
return false;
} }
}; };
...@@ -188,10 +182,10 @@ public class AppiumFieldDecorator implements FieldDecorator { ...@@ -188,10 +182,10 @@ public class AppiumFieldDecorator implements FieldDecorator {
} }
if (listType instanceof Class) { if (listType instanceof Class) {
if (!Widget.class.isAssignableFrom((Class) listType)) { if (!Widget.class.isAssignableFrom((Class<?>) listType)) {
return null; return null;
} }
widgetType = Class.class.cast(listType); widgetType = (Class<? extends Widget>) listType;
} else { } else {
return null; return null;
} }
......
...@@ -5,7 +5,6 @@ import static io.appium.java_client.touch.TapOptions.tapOptions; ...@@ -5,7 +5,6 @@ import static io.appium.java_client.touch.TapOptions.tapOptions;
import static io.appium.java_client.touch.WaitOptions.waitOptions; import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static io.appium.java_client.touch.offset.ElementOption.element; import static io.appium.java_client.touch.offset.ElementOption.element;
import static java.time.Duration.ofMillis; import static java.time.Duration.ofMillis;
import static java.time.Duration.ofSeconds;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent; import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
...@@ -13,11 +12,9 @@ import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent; ...@@ -13,11 +12,9 @@ import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
import io.appium.java_client.MobileElement; import io.appium.java_client.MobileElement;
import io.appium.java_client.MultiTouchAction; import io.appium.java_client.MultiTouchAction;
import io.appium.java_client.TouchAction; import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.offset.ElementOption;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.WebDriverWait;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
...@@ -33,7 +30,7 @@ public class IOSTouchTest extends AppIOSTest { ...@@ -33,7 +30,7 @@ public class IOSTouchTest extends AppIOSTest {
intB.sendKeys("4"); intB.sendKeys("4");
MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton"); MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton");
new TouchAction(driver).tap(tapOptions().withElement(element(e))).perform(); new IOSTouchAction(driver).tap(tapOptions().withElement(element(e))).perform();
assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6"); assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6");
} }
...@@ -57,28 +54,12 @@ public class IOSTouchTest extends AppIOSTest { ...@@ -57,28 +54,12 @@ public class IOSTouchTest extends AppIOSTest {
assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6"); assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6");
} }
@Test public void swipeTest() {
WebDriverWait webDriverWait = new WebDriverWait(driver, 30);
IOSElement slider = webDriverWait.until(driver1 -> driver.findElementByClassName("XCUIElementTypeSlider"));
Dimension size = slider.getSize();
ElementOption press = element(slider, size.width / 2 + 2, size.height / 2);
ElementOption move = element(slider, 1, size.height / 2);
TouchAction swipe = new TouchAction(driver).press(press)
.waitAction(waitOptions(ofSeconds(2)))
.moveTo(move).release();
swipe.perform();
assertEquals("0%", slider.getAttribute("value"));
}
@Test public void multiTouchTest() { @Test public void multiTouchTest() {
MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton"); MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton");
MobileElement e2 = driver.findElementByAccessibilityId("show alert"); MobileElement e2 = driver.findElementByAccessibilityId("show alert");
TouchAction tap1 = new TouchAction(driver).tap(tapOptions().withElement(element(e))); IOSTouchAction tap1 = new IOSTouchAction(driver).tap(tapOptions().withElement(element(e)));
TouchAction tap2 = new TouchAction(driver).tap(tapOptions().withElement(element(e2))); IOSTouchAction tap2 = new IOSTouchAction(driver).tap(tapOptions().withElement(element(e2)));
new MultiTouchAction(driver).add(tap1).add(tap2).perform(); new MultiTouchAction(driver).add(tap1).add(tap2).perform();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册