Test Automation Coded UI Preview
Test Automation Coded UI Preview
Test Automation Coded UI Preview
Navneesh Garg
Vaibhav Mittal
Microsoft Visual Studio 2015
Microsoft Coded UI
Step By Step Guide
All rights reserved. No part of this publication may be reproduced, stored in a retrieval
system or transmitted in any form or by any means, electronic, mechanical, photocopying,
recording, scanning, or otherwise without either the prior written permission of the
author or authorization through payment of the appropriate per-copy fee to the Author.
For permission please contact author at adactin.com/contact.html.
Navneesh Garg
Vaibhav Mittal
ISBN - 978-0-9922935-4-3
This document also contains registered trademarks, trademarks and service marks that
are owned by their respective companies or organizations. The publisher and the author
disclaim any responsibility for specifying which marks are owned by which companies
or organizations.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE
AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO
THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND
SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION,
WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY
BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE
ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR
EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT
THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING OR
OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED,
THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT.
NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES
ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS
REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE
OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE
PUBLISHER ENDORSES THE INFORMATION. THE ORGANIZATION OR WEBSITE
MAY PROVIDE OR MAKE OWN RECOMMENDATIONS.l
2
Contents
3
Test Automation using Microsoft Coded UI with C#
4
Contents
5
Test Automation using Microsoft Coded UI with C#
6
About the Authors
Navneesh Garg
Navneesh Garg is a recognized test automation architect and corporate trainer, specializing
in test automation, performance testing, security testing and test management. As a tool
specialist, he has worked on a variety of functional automation tools including Microsoft
CodedUI, Selenium, HP QTP/UFT, TestComplete, TestPartner, SilkTest, Watir, RFT, and
on varied technologies including Web, Java, .NET, SAP, Peoplesoft and Seibel.
His previous books Test Automation using Unified Functional Testing and Test
Automation using Selenium WebDriver are among best - selling books on test automation.
These books have consistently ranked among the top 100 testing books on Amazon.
He is an entrepreneur and founder of several successful IT companies which encompass
the Adactin Group, CresTech Software, and Planios Technologies.
As an experienced corporate trainer, he has trained professionals in Microsoft CodedUI,
Selenium and other test tools across a wide range of global clients such as Macquarie Bank,
Corporate Express, Max New York Life, Accenture, NSW Road and Maritime Services,
Australian Dept of Education, HCL Technologies, Sapient, Fidelity Group, Adobe Systems,
and many more. He has training experience in diverse geographies such as Australia, India,
Hong Kong and USA.
As a technical test delivery head for his company, he has led and managed functional
automation testing and performance testing teams across a wide range of domains, using
commercial tools and open source tools. Certified in HP QTP, HP Quality Center, HP
LoadRunner, IBM Rational Functional Tester and as a Certified Ethical Hacker, he has
designed several high-end automation frameworks including using Selenium and its
integrations with tools like TestNG, JUnit, Selenium Grid, Jenkins and ANT.
Vaibhav Mittal
Vaibhav Mittal is a seasoned consultant with a vast experience in Information and
Technology. He has experience working on many projects in software development and
testing, exposed to multiple technologies including Microsoft .NET, Java, Oracle, ETL,
Business Intelligence and Analytics. His professional journey enabled him to work across
different geographies like USA, Europe, Japan and India with many esteemed organisations
like Adobe Systems, Oracle, Procter & Gamble, Pfizer and Novartis.
7
Test Automation using Microsoft Coded UI with C#
Vaibhav is Delivery Head with Adactin Group Pty. Ltd, Sydney. During his stint with
Adactin, Vaibhav has worked on various projects in Agile and other project management
methodologies. He is not only an experienced project manager but a tool expert in testing.
His wide knowledge in tools include Microsoft Coded UI, Selenium, UFT, QC/ALM and
many more.
Vaibhav, as a corporate trainer, prepares and delivers courses on various technologies
helping many professionals elevate their IT skills. He has presented papers at international
forums, which makes him a thorough and a passionate IT professional.
8
Preface
Our motivation for writing this book stems from our hands-on experience in the IT and
testing domains and the experience we have gained as automation consultants working in
numerous complex automation projects.
Coded UI, being an automation tool from Microsoft, is gaining huge popularity but still
is not perceived as an easy to use tool especially by testers due to a variety of reasons,
including tool setup, programming background and support issues. A key objective of this
book is to showcase in a simple guided way how to use Microsoft Coded UI so that you can
attain maximum return on investment from using the tool. Not only will you learn how to
use the tool but also how to effectively create maintainable frameworks using Coded UI.
Scope of Topics
As part of the scope of this book we will cover Microsoft Coded UI with C# as the
programming language with Visual Studio 2015.
We will be using Visual Studio 2015 as the main IDE for creating Coded UI tests.
No prior knowledge of C# language is required for this book but having an understanding
of object oriented programming language concepts will definitely help. As part of this book
we will be covering Basics of C# which would be required to use Microsoft Coded UI for
beginner users.
We will also learn how Microsoft Coded UI integrates with continuous Integration tools
like Team Foundation Server.
Ourintent in this book is to discuss the key features of Microsoft Coded UI and cover all
crucial aspects of the tool in order to help you create effective automation frameworks
using Microsoft Coded UI.
Target Audience
The target audience for this book are manual, functional testers who want to learn
Microsoft Coded UI quickly and who want to create effective automation frameworks
that generate positive ROIs to stakeholders.
9
Test Automation using Microsoft Coded UI with C#
A major fear amongst functional testers who want to learn Coded UI is the fear of the
programming language and coding. We address these fears by covering just enough basics
on C# programming language that will give you the confidence to use Microsoft Coded
UI.
This book follows a unique training based approach instead of a regular text book
approach. Using a step by step approach, weguide you through the exercises using pictorial
snapshots.
We also provide step by step installation and configuration of Visual Studio before using
Coded UI.
Instead of using custom html pages with few form fields and links, this book utilizes a
custom developed, Web based application containing many form fields and links.
Another differentiator is that wehave tried to include many practical examples and issues
which most automation testers encounter in their day-to-day activities. We share our real-
life experience with you to give you an insight into what challenges you could face while
implementing an automation solution on your project. Our practical examples cover how
to use most of the features within Microsoft Coded UI.
We also cover aspects of Continuous Integration tool; Team Foundation Server so that
Coded UI scripts can be integrated with the development environment and run on nightly
builds.
Finally, the book includes a special section devoted to answering the most common
interview questions relating to test automation and Microsoft Coded UI.
The source code used in the book can be found at the following
link
www.adactin.com/store/
10
Acknowledgements
I would like to thank my family (my parents, my wife Sapna, my wonderful kids Shaurya
and Adaa) for their continued support. Without them this book would not have been
possible.
I would also like to thank my colleagues and clients for the inspiration, knowledge and
learning opportunities provided.
Navneesh Garg
I would like to thank my family (my parents, my wife Sangeeta, my lovely boy Vedaang) who
supported and encouraged me in spite of all the time it took me away from them.Without
them this book would not have been possible.
I would like to express my gratitude to the many people who saw me through this book; to
all those who provided support, talked things over, read, wrote, offered comments, allowed
me to quote their remarks and assisted in the editing, proofreading and design.
Vaibhav Mittal
Special thanks to William B for his review and feedback, which immensely helped as we
worked on this book.
11
12
1.
Introduction to Automation
Introduction
In this chapter we will talk about automation fundamentals and understand what
automation is and the need for automation. An important objective of this chapter is
to understand the economics of automation, and determine when we should carry out
automation in our projects. We will also discuss some popular commercial and open source
automation tools available in the market.
Key objectives:
What is automation?
Why automate? What are the benefits of automation?
Economics of automation
Commercial and Open Source automation tools
13
Test Automation using Microsoft Coded UI with C#
14
Introduction to Automation
15
Test Automation using Microsoft Coded UI with C#
Example
Let us give you an example from our personal experience.
We performed some automation work for one of our investment banking clients. We had
a five-member team, which automated almost 3000 test cases in about six months time,
which included around 30 total man months of effort. At the end of project, we gave the
clients testing team, a hand-over of the entire automation suite created by our team. Our
recommendation to them was that they would need at least a one or two member team
to continuously maintain the scripts. This was because there were still functional changes
happening to the application and scripts would need maintenance. But since the client
project manager had no budget allocated for this activity, they over looked this advice
and continued to execute automation scripts. After the first six months of the 3000 test
cases, only 2000 test cases passed, while the rest started failing. These scripts failures were
because script fixes were needed due to application changes. The client team was okay with
that and continued to execute those 2000 working test cases, and got rid of the remaining
1000 test cases, which were now executed manually. After another six months, only scripts
corresponding to 1000 test cases passed. So they got rid of another 1000 test cases and
started executing them manually. After another six months (1.5 years in total), all the
Scripts failed and testing had to move back to manual functional testing.
In the above real-life scenario, the cost of automation and its benefits could have been
reaped, if the client had allocated 1-2 automation testers (could have been part-time) to
maintain the scripts and had properly planned and budgeted for it.
16
Introduction to Automation
Microsoft VSTP Code UI tests Code UI tests come with Microsoft Visual
studio Enterprise version. You can program
using VB.net or C# as languages of choice.
Fairly good for technical testers.
17
8.
Adding Assertions in Coded UI
Introduction
Till now, we have just executed a set of actions a functional tester will perform. We have not
validated the applications functionality by comparing any actual values on the application
against expected values.
To accomplish this, we will insert assertion points in Coded UI. In this chapter we will
understand the need for assertions and how to insert assertions in Coded UI script. Also
we will understand the different kinds of assertions or checks we can perform in Coded UI.
Example
As a consultant, we need to work with lots of assertion in our everyday work, either manually
or automatically,both depending on the complexity and time. It is extremely important to
design them in advance. Good assertion is necessary; otherwise we risk gathering wrong/
inaccurate information from QA work. This can delay the delivery of software or leave
issues uncovered in the product.To write good assertions, we have to examine the part of
the software to test carefully, find out whats unique about it, and what we need to find out
as a sufficient proof of its working.
In this chapter we will understand the need for assertions and how to add them in a Coded
UI script.
Key objectives:
Need for assertions
Adding assertion to Coded UI script
Type of assertions
119
Test Automation using Microsoft Coded UI with C#
Let us take a simple test case for automation from our Hotel Application.
Test Objective: To verify that when a location is selected on the Search Hotel page, the
same location is displayed on the Select Hotel page
Test Steps:
1. Login to the application using valid User credentials
2. Select Sydney from the Location field on the Search Hotel page
3. Keep all the default selections
4. Click the Search Button
5. Verify the correct Location is displayed on the Select Hotel page
Expected Result
1. Sydney should appear in the Location column on the Select Hotel search results
page
120
Adding Assertions in Coded UI
121
16.
Test Settings and Playlist Files
Introduction
When you run tests from Visual Studio or in thebuild service, the test framework can
collect data such as diagnostic trace information, system information, or a video recording
of a coded UI test. To utilize these capabilities, we use the .testsettings file in our projects.
These diagnostics can be used to simulate potential bottlenecks on the test machines,
reduce the available system memory, or emulate a slow network.
As suggested on MSDN, Test Settings file is used in the following scenarios
Collect diagnostic data to help isolate bugs in your application.
Emulate potential bottlenecks that your app might occasionally encounter in a
production environment.
Run the client, server, and other parts of your app on different machines, to verify
that it behaves as expected in a distributed environment.
Distribute a large number of tests across additional machines.
Run web performance and load tests.
You can create and save a list of coded UI tests that you want to run or view as a group. To
achieve that we create a playlist file.This is used if you want to separate your tests based on
workflows, test suites or product modules.
In this chapter we will learn how to utilize testsettings and playlist files to execute Coded
UI scripts.
Key objectives:
Adding a testsettings file
Features of a Test Settings
Using a Playlist
202
17.
Continuous Integration with Team
Foundation Server
Introduction
Why do we need Continuous Integration tools for test automation?
Continuous Integration (CI) tools assist in creating frequent builds (usually on a daily basis)
and running developer driven tests (unit tests) to provide timely feedback on application
quality.
We can integrate our Coded UI based functional test automation scripts with CI tools to
execute our scripts as soon as a new build is created which will provide instant feedback on
application issues.
Popular open source tools include Hudson, Jenkins (the offspring of Hudson),
CruiseControl and CruiseControl.NET.
Popular continuous integration tools include Microsofts Team Foundation Server,
ThoughtWorks Go, Jetbrains Team City, Hudson, Jenkins and Cruise Control.
As part of this chapter we will learn how Coded UI scripts integrate with Team Foundation
Server, one of the popular CI tools provided by Microsoft.
Key objectives
Team Foundation Server 2015
Code Repository
213
Test Automation using Microsoft Coded UI with C#
214