Wait for Android app to display a React Native button and then touch it

Hi,
I’m developing a React Native app for Android and I’ve been learning and trying to do my first test in Ruby. Right now I would like my test to wait for the app’s main screen to load and then touch a React ‘TouchableOpacity’ button.
The React Native code is the following:

<View style={styles.row}>
    <View style={styles.buttonContainer}>
        <TouchableOpacity style={styles.buttonIcon} onPress={this.goToFaqsList.bind(this)} accessible={true} accessibility_id={'FAQs'}>
        <Icon style={styles.icon} size={32} name="help" color="white"> </Icon>
        </TouchableOpacity>
        <Text style={styles.buttonText}>FAQ's</Text>
    </View>
<View style={styles.buttonContainer}>

The test:

require 'rubygems'
require 'appium_lib'

capabilities = {
  platformName:  'Android',
  deviceName:    'Android',
  app:           '~/workspace/maps2/android/app/build/outputs/apk/app-debug.apk',
}

server_url = "http://0.0.0.0:4723/wd/hub"

# Start the driver
Appium::Driver.new(caps: capabilities).start_driver

Appium.promote_appium_methods Object

wait = Selenium::WebDriver::Wait.new :timeout => 10
wait.until { elementByAccessibilityId("FAQs").displayed? }

source
mobileElement = elementByAccessibilityId("FAQs")
puts(mobileElement)

driver_quit

The " elementByAccessibilityId " was an approach I saw in another topic but I’m getting an error:

Failure/Error: wait.until { elementByAccessibilityId("FAQs").displayed? }

NoMethodError:
undefined method `elementByAccessibilityId' for main:Object

Can someone tell my mistake and point me in the right direction?
Thanks.

In Ruby methods are usually not camelcased. You’ll find that they almost always use lowercase and underscores. I think what you are looking for is more like:

find_element(:accessibility_id, 'FAQs')

https://github.com/appium/ruby_lib/search?utf8=✓&q=accessibility_id&type=

However, ‘FAQs’ doesn’t look like an accessibility_id. It looks more like the name of an element to me (although I could be wrong, of course). Since you’ve already called Appium.promote_appium_methods, you can call @driver.find_element directly. Maybe something like:

@driver.find_element(:name, 'FAQs')

That doesn’t look like a ruby call. Looking here: https://github.com/appium/ruby_lib/search?utf8=✓&q=accessibility_id&type=

I found this:

find_element(:accessibility_id, “some item”)

Thank you both for the quick replies. I finally got it working.
@wreed, find_element(:name, ‘FAQs’) throws an error saying that “name” is not a valid Locator, and then:

Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator

However in the React Native code I changed the attribute accessibility_id={‘FAQs’} to accessibilityLabel={‘FAQ’}, and in the ruby test file find_element(:accessibility_id, ‘FAQs’). And it’s working! Now I can .click() the button and continue testing :+1:
I’ll take a look in the docs https://github.com/appium/ruby_lib/blob/master/docs/android_docs.md and see what other functions we have available to use :slight_smile:

My bad. ‘name’ locator was depreciated in 1.5. Glad you got it working anyway!