【发布时间】:2019-07-16 03:14:32
【问题描述】:
【问题讨论】:
标签: android-layout selenium-webdriver android-camera appium
【问题讨论】:
标签: android-layout selenium-webdriver android-camera appium
我使用 TouchAction 实现了这一点。
TouchAction touchAction = new TouchAction(driver); touchAction.tap(new PointOption().withCoordinates(111, 222)).perform()
【讨论】:
请尝试以下代码 sn-p。如果您能够使用 android 键盘单击,那么下面的代码应该可以工作。
((AndroidDriver)driver).pressKey(new KeyEvent(AndroidKey.SEARCH));
【讨论】:
在 appium 中使用相机应用接受图像的解决方案。
keyEvent=>27,用于使用相机应用程序捕获图像。
我使用下面的代码来接受捕获的图像。 (但它不起作用)
我使用 keyEvent=> 66, Enter 按钮来接受图像(但它不起作用)。
我使用 keyEvent=> 84, Space 按钮来接受图像(但它不起作用)。
低于工作代码。
我使用了keyEvent=> 22,然后我使用了keyEvent=> 66,它将接受图像。
$app.press_keycode(27) #click on camera accept button.
$app.press_keycode(22)
$app.press_keycode(66)
sleep 2
$app.press_keycode(27)
$app.press_keycode(22)
$app.press_keycode(66)
注意:将代码重复两次
我使用了keyEvent=> 21,然后我使用了keyEvent=> 66,我使用了keyEvent=> 27,这将允许你重新拍摄图像。
我使用了keyEvent=>4,它会从相机应用程序中收回你
【讨论】:
我最初处理 Camera 和 Tick 按钮的方式是使用 Android Key Codes:
Thread.sleep(2000);
androidDriver.pressKey(new KeyEvent(AndroidKey.CAMERA));
Thread.sleep(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
Thread.sleep(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
Thread.sleep(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.ENTER));
在我之前研究过的大多数设备中,上面的 sn-p 对我来说就像是一种魅力。但是,当我最近开始在 Android 版本 9、10 和 11 上进行测试时,这不起作用,并且选项卡的数量增加到 3 或 4 个。为了在三星、OnePlus、Google Pixel 等大多数设备中处理这个问题,我重构了代码为:
Thread.sleep(2000);
// Click Camera shutter button
androidDriver.pressKey(new KeyEvent(AndroidKey.CAMERA));
try {
WebDriverWait wait = new WebDriverWait(androidDriver, 10);
wait.until(ExpectedConditions.elementToBeClickable((MobileBy.AccessibilityId("Done");
// Click Done or Tick after clicking photo (Mostly visible in OnePlus, Nokia, Google Pixel devices)
androidDriver.findElementByAccessibilityId("Done").click();
} catch (NoSuchElementException e) {
flag = true;
System.out.println("NoSuchElement for DONE Button");
}
if (flag) {
try {
// Click OK after clicking photo (Mostly visible in Samsung devices)
// No need to put WebDriverWait here as we already waited for 10 secs after clicking on Camera
androidDriver.findElementByXPath("//android.widget.TextView[@text='OK']").click();
flag = false;
System.out.println("OK Button Clicked");
} catch (NoSuchElementException e) {
flag = true;
System.out.println("NoSuchElement for OK Button");
}
}
if (flag) {
// If both above methods failed, then this may work (Mostly works for Xiaomi, Nokia devices)
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
hardStopWait(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.TAB));
hardStopWait(1000);
androidDriver.pressKey(new KeyEvent(AndroidKey.ENTER));
System.out.println("TABS & ENTER Pressed");
}
【讨论】: