Skip to content

Add support for resource-id #9777

Description

@jsdevel

Issue Description

There currently isn't a way to find elements by resource-id using appium/uiautomatorviewer.

react-native currently supports contentDescription via accessibilityLabel. This is great for clickable elements, but not so great for testing other things like splash screen visibility.

I'd be more than willing to add support for this, but am currently not aware of how react-native builds the android views. If someone could give me some guidance on how android:id could be added to a view then I'd most certainly be willing to give it a shot. My understanding of android:id (per the View docs on IDs), is that it must be set in the XML prior to view creation.

I don't believe this is a duplicate of #7135, because I'm not proposing that we break the way testID currently works, more that I feel it would be nice if testID could add it's value to the corresponding view component in the XML.

Steps to Reproduce / Code Snippets

  • Add testID="something" to any component (e.g. View)
  • Run the app on an android device
  • Run uiautomatorviewer

You'll notice that resource-id is empty

without-id

Expected Results

resource-id has a value like com.myApp:id/something

Additional Information

  • React Native version: 0.32
  • Platform(s) (iOS, Android, or both?): Android.
  • Operating System (macOS, Linux, or Windows?): All

Activity

  1. jsdevel commented on Sep 7, 2016

    @jsdevel
    ContributorAuthor

    @tuckerconnelly referenced BaseViewManager here. I'm thinking it could be modified to do something like this:

      @ReactProp(name = PROP_TEST_ID)
      public void setTestId(T view, String testId) {
        try {
          view.setId(R.id.class.getField(testId).getInt(null));
        } catch (Exception e) {
          // swallow
        }
        view.setTag(testId);
      }

    The trick is gaining access to R which resides in the application's package.

    If that were in place, the only thing you'd need to do is create a resource file for the ids you'll be referencing:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <item name="something" type="id"/>
    </resources>

    Thoughts @ide @mkonicek?

    cc @jasonfma @talarari @sondremare @sijicl @JuliusMalisauskasDB @atom992 @jdeff

  2. 52 remaining items

  3. dshn197 commented on Jan 18, 2018

    @dshn197

    I am testing a react-native application and I do feel I require the support for resource-id. Can you guys open up this ticket again?

  4. Vetalyo commented on Jan 22, 2018

    @Vetalyo

    I have the same trouble, for Robo tests needed resource-id for each page component.
    Any news about this? Very need this functional. 😞

  5. thecopy commented on Feb 8, 2018

    @thecopy

    Yes we need this as well.

  6. rodrix commented on Feb 19, 2018

    @rodrix

    Something new about this issue?
    My testing crew is stuck without this. ;/

  7. shivasrini commented on Feb 22, 2018

    @shivasrini

    +1 that this will help testing

  8. jnrepo commented on Feb 22, 2018

    @jnrepo

    +1 need this for testing

  9. oleksandrriabykh commented on Mar 1, 2018

    @oleksandrriabykh

    PLZ, make us happy. Add resource-id support

  10. dorangao commented on Mar 13, 2018

    @dorangao

    +1, Please. It will make life easier.

  11. jkwohlfahrt commented on Mar 13, 2018

    @jkwohlfahrt

    +1

  12. evanjmg commented on Mar 21, 2018

    @evanjmg

    My workaround for testing right now is accessibility Label. However, this does not help with prelaunch Google Play testing :(

  13. vefimofff commented on May 24, 2018

    @vefimofff

    +1 our team finds this feature really helpful. Are there any plans on moving this forward?

  14. locked as resolved and limited conversation to collaborators on May 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions