Setting checkboxes to specific values
Setting checkboxes to specific values
Afternoon,
I've recently started our trial of Ranorex and after doing the first parts of the tutorial am bumping heads with how to deal with a pair checkboxes.
Short version is I have an app with checkboxes that default to the state they were last set to - so if the app was last run with them unchecked, they'll be unchecked on first load next time etc. I want my test case to run the app with both checked, so because of the defaulting recording a simple click isn't enough. Problem is I don't know how to conditionally change the value of my checkboxes to ensure they're always checked.
Can anyone help or point me in the right direction in the documentation?
Thanks.
I've recently started our trial of Ranorex and after doing the first parts of the tutorial am bumping heads with how to deal with a pair checkboxes.
Short version is I have an app with checkboxes that default to the state they were last set to - so if the app was last run with them unchecked, they'll be unchecked on first load next time etc. I want my test case to run the app with both checked, so because of the defaulting recording a simple click isn't enough. Problem is I don't know how to conditionally change the value of my checkboxes to ensure they're always checked.
Can anyone help or point me in the right direction in the documentation?
Thanks.
Re: Setting checkboxes to specific values
Are you just doing record/playback or are you adding your own custom code?
I don't use record/playback so I cannot comment on that path, but with your own custom code you can write a method that checks checkboxes. Give the method two parameters, one, the checkbox you want to interact with and two, the state you want to set the checkbox.
Have the method check the current state then act accordingly. If you want it checked and it isn't check it, etc...
I don't use record/playback so I cannot comment on that path, but with your own custom code you can write a method that checks checkboxes. Give the method two parameters, one, the checkbox you want to interact with and two, the state you want to set the checkbox.
Have the method check the current state then act accordingly. If you want it checked and it isn't check it, etc...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: Setting checkboxes to specific values
I was trying the record/playback route based on the tutorial - do you have a link handy for doing your own codem in ranorex, or a snippet for how to deal with checkboxes?
I did find some code examples in the old (v2.x) user guide but that is prefaced with a warning to use the 3.x documentation instead - however I've yet to find the equivalent example in the latest user guide.
Apologies in advance if it's somewhere really obvious!
I did find some code examples in the old (v2.x) user guide but that is prefaced with a warning to use the 3.x documentation instead - however I've yet to find the equivalent example in the latest user guide.
Apologies in advance if it's somewhere really obvious!
Re: Setting checkboxes to specific values
Here is my checkboxclick method. You can use it in whole or modified to help you along...
Code: Select all
public static int CheckBoxClick(Boolean SelectCheckBox, Ranorex.Form RanorexFormName, String CheckBoxName)
{
int intResult = CheckBoxClick(SelectCheckBox, RanorexFormName, CheckBoxName, false);
return intResult;
}
public static int CheckBoxClick(Boolean SelectCheckBox, Ranorex.Form RanorexFormName, String CheckBoxName, bool boolHideNotFoundError)
{
/************************************************************************
* Function : CheckBoxClick(Boolean SelectCheckBox, Ranorex.Form RanorexFormName, String CheckBoxName)
*
* Description : This method will search for and (if found)
* : select or de-select a CheckBox on the form.
*
* Parameters : SelectCheckBox - TRUE = Select the CheckBox
* : - FALSE = Deselect the CheckBox
* : RanorexFormName - The form object the the CheckBox lives on
* : CheckBoxName - Name of the CheckBox to click
* : boolHideNotFoundError - FALSE (default) - reports that the item was not found - returns -1
* : - TRUE - Hides the error that the item was not found - Still returns -1
* : - This option basically transforms this method into a check if exists method
*
* Return Type : Integer
*
* Return Value : 0 for success, -1 for failure
*
* Revision History
* Date : Author : Reason/Change
* ---------- : ------------------------- : ------------------------------
* 03/05/2009 : Chris Gendreau : Initial Creation
* 12/10/2009 : Chris Gendreau : Added HideNotFoundError option
************************************************************************/
Ranorex.CheckBox HDcheckbox;
int error = 0;
//Search for the CheckBox on the Form
try
{
RanorexFormName.EnsureVisible();
RanorexFormName.Activate();
Thread.Sleep(500);
HDcheckbox = RanorexFormName.FindSingle(".//checkbox[@controlname='" + CheckBoxName + "' or @text='" + CheckBoxName + "']", 30000);
}
catch (RanorexException e)
{
if (boolHideNotFoundError != true)
{
Report.Error("Unable to find CheckBox: " + CheckBoxName);
Report.Error(e.ToString());
Report.Screenshot();
}
error = -1;
return error;
}
//Select or DeSelect a checkbox
try
{
if (SelectCheckBox == true)
{
Report.Debug("Selecting checkbox: " + CheckBoxName);
if (HDcheckbox.Checked != true)
{
Report.Debug(" Selected checkbox: " + CheckBoxName);
HDcheckbox.Focus();
Thread.Sleep(500);
HDcheckbox.Click(Location.Center);
if (HDcheckbox.Checked != true)
{
HDcheckbox.Focus();
Thread.Sleep(500);
HDcheckbox.Click(Location.CenterLeft);
}
}
else
{
Report.Debug(" " + CheckBoxName + " was already Selected");
}
}
else
{
Report.Debug("DE-Selecting checkbox: " + CheckBoxName);
if (HDcheckbox.Checked == true)
{
Report.Debug(" DE-Selected checkbox: " + CheckBoxName);
HDcheckbox.Focus();
Thread.Sleep(500);
HDcheckbox.Click(Location.Center);
if (HDcheckbox.Checked == true)
{
HDcheckbox.Focus();
Thread.Sleep(500);
HDcheckbox.Click(Location.CenterLeft);
}
}
else
{
Report.Debug(" " + CheckBoxName + " was already DE-Selected");
}
}
}
catch (RanorexException e)
{
Report.Error(e.ToString());
Report.Screenshot();
error = -1;
}
return error;
} //End CheckBoxClick
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
- Support Team
- Site Admin
- Posts: 12002
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Setting checkboxes to specific values
Depending on the technology of the element, you can also try to just set the "CheckState" or "Checked" attribute. You can do that easily using a "Set Value" action in the recorder (see this section in the Ranorex User Guide).
This approach might not work for some elements/technologies, then you have to rely on clicking the checkbox like Ciege proposed.
Regards,
Alex
Ranorex Team
This approach might not work for some elements/technologies, then you have to rely on clicking the checkbox like Ciege proposed.
Regards,
Alex
Ranorex Team
Re: Setting checkboxes to specific values
Hi Ciege , how to set the radiobttn value
thank you,
beginner
thank you,
beginner
Tipu
Re: Setting checkboxes to specific values
Basically the same way, except you use a Ranorex.RadioButton instead of a Ranorex.CheckBox.omayer wrote:Hi Ciege , how to set the radiobttn value
thank you,
beginner
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: Setting checkboxes to specific values
thank you Ciege, how do you maintain these functions, do you keep it under one class or each function has independant class
Tipu
Re: Setting checkboxes to specific values
one more - how do you get the text field from the page and enterring the value same for dropdowlist, list items, combo box,
Tipu
Re: Setting checkboxes to specific values
I have a DLL that is my Ranorex Framework that contains all my re-usable methods. I then reference this DLL from each test scripts. One place to maintain code but re-usable from any test script I want.omayer wrote:thank you Ciege, how do you maintain these functions, do you keep it under one class or each function has independant class
All very similar, you need to use the proper Ranorex type then query its proper attribute (such as the .text attribute of a Ranorex.Text).omayer wrote:one more - how do you get the text field from the page and enterring the value same for dropdowlist, list items, combo box,
For a combobox, you need to find the proper Ranorex.ComboBox then get its list of Ranorex.ListItem(s). Then when you open the combobox, click the listitem you desire.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: Setting checkboxes to specific values
Thanks for the check box code. I am trying to implement the code which builds successfully when I enter it into the user code.
I’m guessing I could call the method from the cs file like so:
CheckBoxClick(true, repo.FormKill_Trinity, repo.FormKill_Trinity.CheckBox1);
But the cs file is overwritten when you run the test so where can you call the method with the correct attribules. Is there a way of entering it into the GUI test steps? I seem to be able to call a method this way but there is no place for the arguments.
thanks for any assistance
I’m guessing I could call the method from the cs file like so:
CheckBoxClick(true, repo.FormKill_Trinity, repo.FormKill_Trinity.CheckBox1);
But the cs file is overwritten when you run the test so where can you call the method with the correct attribules. Is there a way of entering it into the GUI test steps? I seem to be able to call a method this way but there is no place for the arguments.
thanks for any assistance
- Support Team
- Site Admin
- Posts: 12002
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Setting checkboxes to specific values
The Recording "*.cs" file is automatically generated, so all you changes will be reverted. All your user code should go into the "*.UserCode.cs" file. See following topic in the Ranorex User Guide:
http://www.ranorex.com/support/user-gui ... tions.html
You could create a user code action and in that method then call your CheckBoxClick method.
Alternatively, it might be sufficient (and much easier) to just set the Checked attribute of the Ranorex CheckBox element:
Regards,
Alex
Ranorex Team
http://www.ranorex.com/support/user-gui ... tions.html
You could create a user code action and in that method then call your CheckBoxClick method.
Alternatively, it might be sufficient (and much easier) to just set the Checked attribute of the Ranorex CheckBox element:
repo.FormKill_Trinity.CheckBox1.Checked = true;If that works from code, you can also do that from the recorder UI directly using a "Set Value" action.
Regards,
Alex
Ranorex Team
Re: Setting checkboxes to specific values
While I mostly agree with that, there are some potential pitfalls just setting the state of the element. One being that if there happens to be some sort of fire on click associated with the element, then just setting the attribute will not trigger that.Support Team wrote: Alternatively, it might be sufficient (and much easier) to just set the Checked attribute of the Ranorex CheckBox element:repo.FormKill_Trinity.CheckBox1.Checked = true;
Further, I (personally) like having all the extra and standardized error checking and logging with using a custom method such as I have written. It might not be for everyone, but when I want to know what happened and (if an error happens) where and why an error occurs, I can track it down very easily with my method.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: Setting checkboxes to specific values
Hi Ciege,
if page contains 10 different checkboxes and all 10 checkboxes has diff control name, so when i call the function clickcheck w/passing controlname as parameter, how does it work ...shouldn't i have to create 10 different functions to get the object name then passing to the caller, any input please.
Beginner
if page contains 10 different checkboxes and all 10 checkboxes has diff control name, so when i call the function clickcheck w/passing controlname as parameter, how does it work ...shouldn't i have to create 10 different functions to get the object name then passing to the caller, any input please.
Beginner
Tipu