Monday, 9 February 2015

Usage of Cordinate based actions in CodedUI

When you record actions & generate code in Coded UI Test, you get actions like
Mouse.Click(uISearchButton, new Point(18, 15));

Many confuse by the Point argument we pass to Mouse.Click and believe that we are doing a coordinate based action. The Point argument here is relative to the button itself. So test will not fail if the button moves around in the page.

More importantly, you can completely remove the Point argument. The code could be written as

This will still work. If no Point argument is specified, Visual Studio UI Test Framework determines a clickable point and performs the click on that point.

So why do we use coordinates?

There are specific scenarios where these coordinates really come in handy.

Consider a DropDownButton, which drops down when you click on the expander arrow. If you click on the button’s normal area, it is invoked. If you click on the expander, it shows the additional buttons and you can click on one of them. Since we record relative coordinates for the click action, we can playback the actions on the expander also. If we had not recorded coordinates and clicked on the first available clickable point in the button, this scenario would have failed.
e.g:- Look at the screenshot below.

Here I am clicking on the expander in Picture Button to bring up additional options. This scenario will only work if we record relative coordinates on the click action.

No comments:

Post a comment