Hand Coding Coded UI
This book is aimed at testers who want to try their hands at automated testing using Coded UI, which is available as part of Microsoft® Visual Studio® (Enterprise Edition). Coded UI has empowered developers and automation testers to work using the same automation tool and language, hence enabling them to collaborate more efficiently and effectively. Moreover, Coded UI can be used for both Web and Windows-based Applications which enables automation testers to devise a single Automation Framework that reuses common code and libraries. This makes the test automation more efficient, reduces the test automation effort, lowers the cost of maintenance and also provides a higher Return On Investment. Therefore, in my view, if you are planning to use Coded UI for automation, it will be a right step forward in your world of automated testing.
You will find a lot of books which go through mainly the theoretical aspects of automation and provide only a few code snippets on how automation is performed in reality. There is a famous saying ‘‘In theory, theory and practice are the same. In practice, they are not’’, so I thought I should write a book which explains how automation is practically done rather than just explaining it in theory. Moreover, I’m a big fan of hand coding the test automation code as opposed to using the auto generated Record and Playback code. This hand coding approach can be applied to any project which aims to use Coded UI as the test automation tool.
This book provides a step by step guide that will teach you how to setup the Automation Framework from scratch using Coded UI. As mentioned before, the book concentrates on the ‘practical side’ of automated testing rather than the ‘theoretical side’. It includes complete listings of the hand coded automation code for the demo Website, Windows-based applications (Windows Forms and WPF Applications) and Web Service that have been developed for you to test against. The code listings explain the logic of individual tests, repositories and generic functions.
This book is divided into ten chapters as follows:
- Chapter 1, Getting Started, introduces reasons to use automation in our testing. It highlights the reasons why we should avoid the Record and Playback approach. It also provides the Golden Rules one should follow when automating tests.
- Chapter 2, Automation Approach, covers the importance of having a framework, the driving force behind a successful automation. It also discusses the components of an Automation Framework using Coded UI. A demo website has been setup to help you learn the practical Web Testing scenarios listed in the book. We will setup the project structure required to create our Coded UI Automation Framework. We will also learn about the UI Control hierarchy and how to identify them in Coded UI.
- Chapter 3, Web Based Application – UITestControls, starts with creating our first automated test using UITestControls. We will learn how the Coded UI project structure, which we have setup in the previous chapter, hangs together to give us an Automation Framework on which we can build robust and easily maintainable code. We will expand our Automation Framework by learning how to enable the inbuilt logging mechanism provided by Coded UI.
- Chapter 4, Web Based Application – HtmlControls, covers automating the Web Testing scenarios using HtmlControls. We will add a number of important features to the Automation Framework such as logging to the Standard Output window, CSV files (so that you can refer back when required), saving screenshots etc. The chapter also covers how to automate data entry, verification and negative tests using HtmlControls. Finally, we will expand our Automation Framework to create a Test Result Summary report at the end of the test execution.
- Chapter 5, Automate With Databases, covers automating tabular and summary reports in the demo website again using HtmlControls. We will learn how to perform various automated verification tasks using a database.
- Chapter 6, Data Driven Testing, describes how to perform data driven testing using external data files (instead of using hard-coded data in the test). We will cover both XLS and XLSX Excel formats for automation purpose. Before we finish this chapter, we will add more features to the Automation Framework e.g. adding a test step failure threshold, logging failed test steps only and comparing decimal numbers with a defined tolerance.
- Chapter 7, Cross Browser Testing, covers testing our demo website with different browsers using Coded UI. We will cover Mozilla Firefox, Google Chrome, Internet Explorer and Microsoft Edge web browsers. We will also see a practical example on how to make our test scripts browser compatible so that we can run them on multiple browsers.
- Chapter 8, Web Services Testing, deals with automating the testing of web services in Coded UI. We will write a sample working web service and automate its testing via different methods namely WebRequest, HttpWebRequest and Service Reference.
- Chapter 9, Windows Forms Application – WinControls, covers automating Windows Forms Applications using WinControls. The book provides a demo Windows Forms Application to help you learn the practical scenarios listed in the book. The chapter covers automation scenarios on data entry, verification and drag-n-drop tasks using WinControls.
- Chapter 10, Windows Presentation Foundation (WPF) Application – WpfControls, covers automating WPF Applications using WpfControls. The book provides a demo Wpf Application to help you learn the practical scenarios listed in the book. The chapter covers automation scenarios on data entry and verification tasks using WpfControls.
Since this book has been designed to be a Practical Oriented Approach, we will adhere to the following steps in each section of a chapter (wherever applicable):
- define a Test Scenario using one of the demo applications – Website, Windows Forms Application, WPF Application or the Web Service.
- define the required Configuration Parameters in the Configuration File.
- write code for the required controls in the Repository File.
- write code for the required generic functions in the Utility File.
- write code for the business process in the Page File.
- write code for the test logic as per the Test Scenario (defined in the beginning) in the Test File.
- finally, execute the test and view the Outcome.
Welcome to the world of hand coding your Coded UI tests!