Learn to use Visual Studio, Visual Studio Online, Application Insights and Team Foundation Server to decrease rework, increase transparency into your application and increase the rate at which you can ship high quality software throughout the application lifecycle
More videos »
This blog assumes that you have basic understanding of Coded UI and are familiar with the code generated from a recording on Winforms, WPF or Web applications.
A lot of times, while running a UI test, our test runs into an unexpected page\state, say an unexpected error dialog, dismissing which would make our test work, or maybe the server takes too long to respond on occasion and if that happens, rather than having the test rerun from the start, all we want is for it to resume when the page is loaded. As part of VS Update 1, we have added API support for Retrying or Skipping a failed UI action and continuing playback of the remaining steps in the test.
For the purpose of this blog I am taking the example of a winforms application with an alert window. The steps would be no different if you were trying the same on any other supported technology.
Here’s the scenario:- I have a simple Aut with a textbox where I can enter the age of a user, in case the value exceed “50” an alert prompt is thrown. I want my automation to enter some value and click on “Submit Age” button, followed by entering some value in the Name TextBox. Clearly, if the age entered exceeds 50, I won’t be able to proceed with entering my Name in the textbox. For such a case, I want the test to dismiss the alert and retry entering the Name in the textbox.
The Coded UI Test generated code would look something like this at present
Now I would expect step 3 i.e. entering some text into uINameEditEdit to fail. In order to dismiss the alert box and retry the action, I need to follow these steps:-
3. The handler method signature is as shown below
Here PlaybackErrorOptions to Retry\Skip\Default- for further details, msdn documentation for these options is present here.
4. Now simply setting the PlaybackErrorOptions to Retry will retry your failed step over and over until either the step passes or the MaximumRetryCount is hit. If you want to do any special handling, like say dismissing an alert, you can add the code for the same within the handler.
The final code for the above defined scenario looks like this:-
And the Retry handler method code:-
Couple of points to keep in mind:-
Attaching below a sample wpf project which has an unwanted popUp and the corresponding Coded UI Test implementing the retry method to dismiss the same.
When I build this solution I get the following error Error 1 'Microsoft.VisualStudio.TestTools.UITesting.PlaybackSettings' does not contain a definition for 'MaximumRetryCount' and no extension method 'MaximumRetryCount' accepting a first argument of type 'Microsoft.VisualStudio.TestTools.UITesting.PlaybackSettings' could be found (are you missing a using directive or an assembly reference?)
in Visual Studio 2012 - any idea?
Thanks for the guidance on errorhandling.
From what point does the retry start? In the code type John step has to be repeated, so does that step get repeated? Kindly clarify.