Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

29
Getting Started with Coded UI Testing: Building Your First Automated Test Imaginet Resources Corp. http:// www.imaginet.com

description

This training seminar will demonstrate how to record tests run against various types of application user interfaces using Microsoft Visual Studio's Coded UI Tests and how to replay them at any time. Additionally, we will explore how to embed validations, either simple or elaborate, to ensure your application is producing the correct results. Learn how to improve the quality of your applications by having a repeatable set of Microsoft Coded UI Tests available to ensure defects don’t go unnoticed!

Transcript of Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Page 1: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Getting Started with Coded UI Testing: Building Your First Automated Test

Imaginet Resources Corp.http://www.imaginet.com

Page 2: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Agenda

• Coded UI Test Overview

• Recording Coded UI Tests

• Adding Test Validation• Writing your own

code• Best Practices

Page 3: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Coded UI Test Tools

• Used to automate testing from the user interface• Test development/maintenance in Visual Studio• Tools provided to improve creation and maintenance

of Coded UI tests• Can author and maintain tests without writing code or

can extend tests using .NET• Can run within Visual Studio or through automation

(e.g., a build)

Test development and maintenance from within Visual Studio

Page 4: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Supported Platforms

• Supported (2012 RTM)– Windows Forms 2.0+– WPF 3.5+– SharePoint– Internet Explorer 8.0, 9.0– Internet Explorer 10.0

(Desktop)– Dynamix CRM web client

• Supported (2012 Update 1)– Google Chrome 21+– Firefox 15+

• Unsupported but may work– Windows Win32

• Partially Supported– MFC– Dynamix (Ax) 2012 Client– Citrix / Terminal Services– PowerBuilder

• Unsupported– Internet Explorer < 8.0– Silverlight– Flash/Java– SAP– Microsoft Office– Apple Safari– Opera

Page 5: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Agenda

• Coded UI Test Overview

• Recording Coded UI Tests

• Adding Test Validation• Writing your own code• Best Practices

Page 6: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Creating Coded UI Tests

Action Recordingfrom Manual Tests

Visual Studio Recorder

Visual Studio Recorder

Coded UI Test

Page 7: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Option 1: Based on Existing Tests

• Using Microsoft Test Manager (MTM)…– Analyst defines requirements– Tester defines manual test cases for the requirement– Tester runs test cases and records the steps

• As needed, “Automation Tester” converts recorded steps into a Coded UI Test

Define Rqts

Define Tests

Capture Tests

Automate Tests

Page 8: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Option 2: Using the Coded UI Test Builder

• Approach:– Click the record button– Perform the steps in your test target– Click the generate code button– Repeat to generate more methods for the test– Show recorded steps to delete missteps

Page 9: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

DEMONSTRATION

• Converting Test Cases

• Using the UI Recorder

Page 10: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Option 3: Author Tests using .NET

• Hand-code in .NET, without any additional assistance • Utilize one of the Coded UI-based community frameworks:

– CUITe (Coded UI Test Enhanced)• Authored by Microsoft employees but not a ‘product’• Uses its own tooling to maintain a separate UI object repository• Improves code maintainability• Browser-based only• Currently only supported on Visual Studio 2010• Maintained on CodePlex:

http://cuite.codeplex.com/

– Code First Coded UI• Led by Microsoft employees but not a ‘product’• Pure code – does not use an object repository• Installable via NuGet• Uses Scaffolding approach to generate tests• Browser-based only• Currently only supported on Visual Studio 2010• Maintained on CodePlex:

http://codeduicodefirst.codeplex.com/

Page 11: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Agenda

• Coded UI Test Overview

• Recording Coded UI Tests

• Adding Test Validation

• Writing your own code

• Best Practices

Page 12: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Validation

• Use the Coded UI Test Builder to add assertions

• Drag the crosshairs to a target control

• Bundle assertions into methods called from the test

Select a property

Click to add assertion

Generate a method to record the assertion(s)

Page 13: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

DEMONSTRATION

• Adding Assertions

Page 14: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Agenda

• Coded UI Test Overview• Recording Coded UI

Tests• Adding Test Validation• Writing your own code• Best Practices and

References

Page 15: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

The Primary Components

• Test Class (e.g., MyTest.cs)– A .NET Coded UI Test class containing one or more Test

Methods.

• Test Method– An individual automated test case inside a Test Class.

• Recorded Method– Code which actually automates the UI and performs

assertions. (Do not change this code!)

• UIMap– An XML designer file and related generated classes

containing the recorded methods.

Page 16: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Overriding Generated Properties

[TestMethod]public void CodedUITestMethod1(){

this.UIMap.OpenCalc();this.UIMap.AddThreeAndTwo();this.UIMap.VerifySumExpectedValues.UITxtDisplayEditText =

"5";this.UIMap.VerifySum();this.UIMap.CloseCalc();

}

“Recorded Methods” created using the UI Test Builder.

Hand-coded to change the expected value for the VerifySum recorded method. There are many other overrides made available to you in the generated code.

Page 17: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

The API

Microsoft.VisualStudio.TestingTools.UITesting:• UITestControl

• Keyboard– SendKeys

• Mouse

• Playback.PlaybackSettings…– DelayBetweenActions– MatchExactHierarchy– SearchInMinimizedWindows– SearchTimeout– ThinkTimeMultiplier– WaitForReadyLevel– WaitForReadyTimeout

Page 18: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

DEMONSTRATION

• Digging into the Code

Page 19: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Agenda

• Coded UI Test Overview

• Recording Coded UI Tests

• Adding Test Validation• Writing your own code• Best Practices

Page 20: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Best Practices

• Create each test case as a sequence of Recorded Methods.

• Use multiple UI Maps to separate areas o the application.

• Use meaningful test method names.

• Try to limit the length of each recorded method to less than 10 actions.

• Use meaningful UI control names in the application under test.

• Do not edit the UIMap.Designer.cs file.

• Use the Coded UI Test Builder and UI Control Locator whenever possible.

Page 21: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Summary

• Coded UI Test Overview

• Recording Coded UI Tests

• Adding Test Validation

• Writing your own code

• Best Practices

Page 22: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Questions?

Page 23: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Imaginet’s New Visual Studio 2012 Website!

http://visualstudio.imaginet.com

Visit Imaginet’s new Visual Studio 2012 website, your one-stop hub for all your Visual Studio 2012 needs!

Page 24: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

For attendees of today’s session that fill out the survey

FREE Imaginet On DemandWeb Training Subscription Offer

Complete our Post-Webcast survey, and receive 1 free Imaginet On Demand web training subscription, good for 1 person for 1 month!! The survey will be emailed to you immediately after this webcast is over.

What is Imaginet On Demand? Imaginet is proud to announce our newest web-based training program called Imaginet On Demand, your source for the best Application Lifecycle Management (ALM) training on the internet. Imaginet On Demand is a subscription-based training program centric to the Visual Studio ALM tools, including Visual Studio, Team Foundation Server (TFS), Microsoft Test Manager, and Microsoft Visual Studio Lab Management. Learn the new tools of Visual Studio at your pace, from wherever you want. It's that simple!

Page 25: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Need Help with YOUR Quality Assurance & Testing?

• Includes designing, installing, and configuring Microsoft’s testing tools, including Microsoft Test Manager 2012 and Automated Testing with Visual Studio 2012.

• Learn best practices for manual and automated testing with the Microsoft ALM tools.

• Support and training for your team

• Includes a high-level ALM assessment

Imaginet’s Visual Studio 2012Testing Tools 10-day Quickstart

Interested? Just email us at [email protected].

Page 26: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Top Gun Academy Training Classes

• Other Imaginet Training Classes– ALM

• Microsoft Visual Studio & TFS 2012 – Skills Upgrade (2 days)• Overview Training with Microsoft Visual Studio 2012 ALM Tools (4 days)• Overview Training with Microsoft Visual Studio 2010 ALM Tools (4 days)• Testers Training with Microsoft Visual Studio 2012 ALM Tools (4 days)• Testers Training with Microsoft Visual Studio 2010 ALM Tools (4 days)• Developers Training with Microsoft Visual Studio 2012 ALM Tools (4 days)• Developers Training with Microsoft Visual Studio 2010 ALM Tools (4 days)• Imaginet On Demand Online Web Training

– Scrum/Kanban• Professional Scrum Foundations (PSF) (2 days)• Professional Scrum Master (PSM) (2 days)• Professional Scrum Developer (PSD) (5 days)• Professional Scrum Master (PSM) Using Microsoft ALM (3 days)• Accredited Core Kanban Using Microsoft ALM (3 days)

To register or for more information, please visit our website here: http://www.imaginet.com/ or contact us: [email protected]

Page 27: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

Email us at:[email protected]

ALM Planning & Implementation ServicesALM Planning • ALM Assessment & Envisioning Workshops

(3 or 5 days)• VS & TFS Migration Planning Workshop (5

days)• TFS Deployment Planning* (5 days)• Visual SourceSafe to TFS Migration

Planning* (3 Days)• Visual Studio Quality Tools Deployment

Planning* (5 days)

Upgrade• TFS 2010 Adoption Quick Start (5 or 10

days)• TFS 2012 Adoption Quick Start (5 or 10

days)• TFS 2010 Upgrade Quick Start (10 days)• TFS 2012 Upgrade Quick Start (10 days)

Remote Support• Remote Support for TFS & Visual Studio

Lab• Visual Studio Lab Management Quick Start

(10 days)

Testing• Manual Testing with Test Manager Quick

Start (5 days)• Visual Studio Testing Tools Quick Start (10

days)• Visual Studio Automated Testing Quick Start

(5 days)• Visual Studio Load Testing Quick Start (5 or

10 Days)

Builds• Automated Build & Release Management

Quick Start (5 days)• Automated Build Center of Excellence (CoE)

Database• Visual Studio Database Tools Quick Start (10

days)

Integrations• Team Foundation Server (TFS) & Project

Server Integration Quick Start (10 days)• TFS & Quality Center Integration/Migration

Quick Start (10 days)

Page 28: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

For questions or more information,please contact us at:

[email protected] or (972)607-4830

Page 29: Getting Started with Visual Studio’s Coded UI Testing: Building Your First Automated Test

http://www.imaginet.com