Come let us explore together…

Archive for the ‘VS2010 / CodedUI’ Category

Introduction to VS2010 Testing


Hi All,

Greetings!

We will understand how VS2010 is supporting testing and some internals (which I know at this time) on it.

The feature which helps users to record/code/automate, a desktop/UI controls is called CodedUI in VS2010. CodedUI is built on top of existing unit testing framework of visual studio ie., The new UITesting (Microsoft.VisualStudio.TestTools.UITesting) namespace and its siblings which is supporting UI automation is a sibling of the unit testing namespace (Microsoft.VisualStudio.TestTools.UnitTesting). You can witness this when you create new class using this feature where the arrangement of test classes and methods is similar to that of unit testing with slight attribute differences.

These assemblies and few more are important for developing the test and to interact with the AUT. The assert statements, test attributes and test context will be only available if you include the proper namespace references. But mostly they will be added once you create an item of type coded UI test.

In VS2010 ultimate, when you add ‘Coded UI Test’ to the test project, two items are added namely – UIMap.uitest and CodedUITest1.cs which are basic for the development of test automation.

Briefly UIMap.uitest is the UI object repository or map of the UI objects we interact during our recoding or testing. It has two partial classes (UIMap.Designer.cs and UIMap.cs) to support this. CodedUITest1.cs (default class) is the container to add test methods which in turn calls the test actions. You must understand what each item is capable of and I have provided reference at the end of this post.

You must follow the defined framework approach to arrange your tests. The below diagram depicts the details.

Assembly1 {
          Class A {
                   Test method T1 {  }
                   …
                   Test method Tx {  }
          Class B {
                   Test method T11 {  }
                   …
                   Test method Txx {  }
  …      
          Class C {  }
}

 The test will be referenced as Assembly1.ClassA.TestMethodT1().

Thus you should use suitable test attributes like CodedUITest for a class to denote it as a CodedUI class, TestInitialize to tag a method which is invoked automatically  each time just before the a test method is executed and TestMethod to denote the actual test. These and many other test attributes help us to arrange units like the one mentioned above.

If you want to jump-start, just automate a simple scenario like calculator or a Google page (refer MSDN links given below for steps). Then go to the UI map and CodedUI class files to understand the code. If you have prior experience in other automation tools, then UI map in VS might surprise you.

Because, the UI objects are mapped as XML and their properties (which are used to identify them uniquely) is embedded as raw properties inside a class. Yes. NO good UI/Window to showcase the recorded objects. The entire recording is stored as Classes, methods and properties. If you can apply a patch (VS2010 feature pack 2), the XML object mapping visualized as hierarchy of objects in a windows form.

And a BIG advice from Microsoft is “Don’t edit content of UIMap.Designer.cs” file. Manual updates to this file will be lost when you record a new scenario referring to the exited UI map. Only CodedUI recorder is allowed to modify this content and simply updates thru the tool will be preserved.

For example in Step 1: Record action for searching “Testing” in Google. Generate code and close the test recorder.

Step 2: Go to ‘UIMap.Designer.cs’ and replace the string “Testing” (generated by test recorder) to “Automation” which is stored as parameter.

Step 3: (Go to searched Google result page) Start Test Builder from the previously recorded method (say – CodedUITestMethod1 using the right-click context menu). Add an assertion using the cross hair from the test builder for any of the link from the Google results page. Generate and close the test builder.

Now if you look for the replaced parameter done in Step 2, it will be overwritten by test builder when you performed Step 3.

So, Can’t I modify my recorded scripts?

Yes. We can! Since ‘UIMap.Designer.cs’ and ‘UIMap.cs’ are partial classes, we can do our custom scripting in ‘UIMap.cs’ file. And modify the references accordingly. (I will come with an exercise on how to preserve changes in a separate post)

The UI automation is backed by Microsoft’s MSAA technology and has capability to expand well. The recording is good and intelligent.

Like all other tools it supports data driven testing using few default providers for XML, CSV and SQL tables and reporting.

Above all you have the implicit advantages of coding in VS IDE where you can visualize objects, better debugging and organize tests  – to name a few.

We will continue to explore new areas and dig deep in to interested features in the coming post.

Believe!!! There are 101 ways to automate.

Thanks and Regards,

Giri Prasad

Step by step tutorial to start : http://msdn.microsoft.com/en-us/gg465252

Welcome to VS2010 testing and Coded UI


Hi All,

Greetings!

I have been working in VS2010 team system for last couple of months and its time to share and learn along with you.

What VS2010 offers for testing?

Microsoft follows team system approach for team collaboration starting from requirement collection, planning, development and release related activities. Until this version, a major gap exists in their collaboration as they didn’t support functional testing completely (supported unit test only).

In the release of VS2010, it said to landed in testing by providing good support for testing practices and extend all their team system capabilities to testing services as well. I will give credit to Microsoft and their Testing team because they have done it well and supposed to be their first release of supporting testing process.

I am a beginner in VS2010 testing concepts and learning things everyday. I will praise the good things and point out the issues as we move in this exploration.

Microsoft – like every one, bundles different feature for different versions and pricing models. VS2010 Ultimate version is said to have complete set of features of this release where one can develop, write unit, record/develop functional tests(involving UI actions),connect to TFS and with Test Manager to write manual test cases for a test plan, record test actions, run them using lab manager and more. I will be interested on this and most of my posts will be based on this version.

And Believe!!! There are 101 ways to automate.

Thanks & Regards,
Giri Prasad