How To Minimize Automation effort on controls which are ...

Best practices, code snippets for common functionality, examples, and guidelines.
User avatar
_KK_
Posts: 24
Joined: Tue Nov 21, 2017 12:51 pm

How To Minimize Automation effort on controls which are ...

Post by _KK_ » Thu Feb 15, 2018 12:42 pm

How To Minimize Automation effort on controls which are tested against WPF attribute "visible" or "enabled" with parameter "true" or "false"

There is a bunch of controls, e.g. 16 pieces. They are located on one page of the UI, the order is like a Matrix.
They have AutomationId glued, also the Window has an AutomationId so that the controls can be found easiyl.

The WPFP controls are configured with Attributes to enable/disable or show/hide them with extra steering buttons.


First approach in a TestSuite could be (maximum of entries in Ranorex repo for XPathes)


Click event to XPath

Code: Select all

.//form[@automationid='Test']/button[@automationid='CommandButton2' and @visible='False']
Action to change the behavior of the control so that it will be visible (with the extra steering button)

Click event to XPath

Code: Select all

.//form[@automationid='Test']/button[@automationid='CommandButton2' and @visible='True']
Revert behavior with steering button so that control will be hidden

Click event to XPath

Code: Select all

.//form[@automationid='Test']/button[@automationid='CommandButton2' and @visible='False']

Second approach could be using "UserMethods"
Third method could be use DataDriven Testing with csv files


Thanks in advance for any hint.

BR

Klaus

User avatar
_KK_
Posts: 24
Joined: Tue Nov 21, 2017 12:51 pm

Re: How To Minimize Automation effort on controls which are ...

Post by _KK_ » Fri Feb 16, 2018 12:26 pm

I grabbed a solution at least with the help of Pavel!

DDT Approach.

Using XPath with a * (asterisk) as wildcard for Ranorex-Adapter:

Code: Select all

.//form[@automationid='AID-Test']/*[@automationid=$AutomationId and @visible=$visible]
csv-file for DDT looks like

Code: Select all

AutomationId,visible
CommandButton1,true
DataControl1,true
BarControl2,false
TextControl5,false

User avatar
Vega
Posts: 109
Joined: Mon Jul 11, 2016 2:15 pm

Re: How To Minimize Automation effort on controls which are ...

Post by Vega » Fri Feb 16, 2018 8:44 pm

I too like the data driven approach as you can also validate against the expected visible state. There is a less optimal approach and may not even work for your scenario, but if you only care about finding the objects and then performing actions upon it, you could just make your path more generic:

Code: Select all

.//form[@automationid='Test']/button[@automationid='CommandButton2'] //We do not care if it is visible or not
.//form[@automationid='Test']/button[@automationid='CommandButton2' and @visible='False' or @visible='True] //Essentially the same thing as above since visible is a boolean
then once you find the object, you can validate it. As mentioned before, I would recommend doing the data driven approach because it allows you to easily validate the expected state.