Sunday, December 11, 2011

Test Automation Guidance using VS 2010 Coded UI

 

Author:

Raj Kamal (rajkamal@microsoft.com)

 

New !!! On special demand, sharing the below content in PDF format as well as sample reusable Coded UI Framework for your user

http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-42-73-CodedUI/2086.Automation-Guidance-_2800_VS-2010-Coded-UI_2900_-ExternalCommunity.pdf

http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-42-73-CodedUI/0167.CodedUISampleFramework.rar

 

Objective

The objective of this artifact is to provide a L200 test automation guidance leveraging VS 2010 Coded UI features to foster a continuous, consistent and standard automation approach. The document can also be used as a quick jump start guide for beginners.

However the bigger objective is Build, Deploy and Test leveraging Visual Studio Lab Management features, which will allow Automation Testers to reap the benefits of the following

· Integrating with the build process for automatic build deployment

· Execution on VMs

· Capabilities of getting the test automation results reported as part of Test Manager (MTM) for better reporting.

Pre-requisites:

clip_image001 Ensure you have ‘CodedUISampleFramework’ sample Coded UI project

clip_image001[1] For VS 2010 installation & Configuration, go to Appendix: VS 2010 Installation Reference section

clip_image001[2] If you are new to Visual Studio Coded UI, go to Appendix: Getting started with VS2010

clip_image001[3] Ensure your application is supported by Coded UI, go to MSDN link

Jump to Case Study, if your objective is to get started with Coded UI using our recommended framework and practices.

 

Test Automation Process using Visual Studio 2010

It is not enough just to automate your tests but there is also an important need to automate the build process as well as automatic installation and deployment. This will eliminate manual intervention required to trigger the automation due to build and deployment dependencies.

Automated Build, Deploy and Test framework will also enable us to find out the build quality at the earliest by publishing the test results for every run against a new build.

You can run the test suites that are most important for your continuous builds because too many tests can delay the completion of build. Make sure that you run these tests for the current iteration.

image

Figure 1: The topology required for setting up Build, Deploy and Test environment using various VS components like Build Controller and Agents for Build, Test Controller and Agent for distributing test and collecting results, Virtual environment for Deployment and Execution (Reference taken from MSDN)

To run unit or functional automation tests, we can create a set of environments that are managed Hyper-V images in Microsoft Test Manager. Tests that are created at the start can be used as part of continuous integration.

1. For Daily build, we want to run very minimal set of test which are like Build Verification test or Smoke test

2. For Weekly builds, we want to run “Regression test” which will be more in number.

image

Figure 2: Steps for Build, Deploy and Test workflow

If you plan to run your automated tests by using Microsoft Test Manager, you must use a physical or virtual environment that contains a set of roles to run your tests from your test plan.

**Build, Deploy and Test using Visual Studio Lab Management will be demonstrated using the below case study in future editions of this document.

We will now learn Coded UI automation features as well as our recommended automation framework and best practices in rest of the document.

 

Case Study: Coded UI Automation

 

Case Study

You have been given the task to test the basic functionality of Microsoft Bing www.bing.com and automation is in scope. You know that Microsoft Visual Studio Coded UI can be used to automate your functional tests. We assume that you have already written your functional test using MTM

We are going provide guidance on Coded UI automation using a real world case study. We assume you are familiar with Microsoft Test Manager for writing test cases (otherwise please jump to Get started section in Appendix)

Here is a sample snapshot of your test cases in MTM:

image

In subsequent sections, we will present the various approaches and steps involved in Automation Development Lifecycle that you should take to achieve your objective while following the automation standards and guidelines that are recommended.

 

Step 1: Automation Planning

Like Project Planning or Test Planning, Automation planning is equally important to ensure that the teams are not directly jumping into automation scripting without taking all the important factors into consideration which are extremely critical for providing accurate estimates, deciding the right framework, choosing the right approach, the long term maintenance of automation and getting early ROI (Return on Investment).

This activity will be primarily focused on identifying the feasibility and the scope of automation.

image

Figure 3: Steps involved in Automation Scope and Planning

Taking our case study, we will walk you through each of these steps below:

a) Identify Automatable Test Cases, Scenarios & plan Order of Execution

We must clearly know beforehand the test cases that are good automation candidates, the scenarios that can be converted into library methods for reuse and the sequence of execution if the tests are dependent on each other.

SL No.

Checklist

Description

Y/N

1.

Have you identified and marked the automatable tests as PLANNED in Test Manager?

Open your test cases in Test Manager that you want to automate and mark Automation Status = “Planned” for those

image

For the case study, we have marked the automation candidate as “Planned” as shown below.

Whereas the test which are not good candidates for automation are marked as “Not Automated” to show that they are out-of-scope for automation.

image

 

2.

Have you identified your data-driven test cases?

Identify your test cases that are data-driven (this will be required during automation design)

For our case study, look at the example of one data-driven test related to Bing where you want to perform search multiple times for the list of values provided as Test data

image

3.

Have you identified the common functionalities/scenarios OR SHARED STEPS which can be automated for Reusability?

Ensure that you identify the Shared Steps or Common functionalities that can be later be converted into methods inside your application specific libraries to reduce automation effort and redundancy

For the case study, here is one of the examples of Shared step or common functionality which can be added to the automation library.

Note: This will be used during automation design

image

4.

Have you identified the precedence / sequence of execution for your automated tests?

 

Ensure that you mark the sequence / precedence for the automated tests that have to be run

As shown below, define the order of execution for your automaton scripts using OrderID field

image

b) POC (Proof of Concept)

Now that we know the scope, we must also ensure that the application or technology in hand is actually supported by VS Coded UI Test by doing a POC on key scenarios. Many a times there might be custom controls and other components that are not automatable / supported by Coded UI out-of-the-box or need customization or are not worth automating due to low ROI. The outcome of this activity should help you decide your approach and next steps. You may mark the non-automatable test cases as out-of-scope for automation.

SL No.

Checklist

Yes/No

1.

Have you done a feasibility study to ensure VS 2010 Coded UI supports your application?

Identify key scenarios of your application and ensure that they are supported by VS 2010 Coded UI by coding few scripts and checking the results.

2.

Does your application have 3rd party controls or custom controls?

Ensure that you call out the tests which are not supported by VS 2010 as “out-of-scope” for automation.

3.

Testability: Have you worked with the development team to ensure that the properties of the objects are exposed and set appropriately for smooth automation?

It is extremely important to work with the development team to work on the testability right from the design phase to make automation easier later in the cycle.

c) Automation Estimation

The estimation will decide the success or failure of your automation project as it has been observed that automation can take much more time than anticipated if all the key tasks involved in automation lifecycle development are not clearly thought of while estimating.

The following major activities in each phase of automation must be estimated.

Automation Initiation

· Tool/Framework Feasibility Study

· POC

Framework Design/Implement

· Design and Implement Various Framework Components

· Testing the Framework Components and End to End Testing

· Training Resources on the Framework/Tool

· Environment Setup

Script Development Phase

· Script Creation

· Script Debugging

· Script Review

· Review Comments Incorporation

Script Execution Phase

· Environment Setup

· Result Analysis

Follow the below checklist while coming up with you initial estimation apart from effort for automation design and execution.

 

SL No.

Checklist

Y/N

1.

Check if you have included automation planning effort in your estimation including POC (Proof of Concept)- if any

2.

Check that you include environment preparation (installation, configuration) effort into estimations.

3.

Have you identified the Shared Steps or Common functionalities that can be later on converted into methods inside your application specific libraries to reduce automation effort and redundancy

4.

Ensure that you include effort for building framework reusable components (Libraries)

5.

Ensure that you include extra effort required if third party or custom controls are there in the application.

6.

Ensure that you include effort for code review, walkthroughs and compliance with the standards defined.

Ensure that you call out the tests which are not supported by VS 2010 as “out-of-scope” for automation.

7.

Ensure that you include effort for code review, walkthroughs and compliance with the standards defined

8.

Ensure that you include effort for debugging and lead time to resolve bugs discovered in the product (troubleshooting and

workarounds)

9.

Ensure that you include effort for reporting and result analysis.

Now that we have the clarity on the scope, feasibility and estimates, we can move the next logical step which is creating your automation solution

 

Step 2: Creating a new Coded UI Project & Adding project to Source control

You can create a project from scratch or by using an existing template but it’s important to add your project to source control for version management and change tracking.

SL No.

Topics

Description

Y/N

1.

Have you created new Coded UI project & Added it to Source Control (TFS)?

Every automation project must be source controlled.

image

Add project to Source Control by clicking the check box as shown

Project Check-in Path:

All application / project specific automation code tobe maintained under respective ‘project node’ of the TFS being used for the projects.

Recommended Source Control Path:

<Project-Node>/Main/Test/Test Automation

Refer to Appendix: TFS Check-In Policies and Best Practices for details.

2.

Open existing test project and using it as Template

Launch Visual Studio, Browse and open existing ‘CodedUISampleFramework’ template and add it to Source control. You can change the properties as per your needs.

image

Please find below a short description on the folder structure of the template project which will be used for case study:

1. Config: All your application configuration details and playback settings.

etc will go here

Example:

image

Also refer to: http://msdn.microsoft.com/en-us/library/a65txexh(v=VS.100).aspx

2. Library: All your libraries- application level, data access, exceptions, utilities will go here.

Please refer to Step 3

3. Resources: All your keys / strings that’s need to globally defined can be added here rather than hardcoding their values in code.

image

Example: The resource file key “SearchTimeOut” can be used to set playback settings as per your project needs without hardcoding it in your code.

 image

4. Scripts: Your actual test are stored in these .cs files along with components like Test Initialize, Test Cleanup etc

5. Test Data: These will contain your .CSV or .XML test data files for your data-driven automation test

6. UIMaps: These will contain your test object repository along with any test methods or assertions (if any)

image

7. Main Class file: One class that acts as a single point interface to all the test methods and contains instantiations of the UI maps

With next step, we are now entering into the most important phase of Automation Lifecycle Development which involves designing your automation framework. It is worth spending time on coming up with a good design rather than doing lot of rework later due to shortsightedness and eagerness to start scripting. I would strongly recommend you spend a good effort in coming with design/framework that suits your project requirement before writing your automation test.

 

Step 3: Automation Design & Development

Automation design and framework is one of the very important pillars of your automation success and it serves as a guiding light for your team members to follow a standard and consistent automation approach across the team.

In this section we will be walking through the automation framework design for Coded UI projects using our Case Study’s template project.

image

Figure 5: Proposed 3-Tier Architecture for maintaining automated test that promotes high modularity and maximum reuse with minimum maintenance effort in longer run

Follow the below steps for Automation design guidance:

SL No.

Steps

Description

1.

If you have created project from scratch, add Multiple UI Map files

(In the template project, we already have 2 UIMap files for Case Study)

Managing Object Repositories:

Single UI Map File:

By default only one UIMap File is created per project and it is appropriate for a project of small size

Multiple UI Map File: (We recommend using Multi UIMap files for modularization)

For large application, we should use multiple UI Map. Using multiple UI Map files can provide the following benefits:

- Each map can be associated with a logical subset of the application. This makes changes easier to manage.

- Each tester can work on a section of the application and check in their code without interfering with other testers working on other sections of the application.

- Additions to the application UI can be scaled incrementally with minimal effect on tests for other parts of the UI

You can add new UIMap files by selecting Add new Items option and then selecting CodedUI Test Map type and renaming it as per your needs.

image

The system will launch Coded UI Test Builder which can be used to add object properties to your UIMap file. Press Generate Code button (Alt+G).

image

For Case Study, you will find the UIMap files as shown below:

image

Open UIMap .CS files and add User friendly names to constructor:

image

Go to your Main Class file (Bing.cs) in our Case Study and instantiate each Multi UIMap file

 image

Please refer to Appendix: Managing objects using UITestEditor for more details

 

2.

Add/Create Libraries to your project

(For Case Study, We have already created libraries for Bing)

 

Managing Libraries:

Application Functional Libraries using Multiple UI Map files

Ensure common functionalities identified above in planning phase are automated as reusable methods which are then invokes from your Coded UI Test methods

Create functional libraries as per functional modules for your application.

Common Library / Helper Classes:

a) Ensure common utilities like SQL connection, Excel/ XML, String/Date handling etc. are referenced from common library repository in your automated solution (instead of creating them from scratch)

All common libraries need to be browsed and added to automation solution as “References”

image

b) Ensure that common helper classes which are technology specific like WPF, WCR, SharePoint, Silverlight, .Net etc. are referenced in your solution (if any).

Refer to Appendix: Managing Common Libraries in TFS

For our case study, we have created/referenced following libaries based on the Shared Steps and scenarios identified from ‘automatable test cases’ selected in Step 1 (Automation Planning)

image

Example of Application specific library methods

image

Example of Common/Utilies based methods:

image

3

Add your CodedUI scripts

/

Test Methods

 

Automate your ‘automatable test cases’ as CodedUI Test Methods using application libraries, utilities and UI Maps defined above

a) Set the test context which provides information about and functionality for the current test run.

image

b) Test Initialize: To perform steps before running each test like instantiating UIMap files, setting TestContext for logging etc.

image

image

c) Add your Test Methods

image

As you can notice above that we have highlighted certain things which are not recommended like using static playback interval or hardcoding test data. We will see in next section how to handle these.

d) Test Cleanup: To run code after running each steps

image

 

4.

Adding Checkpoints

/

Assertions

 

For validation in Coded UI Testing, you need to use “Assertions”

- Creating assertions using CUIT (Coded UI Test Recorder): You can create assertions without coding by using out-of-the-box feature provided with Coded UI

image

Choose the property you want to validate and Click “Add Assertion”.

- Creating assertions by hand coding: You can create assertions by writing you own code and capturing properties against expected values to validate at the run time.

Verify.WaitForControlPropertyEqual(BING.SearchResultsUI.searchText, "Text", "Bill Gates", 15000);

e.g. We have a method in our Utility “Verify” that waits for control property to be equal to some text value for certain period and returns PASS if found otherwise FAIL

image

 

5.

Make your scripts data-driven

Data-Driven Test

Ensure every variable is parameterized by passing the test data to each test using data-driven capabilities in VS 2010.

Right-click on the Coded UI test and select Properties, to view the properties of the test

image

To start making this a data-driven test, we have to first create a data source for the test to draw from. On the Data Connection String property, click the ellipse button to start the New Test Data Source Wizard

There are three options for creating a data source:

Database -- which allows you to connect to a database or Microsoft Excel spreadsheet

CSV File -- which allows you to use a comma-delimited file

XML File -- which allows you to use an XML file

image

When you add a data source A Data Source attribute is added to the Coded UI Test.

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\data.csv", "data#csv", DataAccessMethod.Sequential), DeploymentItem("data.csv"), TestMethod]

For our Case study, let’s look at one of our data-driven test:

a) We have a method in our data access library (Utilies) to read the data from data sources using the test context

image

b) Another method as part of Application library returns the data from data source and inputs the same to application using the above data access library method

image

c) Test data source which is stored in .CSV format

image

d) Our Data-driven test method calls the above method as part of our functional

image

 

Now I suppose you have your automation tests candidates designed and developed. After you write and debug your scripts its important to run them in a batch or as part of a suite. There are various way to do that and factors to keep in mind as we will see in next section.

 

Step 4: Automation Execution & Deployment

Ensure you have configured test settings to capture logs, code coverage, test impact etc. and you also need to keep in mind that your script should be able to successfully run in multiple environment (for ex. Test to UAT)

After automation design and debugging is completed, you can now run and deploy your automation scripts using the below steps:

SL No.

Areas

Description

1.

Configuring Test Settings

Test Settings

a) Data and Diagnostic: Enable appropriate diagnostic are selected as shown below (Code Coverage, Event Log, Test Impact etc.)

image

b) Define other settings like Roles, Test Timeouts, Setup and Clean scripts

image

2.

Deploy your test to multiple environments

 

Deployment to different environments: We want to run the same test across multiple environments to ensure everything is still working correctly.

Development-> Test -> UAT -> STAGE

Example: We want to run these tests after each deploy to each environment. Each environment has as a different URL, username and password.

public UIMap()

{

// Bind the parameters using Environment Variables.

string testServer =

Environment.GetEnvironmentVariable("TestServer");

string testUserName =

Environment.GetEnvironmentVariable("TestUserName");

string testUserPassword =

Environment.GetEnvironmentVariable("TestUserPassword");

}

Also refer: http://blogs.msdn.com/b/gautamg/archive/2010/02/23/how-to-get-same-test-running-under-different-environments.aspx

 

3.

Command Line Execution (MSTest.Exe)

Grouping & Classifying Test Methods using various parameters

It lets you run groups of tests based on their assigned categories without the requirement to maintain test lists.

Go to Test View and you can filter and view your tests by setting these parameters

image

MSTest.EXE Options:

MSTest.exe is the command-line command that is used to run tests. This command has several options that you can use to customize your test run. You can specify these options in any order on the MSTest.exe command line.

Example:

mstest /testcontainer:"C:\TestProject2\generictest1.generic" /test:testproject32\generic

Refer to http://msdn.microsoft.com/en-us/library/ms182489.aspx

With this, we come to the end of our case study where we walked you through the complete automation development life cycle that involved Automation Planning, Automation Design and Development, and finally Automation execution and Deployment.

Automation scripts are just ‘Code’ at the end of the day and we can’t deny the importance of having high quality of code and best practices adopted for making our automation tests not only readable and easy to troubleshoot but also for long term maintainability.

 

Coding standards and best practices

We recommend following the below checklist and recommendations for your automation code. It is the responsibility of the entire team to follow these and imbibing a culture of peer and lead review of the automation code on a regular basis.

 

Checklist

 

SL No.

Topic

Description

1.

Object Synchronization

over static wait/delay

These synchronization points will make the scripts more resilient and robust.

Wait for Control options:

Ensure that you insert synchronization points by waiting for the object to be ready/exist/enabled etc. before trying to perform any critical action.

Example: WaitForControlReady(),WaitForControlExist() etc

Static Delay:

Ensure that you use WaitForControl options as much as possible but in some unavoidable cases where you must have to hard wait/sleep use Playback.Wait() API instead of Thread.Sleep() API.

2.

Exceptions and Error Handling

Ensure that you use the exception handling feature in all your scripts that C# provides i.e. try, catch and finally to do exception handling. The try encloses the statements that might throw an exception whereas catch handles an exception if one exists. The finally can be used for doing any cleanup process.

The general form try-catch-finally in C# is shown below 

try
{
// Statement which can cause an exception.
}
catch(Type x)
{
// Statements for handling the exception
}
finally
{
//Any cleanup code
}

3.

Logging

Sample Logging Code:

1: [TestMethod]

2: public void CodedUITestMethod1()

3: {

4: Console.WriteLine("Console.WriteLine()");

5: Console.Error.WriteLine("Console.Error.WriteLine()");

6: TestContext.WriteLine("TestContext.WriteLine()");

7: Trace.WriteLine("Trace.WriteLine()");

8: Debug.WriteLine("Debug.WriteLine()");

9: }

If you check the test result window, you should see output like –

image

Each of these ways have their own advantages and disadvantages -

TestContext.WriteLine:

Advantage - Shows up property in the separate section in test result. It is meant for this purpose only.

Disadvantage - You will have to pass TestContext around from you main test class to other classes (like UIMap class in Coded UI Test) to use it.

Recommendation – Prefer this over other methods for tracing in test code.

Trace.WriteLine:

Advantage – Shows up in VS Output window too during debugging.

Disadvantage - The message here could be lost among other trace messages from other components (or product code).

Recommendation – Use it in your product code but avoid in test code. That is good way to separate out messages from product code vs test code. You can use this though in certain scenarios where either TestContext is not there or you want to determine the sequence of operation between test & product code

Debug.WriteLine: Same as Trace.WriteLine except that this shows up only for Debug build and is no-op in Retail build.

Console.WriteLine and Console.Error.WriteLine: These, though work, are tricky. The test harness redirects the Standard Output and Standard Error to capture the output\error from your product code and not for tracing. So, the recommendation is to avoid using these.

In short, use TestContext.WriteLine wherever possible.

4.

1.

Naming Conventions

When you create a method, use a meaningful method name instead of the default name. A meaningful name helps identify the purpose of the method.

In the application under test, use meaningful names when you create the UI controls. This gives more meaning and usability to the automatically generated control names.

5.

Comments

Have extensive and meaningful comments. Remember that code written by you will be around for a long time and has to be understood, extended and debugged by others who do not have the entire context you had when the code was originally developed. Unless there are good comments, it is hard for even the owner to understand the code few weeks or months later.

6.

Startup & Cleanup Scripts

Using Code: Create a test in your test project. In the test class, create methods with the [TestInitialize] and [TestCleanup] attributes. They will be run before/after each test method.

Or, if you want to run before/after all test in that class, create static methods with [ClassInitialize] and [ClassCleanup] attributes.

Lastly, to run before/after all tests in the assembly, create static methods with [AssemblyInitialize] and [AssemblyCleanup] attributes.

We are also providing a compilation of best practices collected from various forums which can be used as a reminder when writing coded UI test.

 

Do’s and Don’ts of UI Automation

Do(s)

o Each recorded method should act on a single page, form, or dialog box. Create a new test method for each new page, form or dialog box.

o Use the Coded UI Test Builder whenever possible.

o Explicitly set focus to the window on which the test Case is expected to input data.

o When possible, limit each recorded method to fewer than 10 actions. This modular approach makes it easier to replace a method if the UI changes.

o Create a separate UIMap file for each module in your application under test. For more information, see Testing a Large Application with Multiple UI Maps.

o If you are creating assertions by coding with the API, create a method for each assertion in the part of the UIMap class that is in the UIMap.cs file. Call this method from your test method to execute the assertion.

o Capture screen shots for failures. Helps in debugging.

o Leave the UI in a known state after a test Case is done executing. E.g.: Close the wizard even if the test Case is to test the first screen of a wizard by cancelling out of the wizard after the first screen.

o Validate that the object being created using the UI with the one being stored in the backend system

o Log before you do something, not after.

o In code reviews for test cases, or new framework automation support review the log messages, is it clear what the test did from just the log?

o Log the origin of messages. If the framework logs, say that it logged, if the test case logged, say that.

o Have two assertion modes that are configurable: 1. Fail instantly. 2. Delay assertion of failure until the test has completed. Steps might be mutually exclusive, you’re losing coverage.

o Log non-fatal exceptions so as not to abort a test, bubble fatal exceptions up to the test and let the exception assert failure.

o Log every valid UI operation being performed in the test Case.

o Use resource files for all data required to be entered in the UI.

o Use Refactoring: Refactoring implies removing a block of code that is being used repeatedly throughout the program into a single function. This helps in reuse of code and makes the code cleaner, and improves readability. 

o Use Constructor of classes for meaningful things: In any class avoid unnecessary overloading of constructors. Minimize the amount of work done in a constructor. Constructors should mainly be used for initialization of members. It is always good practice to have accessory methods (get/set) to expose member variables and also initialize them.

o Using string. Compare () instead of "==" or "Equals ()": It is advisable use string.compare() as in that case we don't have to worry about NullPointerException, unlike using Equals() -- you have to make sure that the object that calls Equals() is not null. 

o Using List<class name> instead of Arrays: Arrays are not type safe, so it is advisable to use the inherent .Net 2.0 collection objects like IList<T>, ICollections<T>. They provide additional type-checking during compile time.

o Use “this.”: Whenever you use a member variable of class, it is a good practice to put "this" in front of the variable. This improves readability and avoids conflicts when the parameter name and the member variable names are same.

o Using .NET attributes for test cases: Attributes provide a mechanism to enable additional data to the Test Code during runtime and it also helps in keeping information associated with the Test Case in the code itself.

Don’t(s):

o Do not modify the UIMap.designer.cs file directly. If you do this, the changes to the file will be overwritten.

o Do not log multiple times.

o Do not sleep after every UI operation.

o Do not give unusually long timeouts for every major operation.

o Fail immediately after an unexpected screen.

o Do not re-launch the UI application for every test Case as it is a time consuming process.

o Test cases should never have hard-coded strings. This includes control ids, menu paths, etc. Even control IDs and menu paths change over time.

o Do not use sleep

o Avoid too many parameters in a Method/Function. It is best practice to avoid passing too many parameters to a function or method. This indicates lack of abstraction. In this case encapsulating the parameters in a separate class or struct may help.

o Avoid Lengthy Functions: If a function is longer than a page, it is a good practice to break it up into smaller functions. However, if the code has a switch statement or straight line code with no loop back, then it is still OK, but in almost all other cases, the code can be simplified by splitting it up into multiple functions.

o Avoid Hard-Coded strings: Avoid the usage of hard coded strings in the code. Instead use the constants utility to store them.

 

Appendix

 

i. Getting Started with VS 2010 Coded UI

 

Getting Started

 

Online Help

Testing the User Interface with Automated UI Tests

Forum

Visual Studio UI Automation Testing (includes CodedUI)

Product Overview

Coded UI Test

Webcasts & Videos

Functional UI Testing
Visual Studio Team System 2010: Manual Test To Coded UI Test

Guidance and References

Best Practices for Coded UI Tests

Coded UI Test Bloggers

Anutthara Bharadwaj
Gautam Goenka
Balachander G. Subramaniam
Rubel Singhal
Rituparna Paul
Team Blog

What’s new in Beta2

What’s new for testers doing UI Automation

 

ii. Visual Studio 2010 Installation

This step is required to ensure that environment is setup and configured to get started with automation,

- Installation: Have you installed VS 2010 Ultimate?

Go to Microsoft.com Download page

- Installation: Have you installed VS 2010 Feature Pack 2

Refer to http://msdn.microsoft.com/en-us/vstudio/ff655021.aspx to find out new features in FP2

- Installation: Have you connected to you Source control (TFS node)?

Go to VS 2010 Ultimate -> Team -> Connect to Team Foundation Server

Add your TFS server name, Choose Project Collection, Select your team project and say Connect

 

iii. TFS Check-in Policies & Best Practices

- Ensure that policies enforced by project administrator are met

Tip: For example “comment” must be entered every time checking the code

http://msdn.microsoft.com/en-gb/library/ms181460.aspx

Apart from that, following are available by default

o Builds:   Requires that the last build was successful before a check-in.

o Code Analysis:  Requires that code analysis is run before check-in.

o Testing Policy:  Requires that certain tests are completed before check-in.

o Work Items:   Requires that one or more work items be associated with the check-in.

http://msdn.microsoft.com/en-gb/library/ms181411.aspx

http://msdn.microsoft.com/en-gb/library/ms245460(v=VS.100).aspx

- Ensure that any custom policies enforced by administrator are met.

- As a best practice, check-in the files at the end of the day

- Code Branching and Merging

image

One of the most common branching strategies is to align branches with product releases. A branch holds all the software development assets for a single release. Occasionally, you must merge updates from one release to another, but they usually never merge. You discontinue a branch when you discontinue its release.

The mechanics of branching in TFS are simplified to a single right-click à Branching and Merging | Branch command.

Figure 6: Courtesy: ALM Rangers Codeplex Branching guidance

If you have more than one work (DEVELOPMENT) branch, forward integration to all work branches should occur as soon as any branch integrates into the MAIN branch. Because the MAIN branch is kept stable, forward integration is safe..

Refer to http://msdn.microsoft.com/en-us/library/ee782536.aspx and http://tfsbranchingguideiii.codeplex.com/ for detailed guidance from ALM Rangers team

- Ensure Reverse Integration and Forward Integration process when multiple teams (Onsite Offshore are working together on same engagement)

FORWARD INTEGRATE (FI) – merges from parent to child branches.

REVERSE INTEGRATE (RI) – merges from child to parent branches

Refer to http://branchingguidance.codeplex.com/wikipage?title=Code%20Promotion%20Best%20Practices

- Gated Check-ins: Ensure the solution is built before the automation code check-in

image

By using a gated check-in for the MAIN branch, you help make the reverse integration much easier because quality gates help avoid conflicts or errors in the MAIN branch. For more information, see http://msdn.microsoft.com/en-us/library/dd794776.aspx and http://blogs.msdn.com/b/patcarna/archive/2009/06/29/an-introduction-to-gated-check-in.aspx

http://intovsts.net/2010/04/18/the-gated-check-in-build-in-tfs2010/

When this trigger is selected for a build definition, any check-in that is made to a file that is mapped in the associated workspace will trigger a verification build. If the build succeeds, the changes will be submitted to the repository. If the build fails, the changes are not allowed to be submitted and must be fixed and resubmitted.

 

iv. Coded UI Frameworks

 

Details of each UI Framework Supported - Differences, Known Issues and Workarounds

 

Web

IE Plugin Part 1
IE Plugin Part 2
UI Test Framework Firefox support

WinForms

WinForms Plugin Part 1
WinForms Plugin Part 2

WPF

WPF Plugin Part 1
WPF Plugin Part 2

SharePoint

UI Test Framework Sharepoint support

MFC/Win32

UI Test Framework MFC support

 

v. Managing common libraries in TFS

All common code and libraries to be maintained at a centralized node which wil be accessible (read-only) to all the projects/apps to be included for reusability.

Note: Only the automation group member will have the add/edit permission on this node to control the change.

Common TFS Project & Node: < placeholder >

Library Path: Automation/Libraries

 

vi. Data driven testing

Use below link if you need more information about Data driven testing using Coded UI and access/store data in MS EXCEL from Coded UI

Data Driven Testing by Mathew

http://msdn.microsoft.com/en-us/library/ee624082(VS.100).aspx

http://msdn.microsoft.com/en-us/magazine/cc163536.aspx

 

vii. Managing object repository using UI Test Editor

This is a new feature launched in FP2 which lets you better manage your object repository.

image

The Coded UI Test Editor toolbar offers the following commands:

1. Find helps to locate UI actions and controls.

2. Delete removes unwanted UI actions.

3. Rename changes the names for test methods and controls.

4. Properties Opens the Properties Window for selected item.

5. Split into a new method lets you modularize the UI actions.

6. Move Code adds custom code to your test methods.

7. Insert Delay Before adds a pause prior to a UI action specified in milliseconds.

8. Locate the UI Control identifies the location of the control in the UI of application under test.

9. Locate All helps to verify control property and significant changes to the application’s controls.

Refer to: http://msdn.microsoft.com/en-us/library/gg269469.aspx

 

viii. Extending Coded UI

VS 2010 Coded UI support extensibility for technologies which are not supported out-of-the-box like Excel or custom controls.

Refer this example for WPF calendar support

http://blogs.msdn.com/b/tapas_sahoos_blog/archive/2010/12/10/adding-new-control-support-in-a-coded-ui-test-plugin.aspx

 

ix. Support & Help

- Discussion forum (External)

http://social.msdn.microsoft.com/Forums/en/vsautotest/threads

Saturday, December 10, 2011

Intelligent selection of test data by applying learning from Marketing Research

 

1. Abstract

2. Prospects Hot Candidates

3. Proposed Solution

4. Process: Intelligent Sampling Process Flow & Engine

5. Sampling Algorithms selected for Database Sampling

6. Cost/Benefit Analysis for the selected algorithms

7. Extended Features

8. Benefits

9. References

  1. Abstract

    When the data volume is not too huge, the entire data of the population can be validated as a part of the test phase (Unit testing/ Integration Testing/ System testing). Such a total study gives an excellent confidence on the quality and coverage which can be very expensive method, because validating all the data involves huge hardware cost, resource dependency and the time required for the completion of the activity. Remember, too, that the objectives of a project do not always require an absolutely exact account of the entire population.

    Sampling is one approach which can be adopted when the data is voluminous. Note that sampling does not mean that you were not equally interested in all the items in the population. On the contrary, you would like to study all of them, but you pick the sample for practical reasons. Perhaps you have a population of millions of objects and it is impossible to reach even a major part of them. Also in those cases (with populations of, say, up to 10,000) where you might choose to study every object, the sampling study may be a prudent choice, because it saves your time and you can then use the time you save to study the sampled items more carefully.

    Few months back, we were in the middle of testing our application, which processes more than 1.50 TB of data and takes approx 36 hours of time when we received this great news that Microsoft was voted as the Best Employer by BT TNS Mercer’s Best Companies to work for in India & it was no doubt a moment of pride but i wasn’t interviewed and none of my friends were either but it struck us how they were still able to echo our feelings so well (for most of us i spoke to were not surveyed)

    After thinking it over for a couple of days we realized that this very same concept is very much applicable to our IT solution as well. Why do we have to process 1.5 GB of data and wait for 36 hours to run or why should i make up the data by generating it randomly and taking the risk of compromising on the coverage when i have access to customer/ production equivalent data (non PII)?

    The Big Question:

    “Why didn’t we do intelligent sampling yet?”

    The Big Question:
    “Choosing Sample Test Data from Population/ Customer data is not a challenge but how do you ensure that sample is a GOOD sample”

    I agree, “GOOD” is a quite subjective term. Let me rephrase
    “How do you ensure that the sample chosen is a GOOD representative of your entire data population?”

  2. Prospects Hot Candidates:

    Bigger the Size of font in the image below, more is the importance & applicability.

  3. Proposed Solution

    Best Sample selection based on your requirement is the true objective. There are multiple solutions in silo to cater to specific scenarios.

    What better place to have this solution than in Visual Studio DbPro

  4. Process: Intelligent Sampling Process Flow & Engine

    1. Selection Criteria

      i) Population Selection

      The data set which needs to be sampled should be chosen first. This can be chosen based on the parameters of

      1. Size – the dataset for sampling should be of reasonable size (>500 MB). This is to make the process of data sampling worth the effort
      2. Complexity – If the dataset to be sampled is of lesser complexity, data generation approaches may be more suitable. It is for complex data set which involves some business rules plus data integrity to be maintained where subset data selection would help.
      3. Test cases to be run – Subset data selection is for a scenario where number of test cases to be run is high and considerable amount for data regression is required
      4. Variety in data – The dataset to be sampled contains a variety in data. For Eg. Databases of an enterprise system would be ideal. On the other hand one which contains only Taxonomy related data or domain values may not be suitable for sampling

      ii) Business Rules / Requirements or user input / Sampling Frame

      Whenever a sample data is selected from an existing database, one needs to ensure that the underlying business rules are intact. In order to cater to negative test case scenarios, some sample breaking the rules is also fine. However on the whole, business rules have to be maintained.

      Most datasets where sampling is required also have some ‘business rules’ attached to them. For Eg. Expense related calculations may need checks of exchange rates; billing related calculations may need checks of status and so on. If there are business rules which are critical to the transformation of the system to be tested, these can be input by the user, to ensure that the sampling happens accordingly.

      iii) Get Expected Cost Associated From Sample from the User.

      The user should also be able to select an expected associated cost to the sample which would be created. This cost would be based on the size/time taken for the sample generation and coverage based on data variety included in the sample. The expected associated cost entered by the user would be used to prioritize on the sample algorithms to be run, which are known to provide the expected cost. Running these algorithms with the expected cost as an input would help reach the required end result and propose different data sampling options to the user.

    2. Sampling Method

      i) Data Profiling Required - Domain/Transactional Data

      In order to go for effective sampling, we also recommend categorizing the existing dataset into tables containing ‘Master’* data and those containing transactionaldata.This could be an outcome of the Data Integrity relationship detected, or a step within the sampling engine while applying the algorithm. This categorization helps in selecting required amount of samples from each of these tables as well as selecting an appropriate sampling method. For instance, if a table contains date/calendar information, thus making it fall under a master category, would not need to be sampled or reduced; where as one containing daily transactions of an account can be a candidate for sampling. Detection of data set impacting the coverage is critical before coming up with the sampling plan.This would be done based on

      1. Profiling the data and checking for columns which contain distinctively unique values which are sure to impact the test case/data coverage.

      2. Get input from the user based on his prior knowledge.

      Once this input is provided, save it to use during generating the sampling plans.

      ii) Generate Plans with associated cost

      Generate the different plans possible for data selection and provide the‘cost’ associated with it based on the rules applied prior to sampling This cost would be calculated based on following factors:

      • Expected size of the sample
      • Expected data coverage of the sample.

      The plans along with the indicator of cost associated with each of the plan would be provided to the user. Thereafter, the user could either choose the best recommended plan, or go for another based on his discretion.

      iii) User to choose plan or go for regeneration

      If the user is not satisfied with the plans and their cost, he can ask for a regeneration of plan which would involve trying out a different set of inputs or providing different columns for driving data coverage.

    3. Sampling Engine

      The sampling engine is expected to perform all of the above steps after scanning through the target population, as well as consuming specific inputs provided by the user. Next Steps are:

      i. Implementing the sampling plan

      ii. Reviewing the sampling process

      The sampling engine is the core of the data selection process. Stages involved within the sampling engine:

      i) Building the Sampling Rules

      • The sampling rules would be built based on the Data Integrity Checks run on the database as well as after profiling the data for any exceptions to business rules and categorizing data sets into master or transactional.
      • This could also include setting any delta rule condition (or in other words reducing the scope of data to be sampled
        When a Data Volume is sampled already, the next time the Sampling Engine Runs on the same dataset, the sample is generated for the new added data rows only. This would save time, effort and money and would give more ROI to the proposed feature inclusion in VSTF DB Pro.
      • These sampling rules would form the underlying conditions which need to be satisfied by the selected database.
      • This ensures that after selecting a sample from the source system, when we run our ETL process on it, the ETL should not break due to incorrect sample set.

      ii) Apply algorithm

      • The algorithms chosen for application within the sampling engine are covered in next section (Section 7). Each of the above algorithms would be applied to the source system data and cost for the same would be calculated

      iii) Calculate Sampling Cost :

      We define sampling cost based on two parameters

      • Sample Size
      • Data coverage

      The Sampling Cost would be calculated based on the Size (This could be Row Count of each table available in the sample or the actual Size in MB/GB). This percentage reduction in Size would act as one parameter in Cost. Data Coverage in the sample would be detected differently by differently algorithms. If the algorithm is probabilistic, frequency of data would be a key in determining coverage, if statistical algorithm is used, distinct values in columns would form key criteria and in T-Way, the requirements would be primary. This would be covered in detail in the subsequent section.

      iv) Check for correctness and update the Sampling Rules

      Identify if the sample satisfies the basic rules and if the user wishes he/she could opt for re-sampling, and this time fine-tune the rules as well as inputs provided.

      v) Log Errors

      Any errors encountered during the process of profiling/sampling method generation would have to be logged and reported.
      The diagram below shows an end-to-end mock of the screens that could show up during this process of sampling method generation and selection and the various inputs that need to be provided by the user and the actions that take place.

  5. Sampling Algorithms selected for Database Sampling

    Within any of the types of frame identified above, a variety of sampling methods can be employed, individually or in combination. Factors commonly influencing the choice between these designs include:

    • Nature and quality of the frame
    • Availability of auxiliary information about units on the frame
    • Accuracy requirements, and the need to measure accuracy
    • Whether detailed analysis of the sample is expected
    • Cost/operational concerns

    a) Probabilistic Sampling Methods - Multi-Stage Sampling

    In most real applied application, we would use sampling methods that are considerably more complex than simple methods like (random sampling, cluster, stratified, systematic etc). The most important principle here is that we can combine the simple methods in a variety of useful ways that help us address our sampling needs in the most efficient and effective manner possible. When we combine different probabilistic sampling methods, we call this Multi-Stage sampling. By combining different sampling methods we are able to achieve a rich variety of probabilistic sampling methods that can be used in a wide range of social research contexts. This leads to less Sampling Error by relying on multiple randomizations by choosing random samples of preceding random samples.

    3-Stage Multi-Stage Sample Process

    1. Select the clusters from the population
    2. Select all strata from each clusters
    3. In next stages, select additional random sample from selected strata units and so on
    4. Finally all ultimate samples selected are chosen

    b) Statistical Sampling – Purposive Sampling

    The difference between non-probability and probability sampling is that non-probability sampling does not involve random selection and probability sampling does. Most sampling methods are purposive in nature because we usually approach the sampling problem with a specific plan in mind. In purposive sampling, we sample with a purpose in mind. We usually would have one or more specific predefined groups we are seeking. Useful when you need to reach a targeted sample quickly and where sampling for proportionality is not the primary concern.

    For ex. have you ever run into guys in a mall asking people if they could interview them? Most likely they are conducting a purposive sample. They might be looking for Caucasian females between 30-40 years old as that’s their need and they do that by estimating

    One caveat is that you are also likely to overweight subgroups in your population that are more readily accessible.

    c) T -Way Sampling Method

    T-way Testing is a type of interaction testing which requires that for each t-way combination of input parameters of a system, every combination of valid values of these t parameters must be covered by at least one test case. It involves selecting test samples in such a manner that it covers all the t-wise interactions between the parameters and the possible values of a given system.

    For example, Let us consider Employee Entity which contains attributes like Employee Discipline and Employee Role. Also, consider the Country Entity has attributes like CountryName and IsActive. Correspondingly, the possible values Employee Entity and Country Entity are as shown below.

    The total Number of Combinations possible for values between Employee and Country = 3*2*3*2 = 36 combinations. We can also say, that our code will work if I have 1 combination, but neither of them strikes an optimal balance between Quality Assurance and Delivery!

    Applying the t-way testing methodology and setting t=2, we get the Dataset which has only 9 combinations


    Similarly, when t=3, the number of combinations increase but the data coverage also increases and hence the sample size increases, and it strikes an optimal balance between the size of the dataset and the code coverage. A sample run would generate 14 records for the current example.
    We propose, set t=3 to find out the optimal data combination both in terms of coverage and time.

  6. Cost/Benefit Analysis for the selected algorithms

    This section will be used internally by the system to determine best algorithm for a selected population by doing a cost/benefit of each algorithm statistically

    a) Cost Benefit for Statistical Algorithms


    b) Cost Benefit for Statistical Algorithms


    c) Cost Benefit for T-Way Algorithm

  7. Extended Features:

    7.1 Avoid Re-sampling of the Sampled Data to increase data coverage

    Sampling schemes should be generally defaulted to Without Replacement (‘WOR’). No element should be re-selected more than once in the subsequent sampling attempts if it’s already sampled in one of the past attempts (unless RESAMPLI NG = 1 is explicitly configured by the user). By Default, Re-Sampling Flag is set to 0 to ensure that already sampled data doesn’t always get picked in every sample run and rest of the data should get a fair chance of getting selected.

    For example, if we catch fish, measure them, and immediately return them to the water before continuing with the sample, this is a WR design, because we might end up catching and measuring the same fish more than once. However, if we do not return the fish to the water (e.g. if we eat the fish), this becomes a WOR design.

    Marking already sampled data helps ensuring that the already sampled data is not picked in the future runs unless we run out of data. This basically follows the assumption that the sampling method chosen by the user / system picks the best available sample for the first run but say for the second run we don’t want to pick the already sampled data (selected based on run #) and so on.

    7.2 Weighted Sampling

    Weights can be provided by the user in the proposed user configuration settings to give more value / importance to a specific column which is more important based on the business need.

    More generally, data should usually be weighted if the sample design does not give each individual an equal chance of being selected. In many situations the sample fraction may be varied by stratum and data will have to be weighted to correctly represent the population.

    Real World Example, a simple random sample of individuals in the United Kingdom might include some in remote Scottish islands who would be inordinately expensive to sample. A cheaper method would be to use a stratified sample with urban and rural strata. The rural sample could be under-represented in the sample, but weighted up appropriately in the analysis to compensate.

  8. Benefits

    The following are direct /indirect benefits to the various stakeholders like Dev, Test, PM’s & Business Community.

    • Overall Test Execution Time Reduction
    • Higher Requirement & Test Coverage
    • Higher Code Coverage
    • Effective Unit Testing & Functional Testing -Boundary Values, Equivalence Partitioning
    • Reduces Hardware Cost for IT
    • High confidence while delivering to Test, UAT & Production
    • Increased Domain knowledge & business understanding of the resource while choosing & profiling the sample data
    • Earlier detection of potential Data Quality issues by analyzing the data (while profiling) for sampling
  9. References

    http://en.wikipedia.org/wiki/Sampling_%28statistics%29

    http://doi.acm.org/10.1145/1102351.1102456

    http://www.ai.mit.edu/projects/jmlr/papers/volume3/scheffer02a/scheffer02a.pdf

    http://www.uiah.fi/projects/metodi/152.htm

    http://en.wikipedia.org/wiki/Quantitative_marketing_research

    http://en.wikipedia.org/wiki/Expectation-maximization_algorithm

    http://www.gabormelli.com/RKB/EM_Algorithm

Authors

Raj Kamal (rajkamal)

Web Services Test Automation Guidance using VS 2010 - Unit Test & Web Test

 

All your wait is over. Finally its out Smile  http://webservicestesting.codeplex.com/

<<Please refer to Web Services Automation Guidance (VS 2010 Unit Test & Web Test).PDF http://webservicestesting.codeplex.com/releases/view/78473#DownloadId=312126 for detailed documentation>>

clip_image001

The artifact will provide Web Services Automation guidance for Functional & Performance Testing leveraging VS 2010. The document will provide recommendation on using either Unit Test or Web Test for functional testing depending on your project and test objective as will be later covered in the document. Load Test will be used for Performance Testing in both cases.

The primary objective is to propose a viable web services test automation approach & reusable libraries to customers, partners and consultant. It will also be a step in standardizing web services automation using VS 2010 platform across the Industry and filling the gaps by extending our tools as suggested in the talk. The document can also be used as a quick jump start guide for beginners to get started on Web Services Automation Testing.

Have fun guys. We want to hear from you.

Thanks,

Raj, Vipul, Ranjit &  Gunjan

Thursday, March 3, 2011

Microsoft Case Study: Visual Studio 2010 Automation Testing (Raj Kamal)

 

“We wanted a test process that would be faster and more productive. We achieved that by using the automated tools in Visual Studio 2010.”

Raj Kamal
BI Engineering Automation Team Lead, Microsoft IT

http://www.microsoft.com/casestudies/Case_Study_Detail.aspx?CaseStudyID=4000009261