question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

XCUITest is failing because testID cannot be found when using native base components

See original GitHub issue

The native-base version I am using is 2.2.1.

I have the following UI test in Xcode:

class timesUITests: XCTestCase {
…
    func testExample() {
      let app = XCUIApplication()
      setupSnapshot(app)
      app.launch()
      
      app.textFields["testOne"].tap()
      app.textFields["testOne"].typeText("Hello")
}

and the following components rendered in my app:

      <View>
        <Input
          testID={'testOne'}
          value={this.state.sometext}
          onChangeText={(sometext) => this.setState({sometext})}
        />
      </View>

I would expect that the test succeeds, but it fails with the native base component Input. When I replace the native base Input component with the React Native counterpart TextInput the test runs fine and succeeds in Xcode.

It seems that the test fails in Xcode because the testID prop gets lost somehow.

I am using iOS only, but I would expect that a similar test would also fail in Android, as the testID gets lost on the way.

It would be great if NativeBase would respect the testID prop, because this would allow testing in Xcode and would also support the great Fastlane Snapshot tool.

(Thanks for NativeBase, it is great 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
faogustavocommented, Dec 1, 2017

I discovered that Touchable components are the problem. When you use one, all itens inside it will not be accessible by testID. To fix, just add a accessible={false} prop to the Item.

            <Item floatingLabel accessible={false}>
              <Label>
                {t("loginUsername")}
              </Label>
              <Input
                testID="login-username"
                ref={username => {
                  this.username = username;
                }}
                returnKeyType="next"
                clearButtonMode="while-editing"
                autoCapitalize="none"
                autoCorrect={false}
                value={this.state.username}
                onSubmitEditing={() => {
                  this.password._root.focus();
                }}
                onChangeText={username => {
                  this.setState({ username });
                }}
              />
            </Item>

A better explanation can be found here: https://github.com/facebook/react-native/issues/11869 If possible, please add this to documentation for future problems.

0reactions
saggiyogeshcommented, Aug 9, 2018

@faogustavo Works great. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UI Tests with react native. How to fix Timestamped Event ...
For anyone else looking for an answer for this - I found that Touchable elements in RN have an issue with the UI...
Read more >
Installation - NativeBase
Refer the guides shown below to setup NativeBase in your React app. Install in Expo project. Follow this guide to install NativeBase in...
Read more >
How To Get A React Native Textinput By Its Testid In An Ios ...
XCUITest is failing because testID cannot be found when using native base components Fantashit February 20 Full dicussion on github.com It seems that...
Read more >
Cypress Best Practices For Test Automation - LambdaTest
This blog will teach you the Cypress best practices to write reliable and high-quality test codes while performing Cypress testing.
Read more >
UI Testing in React Native with Detox - Irem Karaoglu - Medium
After a while, I am here with another React Native content. Thank you all for your support to my previous blog post. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found