【发布时间】:2018-01-26 03:29:38
【问题描述】:
在我使用 Appium 测试 React Native 移动应用程序的初始概念验证中,我注意到当我加载 APK 开始测试时,我会看到一个 Android 提示“允许在其他应用程序上绘图”,就像我一样创建我的 AndroidDriver 驱动程序。如果我手动移动滑块,然后单击后退按钮,一切都很好——应用程序完全加载,我的测试继续进行。但是,我看不到如何使用我的 Appium 脚本自动执行此操作,因为看起来驱动程序实例化在滑块移动之前不会完成。
大多数人在 Appium 测试中看不到这一点,因为它似乎特定于开发模式下的 React Native,如此处所示...
这是我的代码,我在其中放入条件代码以单击滑块,但我从未到达那里,因为它在“driver = ...”行等待:
AndroidDriver driver = null;
@Before
public void setUp() throws Exception {
// < defining capabilities (emulator6p) up here...>
// initialize driver object
try {
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), emulator6p);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
}
@Test
public void test1() throws Exception {
By BY_slider_permitDrawing = By.id("android:id/switchWidget");
boolean present = (driver.findElements(BY_slider_permitDrawing).size() == 1);
if (present) {
driver.findElement(BY_slider_permitDrawing).click();
driver.navigate().back();
}
WebElement button_begin = driver.findElementByAccessibilityId("button-lets-begin");
button_begin.click();
}
我确实听到很多人说 Appium 是 React Native 测试的可行解决方案,并且确实需要克服这个困难。
提前感谢您的任何建议!
jph
附言如果不是很清楚,如果我没有从头开始加载 APK,测试不会挂在“driver =”行,但我需要在未来进行 CI 测试。
【问题讨论】:
-
它将在调试版本中提供。发布版没有这个问题
-
Paras,我假设您指的是 react native 应用程序的发布/生产版本。我需要使用调试版本,因为使用 ID 为各种组件播种的策略如下... testProps = (id) => { if (DEV) { return {testID: id, accessibilityLabel : id} } }
标签: react-native appium react-native-android