Using Excel to make a choice on what CheckBox to select

Best practices, code snippets for common functionality, examples, and guidelines.
Djones92
Posts: 9
Joined: Tue Aug 16, 2016 3:54 pm

Using Excel to make a choice on what CheckBox to select

Post by Djones92 » Tue Aug 16, 2016 4:05 pm

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.

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

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

Post by asdf » Wed Aug 17, 2016 1:15 pm

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
Attachments
SetCheckbox.zip
(21.66 KiB) Downloaded 34 times

Djones92
Posts: 9
Joined: Tue Aug 16, 2016 3:54 pm

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

Post by Djones92 » Wed Aug 17, 2016 2:03 pm

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.
Attachments
exampleSheet.zip
(2.94 KiB) Downloaded 27 times

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

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

Post by asdf » Fri Aug 19, 2016 2:38 pm

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

Djones92
Posts: 9
Joined: Tue Aug 16, 2016 3:54 pm

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

Post by Djones92 » Fri Aug 26, 2016 1:07 pm

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!
Attachments
checkBoxExampleSheet.zip
(6.35 KiB) Downloaded 28 times

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

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

Post by krstcs » Fri Aug 26, 2016 1:32 pm

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.
Shortcuts usually aren't...

Djones92
Posts: 9
Joined: Tue Aug 16, 2016 3:54 pm

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

Post by Djones92 » Fri Aug 26, 2016 1:43 pm

@krstcs

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

Thanks!

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

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

Post by krstcs » Fri Aug 26, 2016 2:16 pm

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.).
Shortcuts usually aren't...