LaV*_*lle 4 testing appium react-native
我开始使用 Appium 测试我的 React Native 应用程序。我有一个简单的登录场景,我希望应用程序在输入并提交一些用户名和密码后status出现。'Logged in'我正在 iPhone X 12.2 模拟器上运行测试。
但是测试失败并出现以下错误:
Expected: "Logged in"
Received: "status"
Run Code Online (Sandbox Code Playgroud)
不知何故,文本值未正确接收。那么如何获取我的元素的内部文本呢?
应用程序.js:
<Text accessibilityLabel="status">{this.state.status}</Text>
Run Code Online (Sandbox Code Playgroud)
appium.test.js:
test('Login success', async() => {
expect(await driver.hasElementByAccessibilityId('username input')).toBe(true)
expect(await driver.hasElementByAccessibilityId('password input')).toBe(true)
expect(await driver.hasElementByAccessibilityId('submit button')).toBe(true)
expect(await driver.hasElementByAccessibilityId('status')).toBe(true)
await driver.elementByAccessibilityId('username input').sendKeys('some_username')
await driver.elementByAccessibilityId('password input').sendKeys('some_password')
await driver.elementByAccessibilityId('submit button').click()
const result = await driver.elementByAccessibilityId('status').text()
console.log(result) // 'status' WHY???
// the test runs fine until here:
expect(result).toBe('Logged in')
})
Run Code Online (Sandbox Code Playgroud)
我能想到的是,这text()不是获取元素内部文本的正确函数,但这是我在我一直关注的文档或教程中看到的所有内容......
我遇到了同样的问题。好像RN0.50引入了这个问题。
这不是 Appium 上的错误,而是 WDA 实现及其返回文本值的方式的问题。 https://github.com/appium/appium/issues/10349有一个关于这个问题的讨论。
您可以在 IOS 上使用testID而不是 来解决它accessibilityLabel。
let textProps={}
if(Platform.OS==='android')
textProps.accessibilityLabel = "welcomeLabel"
...
...
...
<Text
style={styles.welcome}
{...textProps}
testID="welcomeLabel">
...
...
Run Code Online (Sandbox Code Playgroud)
您仍然可以使用elementByAccessibilityId函数。
| 归档时间: |
|
| 查看次数: |
1392 次 |
| 最近记录: |