Deep Dive Modern Apps Lifecycle with Visual Studio 2012: How to create cross browser test automation using Coded UI Testing
1. How to create cross browser test
automation using Coded UI Testing
2.
3. Agenda
Test automation with visual Studio 2012
Coded UI tests
Technologies supported
How does CodedUI find the objects?
Multi browser support
Maintainability of your tests
BDD style testing and MTM
BDD style testing and CodedUI
Page object pattern
BDD style testing and CodedUI revisited
Running your test automation from MTM and the build
Summary
4. Test Automation Pyramid & VS
Test Cases & Manual
Shared Steps Tests
Coded UI Tests
GUI
Tests
Unit Tests Acceptance
Tests (API Layer)
Unit Tests Unit Tests / Component
Tests
Maintainable Coded UI Tests (CUITs) met VS2012 4
5. Introduction into CodedUI
Microsoft Framework to implement Test autmation
CodedUI tests are based on the MSTest Framework
It supports different UI technologies
Web Browser
WPF applications
WinForms applications
Silverlight applications
(Microsoft Visual Studio UI Test Plugin for Silverlight)
6. Searching for controls
CodedUI uses the search properties of the control first to find the control
relative to the specified parent control
If a Search results in multiple controles then the Filter Properties are
applied
If a Search results in 1 control, then search properties are ignored
Search of controls works best if they can be easily identified
Best practice:
For web controls always give controls an “id” attribute
For other technologies, add an AutomationPeer to the control
7. Supported technologies
IE8, 9 & 10 on Windows 7, 8
Chrome, firefox
Silverlight 4 & 5 in IE 8,9 & 10
Windows forms 2.0
WPF fully supported
SharePoint
Dynamics CRM
8. Test automation with Visual Studio 2012
Cross browser support:
”Selenium components for Cross Browser “:
http://bit.ly/vs2012crossbrowser
9.
10. Wait for specific events
WaitForControlReady The methods return true if the
WaitForControlEnabled wait is successful and false if the
wait failed.
WaitForControlNotExist
•The implicit timeout for the wait
WaitForControlPropertyEqual operation is specified by
WaitForControlPropertyNotEqual WaitForReadyTimeout property
WaitForControlCondition
(Predicate) use the Playback.Wait() instead
WaitForCondition (Predicate) of Thread.Sleep() API
11. Data Driven tests
Data sets can be used to drive the UITests
Different Data Sources available
CSV
XML
Excel
Test Case in MTM
SQL Server
Use the TestContext to get the data rows
string paramVal = TestContext.DataRow["Input1"]
16. BDD style acceptance test specification
In order to correct wrong items in my shopping cart
As a customer
I should be able to correct items in my shopping car cart.
Scenario 1: Wrong selected Items should be removable from shopping cart
Given a customer added an article to his shopping cart
When the customer navigates to the shopping cart
Then he should be able to remove the item from the basket
Scenario 2: Wrong number of items should be correctable
Given a customer added an article to his shopping cart
And he increased the quantity of the article
When the customer navigates to the shopping cart
Then he should be able to decrease the quantity of the article
17. BDD
• The language is used by all team members!
• Given, when, then... can be seen as keywords
for the domain language.
• It’s a captured conversation
• Simple
18.
19.
20. Making test readable & reusable
Page Objects
= UIMap
Create multiple (per page for example)
Technical interface for interacting with the pages
Shared Step
Page Object
Pagina • UI Control Test Script
• UI Action
Maintainable Coded UI Tests (CUITs) met VS2012 20
21. Code first - extensions
http://codeduicodefirst.codeplex.com/
28. Autmated run in MTM pushes data to
TestContext.Properties[]
__Tfs_IsInLabEnvironment__ True
__Tfs_TestRunId__ 22
__Tfs_TestCaseId__ 117
__Tfs_TeamProject__ MyTeamProjectName
vsalmffdropsNew Build Definition 1New Build Definition
__Tfs_BuildDirectory__
1_20130222.7
<?xml version=”1.0″ encoding=”utf-16″?><LabEnvironment
Id=”5f37b167-ad24-4f7e-bb1e-2e65a3e71a1f”
Name=”Windows 7 Client”
Uri=”vstfs:///LabManagement/LabEnvironment/2″><LabSys
__Tfs_LabEnvironment__
tems><LabSystem Name=”TestClient”
ComputerName=”TestClient” Roles=”Desktop
Client”><CustomProperties
/></LabSystem></LabSystems></LabEnvironment>
__Tfs_TestConfigurationId__ 2
__Tfs_TestPlanId__ 4
__Tfs_TestConfigurationName__ Chrome
__Tfs_TestPointId__ 12
__Tfs_TfsServerCollectionUrl__ http://vsalm:8080/tfs/fabrikamfibercollection
__Tfs_BuildPlatform__ Any CPU
__Tfs_BuildNumber__ New Build Definition 1_20130222.7
__Tfs_BuildFlavor__ Debug
__Tfs_BuildConfigurationId__ 22
29. Initialize your test
[TestInitialize]
public void TestInitialize()
{
if (TestContext.Properties["__Tfs_TestConfigurationName__"] != null)
{
string selectedBrowser =
TestContext.Properties["__Tfs_TestConfigurationName__"].ToString();
Debug.WriteLine(string.Format("Selected browser configuration
'__Tfs_TEstConfigurationName__' == {0}",selectedBrowser));
if (!string.IsNullOrEmpty(selectedBrowser))
{
// check if we selected IE, Firefox or chrome
if (selectedBrowser == "IE")
return;
BrowserWindow.CurrentBrowser = selectedBrowser;
}
}
}
30.
31.
32. Summary
Test automation with visual Studio 2012
Coded UI tests
Technologies supported
How does CodedUI find the objects?
Multi browser support
Maintainability of your tests
BDD style testing and MTM
BDD style testing and CodedUI
Page object pattern
BDD style testing and CodedUI revisited
Running your test automation from MTM and the build
Call to Action
Editor's Notes
- Hoe is dit nu verwerkt in de Visual Studio product stack?