This blog post has been updated to reflect changes in VS 2010 RC or later build. If you are on VS 2010 Beta 2, please upgrade before trying this post.
This is Part 1 of two part series. In this part we will focus on -
Why is generated code not a straight-line code?
In the Part 2, we will focus on -
How is generated code making reusability & customization easier?
So, why is generated code not a straight-line code?
While generating the straight-line code i.e. dumping everything in one method is the easiest thing for Coded UI Test, the tool is not doing that because in almost all cases that is not what you want.
The guidelines for code generation that we came up with (some based on the feedback received) was -
Following through the above guidelines have made the generate code bit complex (and might look overwhelming to first time users). In this blog, I will explain the generate code and how it is doing against the above guidelines.
Before proceeding further, let me take an example test case to automate. Say I am a tester with the Bing Search team. One of the P0 tests for me would be to ensure when searched for word “bing”, the Bing Search comes as the first link. The test steps for this would be –
Using the tool and recording each step as a separate method, the final code in the TestMethod would look something like this -
[TestMethod] public void SearchBingTest() { this.UIMap.LaunchBing(); this.UIMap.SearchBing(); this.UIMap.VerifyFirstLink(); this.UIMap.CloseBing(); }
The complete code is attached as BingTestGeneratedCodeAsIs.zip.
At this point, let us drill down into understand the code. The following files are generated by the tool -
Going by code generated by classes, there are 4 sets of classes -
Once we have understood the basic concept, let us go into the next blog - How is generated code making reusability & customization easier?