I am new in Appium.
I try automated testing React Native App with Appium.
My case is, I have 2 screens, Login and Home screen. Login screen will loaded first, then Home screen.
But when I try to render accessibilityLabel in Home Screen it will return error like this,
[elementByAccessibilityId("buttonHome")] Error response status: 7, , NoSuchElement - An element could not be located on the page using the given search parameters. Selenium error: An element could not be located on the page using the given search parameters.
This is my Login screen
import React, { Component } from 'react'
import { View, TouchableOpacity, Text, TextInput } from 'react-native'
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
email: ''
}
}
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1, width: '50%', marginBottom: 10 }}
onChangeText={email => this.setState({ email })}
value={this.state.email}
placeholder={'Email'}
accessible={true}
accessibilityLabel={'fieldEmail'}
/>
<TouchableOpacity
accessibilityLabel='buttonLogin'
style={{ width: 100, height: 50, backgroundColor: 'blue', justifyContent: 'center', alignItems: 'center', borderRadius: 5 }}
onPress={() => this.props.navigation.navigate('Home')}>
<Text style={{ color: 'white' }}>Submit</Text>
</TouchableOpacity>
</View>
)
}
}
This is my home screen
import React, { Component } from 'react'
import { View, TouchableOpacity, Text, Alert } from 'react-native'
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
email: ''
}
}
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity
accessibilityLabel='buttonHome'
style={{ width: 100, height: 50, backgroundColor: 'blue', justifyContent: 'center', alignItems: 'center', borderRadius: 5 }}
onPress={() => Alert.alert('Notification', 'Welcome home.')}>
<Text style={{ color: 'white' }}>Submit</Text>
</TouchableOpacity>
</View>
)
}
}
And this is my test file
/* eslint-disable no-undef */
import wd from 'wd'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000
const PORT = 4723
const config = {
platformName: 'Android',
deviceName: 'Pixel 3a XL API 29',
app: '/Users/gandahalojasa/Documents/Project/Learn/Appium_React_Native/android/app/build/outputs/apk/debug/app-debug.apk'
}
const driver = wd.promiseChainRemote('localhost', PORT)
beforeAll(async () => {
await driver.init(config)
await driver.sleep(4000)
}) // Sometime for the app to load
test('login screen test', async () => {
// console.log('Active Element ', await driver.active())
let activity = await driver.getCurrentActivity()
console.log('Activity ', activity)
expect(await driver.hasElementByAccessibilityId('fieldEmail')).toBe(true)
await driver.elementByAccessibilityId('fieldEmail').type('[email protected]')
expect(await driver.hasElementByAccessibilityId('buttonLogin')).toBe(true)
const element = await driver.elementByAccessibilityId('buttonLogin')
await element.click()
})
test('home screen test', async () => {
expect(await driver.hasElementByAccessibilityId('buttonHome')).toBe(true)
const element = await driver.elementByAccessibilityId('buttonHome')
await element.click()
})