Calabash - how do I check a radioButton has been selected (multiple same named buttons)

381 views Asked by At

I am at a loss with the following and maybe the code needs to be changed, but I'll ask here first and hopefully someone will be able to assist.

I have a long form with multiple choice questions. eg.

Q1 to Q30 - each answer is a radioButton named "OK", "not OK", "Don't Know" now running queries on the IRB console as: Query("radioButton") and query("FormsTextView") I get the contentDescription and the text values.

Now, due to the way the form data is generated (via Xamarin forms) each question has: Q1 - text = ok, not ok, don't know. contentDesciption is one per question.

So, asserting on the text is not an option, and asserting on the contentDescription will only select the first radioButton.

asserting on ID is not an option as these are generated at run time by xamarin.

So what I am looking for is a way to see if a radioButton has been selected then select a different one.. eg. if 'ok' is selected, then select 'not ok' (note, both have same contentDescriptions, so maybe select 2nd instance of contentDesciption may work, however I am not that versed in Ruby as yet to write a custom step definition that would handle this scenario.

A probable solution may also be: Then I touch textAndContent text - with a step def's pseudo code of " Then I touch the "textNameOfButton" == "contentDescription" do touchElement where textNameofButton -- contentDescription so basically the custom step takes an input of text and contentDescription and passes those to a compound query, only then performing the tap_when_element_exists method. not idea how to do this sadly :(

Any help or pointers is most appreciated.

Thank you in advance. G

1

There are 1 answers

4
Lasse On

As I understood you you will have 30 buttons with "OK", 30 with "Not OK" and 30 with "Don't know".

I would query for each kind and place output i an array. Something like this (for OK):

okArray = query "radioButton text:'OK'

Then look at index 0 in all 3 arrays to see which one is selected. And then just select a different one. And then do the same for each of the other indexes.