在我本地运行 2.0.1 的 appium 上,这是有效的:
WebElement element = assertElement(new AppiumBy.ByAndroidUIAutomator("new UiSelector().resourceId(\"" + resourceId + "\")"));
//logic to long press on my to do
TouchAction action = new TouchAction(driver);
action.longPress(ElementOption.element(element)).release().perform();
但是,在从 jenkins 运行的远程 appium 上,我有 2.5.1,然后我得到:
org.openqa.selenium.UnsupportedCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
Build info: version: '4.9.1', revision: 'eb2032df7f'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '14.0', java.version: '20.0.2'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [34caf98b-9993-44bb-8b5b-06f8db975aec, performTouchAction {actions=[{action=longPress, options={duration=2000, element=00000000-0000-0144-0000-0110000000af}}, {action=release, options={}}]}]
Capabilities {appium:app: /Users/testlaptopmac/Downlo..., appium:appPackage: com.xelion8.android.debug, appium:applicationName: xcover5, appium:autoGrantPermissions: true, appium:automationName: UiAutomator2, appium:databaseEnabled: false, appium:desired: {app: /Users/testlaptopmac/Downlo..., applicationName: xcover5, autoGrantPermissions: true, automationName: UiAutomator2, deviceName: xcover5, platformName: ANDROID, udid: R58T70RWNTZ}, appium:deviceApiLevel: 33, appium:deviceManufacturer: samsung, appium:deviceModel: SM-G525F, appium:deviceName: R58T70RWNTZ, appium:deviceScreenDensity: 340, appium:deviceScreenSize: 720x1480, appium:deviceUDID: R58T70RWNTZ, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:networkConnectionEnabled: true, appium:pixelRatio: 2.125, appium:platformVersion: 13, appium:statBarHeight: 51, appium:takesScreenshot: true, appium:udid: R58T70RWNTZ, appium:viewportRect: {height: 1429, left: 0, top: 51, width: 720}, appium:warnings: {}, appium:webStorageEnabled: false, platformName: ANDROID, se:bidiEnabled: false, se:cdpEnabled: false}
Session ID: 34caf98b-9993-44bb-8b5b-06f8db975aec
我尝试检查文档,但我不明白发生了什么变化,或者要替换什么,请帮助
这是我的设置:
UiAutomator2Options options = new UiAutomator2Options().setApp(androidInfo.apkUrl())
.setAutoGrantPermissions(androidInfo.autoGrantPermissions())
.setDeviceName(androidInfo.device());
driver = new AndroidDriver(testGridInfo.url(), options);
编辑:
我设法像这样“点击”:但我需要“长按” 有什么想法吗?
int x = element.getLocation().getX() + (size.width / 2);
int y = element.getLocation().getY() + (size.height / 2);
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence tap = new Sequence(finger, 1);
tap.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), x, y));
tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
waitForTime(2000); //simulate long press
tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(Arrays.asList(tap));
我是这样处理的:
WebElement element = assertElement(new AppiumBy.ByAndroidUIAutomator("new UiSelector().resourceId(\"" + resourceId + "\")"));
//logic to long press on my to do
Dimension size = element.getSize();
int x = element.getLocation().getX() + (size.width / 2);
int y = element.getLocation().getY() + (size.height / 2);
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence tap = new Sequence(finger, 1);
tap.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), x, y));
tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
tap.addAction(new Pause(finger, Duration.ofMillis(2000)));
tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(Arrays.asList(tap));