Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for resource-id #9777

Closed
jsdevel opened this issue Sep 6, 2016 · 16 comments
Closed

Add support for resource-id #9777

jsdevel opened this issue Sep 6, 2016 · 16 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@jsdevel
Copy link
Contributor

jsdevel commented Sep 6, 2016

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
@jsdevel
Copy link
Contributor Author

jsdevel commented Sep 7, 2016

@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

jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 16, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 19, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 20, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 20, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Sep 21, 2016
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Oct 17, 2016
* Calling view.setId() with the matching resource-id of an id found in R.class.  Added TestIdUtil to facilitate this.
* Updating the android sample project to include a testID example.  Updating the e2e test to use it.
* Changing the signature for virtually all Event Classes to require the View instead of the viewTag.  This reduces the number of locations where TestIdUtil.getOriginalReactTag is called.
* Minimizing the impact in non __DEV__ environments where testID should not be set by simply returning view.getId() in TestIdUtil.getOriginalReactTag.
* This closes facebook#9777.
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Oct 25, 2016
* Calling view.setId() with the matching resource-id of an id found in R.class.  Added TestIdUtil to facilitate this.
* Updating the android sample project to include a testID example.  Updating the e2e test to use it.
* Changing the signature for virtually all Event Classes to require the View instead of the viewTag.  This reduces the number of locations where TestIdUtil.getOriginalReactTag is called.
* Minimizing the impact in non __DEV__ environments where testID should not be set by simply returning view.getId() in TestIdUtil.getOriginalReactTag.
* This closes facebook#9777.
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Oct 26, 2016
* Calling view.setId() with the matching resource-id of an id found in R.class.  Added TestIdUtil to facilitate this.
* Updating the android sample project to include a testID example.  Updating the e2e test to use it.
* Changing the signature for virtually all Event Classes to require the View instead of the viewTag.  This reduces the number of locations where TestIdUtil.getOriginalReactTag is called.
* Minimizing the impact in non __DEV__ environments where testID should not be set by simply returning view.getId() in TestIdUtil.getOriginalReactTag.
* This closes facebook#9777.
jsdevel added a commit to kogosoftwarellc/react-native that referenced this issue Oct 26, 2016
* Calling view.setId() with the matching resource-id of an id found in R.class.  Added TestIdUtil to facilitate this.
* Updating the android sample project to include a testID example.  Updating the e2e test to use it.
* Changing the signature for virtually all Event Classes to require the View instead of the viewTag.  This reduces the number of locations where TestIdUtil.getOriginalReactTag is called.
* Minimizing the impact in non __DEV__ environments where testID should not be set by simply returning view.getId() in TestIdUtil.getOriginalReactTag.
* This closes facebook#9777.
sondremare pushed a commit to EdtechFoundry/react-native that referenced this issue Nov 6, 2016
* Calling view.setId() with the matching resource-id of an id found in R.class.  Added TestIdUtil to facilitate this.
* Updating the android sample project to include a testID example.  Updating the e2e test to use it.
* Changing the signature for virtually all Event Classes to require the View instead of the viewTag.  This reduces the number of locations where TestIdUtil.getOriginalReactTag is called.
* Minimizing the impact in non __DEV__ environments where testID should not be set by simply returning view.getId() in TestIdUtil.getOriginalReactTag.
* This closes facebook#9777.
@charpeni
Copy link
Contributor

@facebook-github-bot label Icebox

@charpeni
Copy link
Contributor

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/add-support-for-resource-id

ProductPains helps the community prioritize the most important issues thanks to its voting feature.
It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix.
We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.

@charpeni
Copy link
Contributor

@facebook-github-bot close

@facebook-github-bot facebook-github-bot added Icebox Ran Commands One of our bots successfully processed a command. labels Nov 14, 2016
@facebook-github-bot
Copy link
Contributor

@charpeni tells me to close this issue. If you think it should still be opened let us know why.

@facebook-github-bot facebook-github-bot added the Ran Commands One of our bots successfully processed a command. label Nov 14, 2016
@dshn197
Copy link

dshn197 commented Jan 18, 2018

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?

@Vetalyo
Copy link

Vetalyo commented Jan 22, 2018

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

@thecopy
Copy link

thecopy commented Feb 8, 2018

Yes we need this as well.

@rodrix
Copy link

rodrix commented Feb 19, 2018

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

@shivasrini
Copy link

+1 that this will help testing

@jnrepo
Copy link

jnrepo commented Feb 22, 2018

+1 need this for testing

@oleksandrriabykh
Copy link

PLZ, make us happy. Add resource-id support

@dorangao
Copy link

+1, Please. It will make life easier.

@jkwohlfahrt
Copy link

+1

@evanjmg
Copy link

evanjmg commented Mar 21, 2018

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

@vefimofff
Copy link

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

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet