java - Appium 测试在我们应用程序的先前版本中有效,但在我们应用程序的新版本中并非全部有效
问题描述
当我们在 2.4.0 版本中运行我们的 appium 测试时,他们的通过率是 100%。但是,在我们的新版本 2.5.0 中,一些测试失败了。
他们失败了,因为在某些屏幕上他们找不到元素。元素的 id 在 2.5.0 中与在 2.4.0 中完全相同。
我确保它正在等待屏幕加载。发生的情况是它会通过几个屏幕然后总是卡在同一个屏幕上并在我设置的超时时间内坐在那里然后失败说它无法找到元素。
以下是测试进入输入名称屏幕时的 appium 日志。它应该找到名字字段,并发送文本。
> [debug] [MJSONWP] Calling AppiumDriver.findElement() with args:
> ["id","Step3.firstname","489801e6-96d8-45f8-9712-0c2ec940413b"]
> [debug] [BaseDriver] Valid locator strategies for this request: xpath,
> id, class name, accessibility id, -android uiautomator [debug]
> [BaseDriver] Waiting up to 0 ms for condition [debug]
> [AndroidBootstrap] Sending command to android:
> {"cmd":"action","action":"find","params":{"strategy":"id","selector":"Step3.firstname","context":"","multiple":false}}
> [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from
> client:
> {"cmd":"action","action":"find","params":{"strategy":"id","selector":"Step3.firstname","context":"","multiple":false}}
> [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type
> ACTION [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command
> action: find [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug]
> Finding 'Step3.firstname' using 'ID' with the contextId: '' multiple:
> false [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using:
> UiSelector[INSTANCE=0,
> RESOURCE_ID=com.readytouchpos.smallstore:id/Step3.firstname] [debug]
> [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using:
> UiSelector[INSTANCE=0, RESOURCE_ID=android:id/Step3.firstname] [debug]
> [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using:
> UiSelector[INSTANCE=0, RESOURCE_ID=Step3.firstname] [debug]
> [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using:
> UiSelector[DESCRIPTION=Step3.firstname, INSTANCE=0] [debug]
> [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element.
> Clearing Accessibility cache and retrying. [debug] [AndroidBootstrap]
> [BOOTSTRAP LOG] [debug] Finding 'Step3.firstname' using 'ID' with the
> contextId: '' multiple: false [debug] [AndroidBootstrap] [BOOTSTRAP
> LOG] [debug] Using: UiSelector[INSTANCE=0,
> RESOURCE_ID=com.readytouchpos.smallstore:id/Step3.firstname] [debug]
> [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using:
> UiSelector[INSTANCE=0, RESOURCE_ID=android:id/Step3.firstname] [debug]
> [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using:
> UiSelector[INSTANCE=0, RESOURCE_ID=Step3.firstname] [debug]
> [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using:
> UiSelector[DESCRIPTION=Step3.firstname, INSTANCE=0] [debug]
> [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result:
> {"status":7,"value":"No element found"} [debug] [AndroidBootstrap]
> Received command result from bootstrap [debug] [MJSONWP] Matched
> JSONWP error code 7 to NoSuchElementError [debug] [MJSONWP]
> Encountered internal error running command: NoSuchElementError: An
> element could not be located on the page using the given search
> parameters. [debug] [MJSONWP] at AndroidDriver.callee$0$0$
> (C:\Users\arroy\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:75:11)
> [debug] [MJSONWP] at tryCatch
> (C:\Users\arroy\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
> [debug] [MJSONWP] at GeneratorFunctionPrototype.invoke [as
> _invoke] (C:\Users\arroy\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
> [debug] [MJSONWP] at
> GeneratorFunctionPrototype.prototype.(anonymous function) [as throw]
> (C:\Users\arroy\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
> [debug] [MJSONWP] at GeneratorFunctionPrototype.invoke
> (C:\Users\arroy\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
> [debug] [MJSONWP] at <anonymous>
这是用于将密钥发送到名字字段的方法:
> public EnterNameScreen typeFirstName(String firstName){
> waitForElement(firstNameTextBox).sendKeys(firstName);
> return this;
> }
这是 typeFirstName 方法中使用的 wait 方法:
protected WebElement waitForElement(By locator) {
int count = 0;
int maxTries = 3;
while(true) {
try {
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(ExpectedConditions.visibilityOfElementLocated((locator)));
return driver.findElement(locator);
} catch (Exception e) {
// handle exception
if (++count == maxTries) throw e;
}
}
}
请记住,这些在我们的 2.4.0 版本中运行良好。仅在我们的新版本 2.5.0 中,它才停止工作。一些按钮仍然按预期被点击,一些字段仍然按预期收到发送的文本,但像上面这个例子中的一些则不是。以前有没有人发生过这种情况?会不会是在应用程序上更新的库导致了这种情况?
解决方案
推荐阅读
- node.js - 怎么能把开玩笑的测试结果存入数据库
- python-3.x - 包含 Keras 模型的网格搜索投票分类器
- python - 我怎么知道数据中的值是什么
- python - 404:[33mGET /search?q=books HTTP/1.1[0m”404 -
- java - 如何在 Java 中检索 Android 设备上的设置值
- python - IndexError:索引 2 在文件绘图期间超出轴 1 的范围,大小为 2
- karate - JSONPath 在空手道中使用时不返回值,但使用在线评估器时不返回值
- reactjs - 您是否需要 Web 服务器来在 VPS 上运行 React 应用程序的生产版本?
- laravel - 如何在我的模板 PhpWord 中设置 Yes 或 No 值而不是 1 或 0?
- python - 在 Python 中链接数组匹配