dimanche 14 avril 2019

Appium element.text() returns element accessibilityLabel instead of text

I am starting to test my React Native app with Appium. I have a simple login scenario where I expect the app status to be 'Logged in' after some username and password are entered and submitted. I am running the test on an iPhone X 12.2 simulator.

However the test fails with this error:

Expected: "Logged in"
Received: "status"

Somehow the text value is not received correctly. So how to get the inner text of my element?

App.js:

<Text accessibilityLabel="status">{this.state.status}</Text>

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')
})

All I can think of is that text() is not the right function to get the inner text of my element, but this is all I see in the docs or tutorials I've been following...

Aucun commentaire:

Enregistrer un commentaire