Partilhar via


FAQ: Why are we using coordinate based actions in Coded UI Test?

Corollary: If we use coordinate based action, will it not fail if the control moves its position?

 

When you record actions & generate code in Coded UI Test, you get actions like

Mouse.Click(uISearchButton, new Point(18, 15));

 

Many users are confused by the Point argument we pass to Mouse.Click and believe that we are doing a coordinate based action here. 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

Mouse.Click(uISearchButton);

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.

 

Why do you then keep coordinates? Remove them!!

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.

clip_image002

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.