Page 1 of 1

Using Excel to make a choice on what CheckBox to select

Posted: Tue Aug 16, 2016 4:05 pm
by Djones92
Hi,
Running RX v.6 on a Silverlight application.

I have some CheckBoxes, let's say A, B, C and D.
I have a field in an Excel sheet, let's call it Choices.
I have successfully read in the spreadsheet (proven through use in some steps) and now what I would like to do is use the Choices field to determine whether to "check" A, B, C or D.
I have tried getValue, but this requires a Repository Item to work, which is not what I'm aiming to do.

I'm guessing I'll need to write some usercode, but I'm not a developer and am struggling.
Please note for security purposes I am unable to provide snapshots.
Thank you.

Re: Using Excel to make a choice on what CheckBox to select

Posted: Wed Aug 17, 2016 1:15 pm
by asdf
Hi Djones92,

Unfortunately, I'm not exactly sure what do you want to achieve. If you want to check/uncheck checkboxes according to a excel connector, please take a look at the attached sample solution.

I hope this helps.

Kind regards,
asdf

Re: Using Excel to make a choice on what CheckBox to select

Posted: Wed Aug 17, 2016 2:03 pm
by Djones92
Thanks asdf.
Attached is the kind of sheet I will be using.
The Check column could range from A-D. I want to use the values in that column to select the corresponding checkbox in the application.
Basic Pseudocode for concept example:

Code: Select all

if(checkVal == A)
{
 click(BoxA);
}
and so on...
Can I ask why your example spreadsheet only has a single column? From my experience that will select a different box through iterations as that seems parameterised, I might be wrong, however. I'm pretty new to RX.

Re: Using Excel to make a choice on what CheckBox to select

Posted: Fri Aug 19, 2016 2:38 pm
by asdf
Hi Djones,

I would suggest creating a repository variable for the checkboxes name.
Afterwards, just create a excel sheet where you set the name of the checkboxes which have to be checked/unchecked in 1 column and connect it to a TestCase. Add a new MouseClick action to the recording, which clicks on the variable repository item.
Go to the DataBinding dialog of the corresponding Testcase and bind the variable to the data source.
If you are using this approach, you don't need any, not very maintainable, if-statements.

I hope this helps.

Kind regards,
asdf

Re: Using Excel to make a choice on what CheckBox to select

Posted: Fri Aug 26, 2016 1:07 pm
by Djones92
Hi asdf,

I couldn't quite work out what to do in that regard, so I decided to go down the user code route- first with if statements (one column sheet), then case statements (multiple column sheet) for robustness and multiple selection capability.
For future reference if anyone else needs to do this, here is my solution and a spreadsheet to work with:

Code: Select all

public void checkBoxes(int Box1, int Box2, int Box3, int Box4)
{
    int i = 0; //start counter
    while(i < 4)//varying on your number of boxes
    {
          switch(i)
          {
              case 0:
                  if(Box1 == 1)//1 means checked
                      { 
                      ...CheckBox1.Check(); //include xpath!!
                      }
                      else ...CheckBox1.Uncheck();
                      i++;
                      break;


         //continue for all other boxes
         }   
    }
}
NOTE: The spreadsheet values are all numbers, not strings. This is important.
Also remember to set your userCode method args as int32 and to bind your data source!

Re: Using Excel to make a choice on what CheckBox to select

Posted: Fri Aug 26, 2016 1:32 pm
by krstcs
Just to let you know, ALL data from any data source (data connector) is treated as a string in Ranorex. It doesn't matter what the actual data type is, Ranorex reads it as a string value in the data connector. If you use Excel (you should really use CSV instead, but that is another topic), this means that integer or money value columns are still treated as strings in Ranorex. This can cause issues if you think that the money value should be formatted a certain way, but Ranorex only gives you the value without formatting.

The reason you are able to set the method variables as integers is because Ranorex boxes and un-boxes the string values behind-the-scenes for you. There is no reason for you to change from a string to an int in your case though, as you could just compare to the string values, and the RanoreXPath treats it as a string when replacing parts of the path anyway.

The only reason to convert from a string is if you need to do calculations directly on the value.

Re: Using Excel to make a choice on what CheckBox to select

Posted: Fri Aug 26, 2016 1:43 pm
by Djones92
@krstcs

Cool, I'll keep that in mind. :D
Why would csv be considered best practice?

Thanks!

Re: Using Excel to make a choice on what CheckBox to select

Posted: Fri Aug 26, 2016 2:16 pm
by krstcs
I'm a DB guy, myself, but I would use CSV before XLSX, because you don't need to have Excel installed in order to use CSV, but you do to use XLSX. In addition, Excel can open and save CSV natively.

The only issue is that you lose formatting and types. So, everything is a string, but again, that is how Ranorex treats it anyway, so it shouldn't matter.

The GOOD thing about loosing formatting and typing is that you then have to put the values in exactly how you want them to look. So money would have the localized denotation ("$0.00" for EN-US, etc.).