1

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

Graeme Phillips
  • 131
  • 1
  • 1
  • 10
  • sorry but that doesn't work :( Ive tried. Then /^I touch contentDescription text: (.*?)$/ do |arg1| tap_when_element_exists("TextView contentDescription:#{arg1}") end Then /^I touch contentDescription (.*?)$/ do |Text| tap_when_element_exists("TextView contentDescription:#{arg1}") end Then /^I touch contentDescription (.*?)$/ do |arg1| tap_when_element_exists("RadioButton contentDescription:#{arg1}") end Tried RadioButton as the query("RadioButton") returns the values I want to assert on. the cucumber BDD is: Then I touch the contentDescription "thisIsMyContentDesription" text – Graeme Phillips Apr 28 '15 at 08:29
  • Maybe the issue is about missing apostrophes around `contentDescription`'s value in your query? I've already edited my answer. – kjuri Apr 28 '15 at 08:53
  • step in feature is: Then I touch the contentDescription "cabbages" text step def is: Then /^I touch the contentDescription text: (.*?)$/ do |text| tap_when_element_exists("RadioButton contentDescription:'#text}'") end still doesn't seem to want to work.......is there is chip I can place in my brain please..! insert:Caffiene! – Graeme Phillips Apr 28 '15 at 09:32
  • For step in feature like `Then I touch the contentDescription "cabbages" text` definition should look like: `Then(/^I touch the contentDescription "(.*?)" text$/ do |text| tap_when_element_exists("RadioButton contentDescription:'#{text}'") end` – kjuri Apr 28 '15 at 09:48
  • sadly that has not worked either: the error returned in the results html file is as: Timeout waiting for elements: RadioButton contentDescription:'cabbages' (Calabash::Android::WaitHelpers::WaitError) ./features/step_definitions/custom_steps.rb:14:in `/^I touch the contentDescription "(.*?)" text$/' features\myFeatureFile.feature:62:in `Then I touch the contentDescription "cabbages" text' the step def is: Then /^I touch the contentDescription "(.*?)" text$/ do |text| tap_when_element_exists("RadioButton contentDescription:'#{text}'") end – Graeme Phillips Apr 28 '15 at 10:09
  • Does `query("RadioButton contentDescription:'cabbages'")` return anything when called from the console on the proper screen? – kjuri Apr 28 '15 at 10:20
  • that returns a console error: this syntax returns the content desciptions ok: query("RadioButton", :contentDesciption) that returns all radiobuttons present along with their content desctiptions as: [0] "lemons" [1] "cabbages" – Graeme Phillips Apr 28 '15 at 10:44

2 Answers2

3

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
kjuri
  • 158
  • 1
  • 10
  • hi @kjuri , sorry to say that didnt work. my query was this: query("RadioButton") this returns and array with various contentDescriptions, let's say the one I am looking for is "cabbages". So in my cucumber I have: Then I touch the contentDescription "cabbages" text. I've tried using various values in the step definition, none of which work... this is what I have tried: Then /^I touch the contentDescription (.*?)$/ do |text| tap_when_element_exists("Radiobutton contentDescription:#{arg1}") end – Graeme Phillips Apr 28 '15 at 08:18
  • But you still assign value of contentDescription to variable `text` and then try to use `arg1`? I mean, if you do `|text|` then you need to access it via `#{text}`, not via `#{arg1}`. And do not forget about apostrophes around it: `tap_when_element_exists("RadioButton contentDescription:'#{text}'")` – kjuri Apr 28 '15 at 08:33
0

@kjuri - your solution has now worked, it appears that in my windows environment set up it was looking at the incorrect step def, I cleared out the folder and started again - basically turned it on and off again!! thank you very very much for your patience on this, and your help.. greatly appreciated indeed. To summize this worked:

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

Graeme Phillips
  • 131
  • 1
  • 1
  • 10