Search code examples
xamarincalabash-android

calabash-android passing in contentDescription into custom step definition


I am trying to pass in contentDescription into a custom step definition, with little success and I am not sure I can do it, there is very little help out there, so I am a bit lost.

so I have started calabash-android console then start_test_server_in_background then query("TextView") which returns a list of elements in the textView, in this list are contentDescription, each has a string value, e.g "thisIsValue"

now I have written a step in my feature file as:

Then I touch contentDescription "thisIsValue" text

the syntax of my custom step method is:

Then /^I touch contentDescription text (\d+)$/ do |text, contentDescription| tap_when_element_exists("contentDescription contentDescription:#{arg1}")

I'm starting to think passing in contentDescription just isn't possible for multiple values of the same text on a form, using ID is not possible due to the way xamarin forms are generated in our instance, another option would be on index, however that is not really good moving forward.

thanks all.

Graeme


Solution

  • There are few possibly wrong details about your step definition.

    1. The (\d+) regular expression indicates, that you are looking only for elements with digits in contentDescription.
    2. You are passing into block one value (which is mentioned above digit-only value) and then expecting two values to be passed (text and contentDescription).
    3. You should tap element of type TextView, ImageView, * etc., but you want to tap contentDescription element.
    4. You want to tap element with contentDescription with value of arg1, but there is none arg1 inside your block.
    5. Do not forget about apostrophes around contentDescription's value in your query.

    So, your step definition possibly should look something like that:

    Then /^I touch contentDescription text: (.*?)$/ do |arg1|
      tap_when_element_exists("TextView contentDescription:'#{arg1}'")
    end