31
1 Introduction to UI testing with SWAT 2/12/2011

11 Introduction to UI testing with SWAT 2/12/2011

Embed Size (px)

Citation preview

Page 1: 11 Introduction to UI testing with SWAT 2/12/2011

11

Introduction to UI testing with SWAT

2/12/2011

Page 2: 11 Introduction to UI testing with SWAT 2/12/2011

22

Ultimate is a leading provider of unified human capital management SaaS solutions for global businesses. Its award-winning UltiPro® includes recruitment, onboarding, benefits management, payroll, performance and learning management, reporting, self-service, and more.

Ultimate Software

Page 3: 11 Introduction to UI testing with SWAT 2/12/2011

33

About Ultimate Software

• Founded in 1990• Dedicated focus on HR, payroll,

benefits, talent management• Award-winning UltiPro® product

and customer services• 1100 employees• 250 people in development• 15 large kanban teams• .NET, MSSQL, Delphi shop• Headquarters in Weston, FL

Page 4: 11 Introduction to UI testing with SWAT 2/12/2011

44

Full-time and Internship positions

Email Resumes or Connect on LinkedIN: [email protected]

Best Mid-Size Company to Work for in America 2008 & 2009

Page 5: 11 Introduction to UI testing with SWAT 2/12/2011

55

• Michael Longin – Ultimate Software• Lead Process Engineer \ Software Engineer• Certified Scrum Master• Project Lead - SWAT

Who Am I???

Page 6: 11 Introduction to UI testing with SWAT 2/12/2011

66

Goals for this session

• Attendees should be able to create and update UI tests

Page 7: 11 Introduction to UI testing with SWAT 2/12/2011

77

Syllabus

• Why Test Through the UI• Introduction to SWAT• Running tests against different browsers (IE\Firefox\Chrome)• Navigating• Bread and Butter Commands• The concept of expressions• Variables• Command Modifiers• Macros• SWAT Editor• Where to get help• Questions?

Page 8: 11 Introduction to UI testing with SWAT 2/12/2011

88

Why Test Through the UI

Testing Pyramid

Page 9: 11 Introduction to UI testing with SWAT 2/12/2011

99

An Introduction to SWAT

• SWAT– Simple Web Automation Toolkit– Meant to provide a simple way to test the UI of a website– C# Library

• Library of commands– UI– Database

• Not tied to the included editor, fitnesse, or any other runner• Open Source

– Anyone can download the program and the source

Page 10: 11 Introduction to UI testing with SWAT 2/12/2011

1010

Demo

Page 11: 11 Introduction to UI testing with SWAT 2/12/2011

1111

Browsers

• Currently Supported Browsers– IE– Firefox– Chrome– Safari on OSX

Page 12: 11 Introduction to UI testing with SWAT 2/12/2011

1212

Choosing a browser in a test

• C#var _browser = new WebBrowser(BrowserType.InternetExplorer) orvar _browser = new WebBrowser(BrowserType.FireFox)

• Editor \ Fitnesse– First line of the test

!|InternetExplorerSWATFixture|or!|FireFoxSWATFixture|

– SHOULD ONLY BE IN A TEST ONCE!!!

Page 13: 11 Introduction to UI testing with SWAT 2/12/2011

1313

How commands are entered (fitnesse\editor)

• All test blocks start with !|SWATFixture|• Commands come underneath• Example:

!|SWATFixture||OpenBrowser||NavigateBrowser|www.google.com|

Page 14: 11 Introduction to UI testing with SWAT 2/12/2011

1414

Navigation

• Open Browsero |OpenBrowser|o _browser.OpenBrowser()

• Navigate Browser– Syntax

• |NavigateBrowser|url|• _browser.NavigateBrowser(string url)

– Example• |NavigateBrowser|www.google.com|

Page 15: 11 Introduction to UI testing with SWAT 2/12/2011

1515

Navigation continued

• Attach to Window– Used to attach to an open browser or popup– Does not need to be exact– |AttachToWindow|WindowTitle|– _browser.AttachToWindow(string windowTitle)

• Close Browser– |CloseBrowser|– _browser.CloseBrowser()

Page 16: 11 Introduction to UI testing with SWAT 2/12/2011

1616

Where we are now

• C#var _browser = new WebBrowser(BrowserType.InternetExplorer) _browser.OpenBrowser();_browser.NavigateBrowser(“www.google.com”);_browser.CloseBrowser();

• Editor \ Fitnesse!|InternetExplorerSWATFixture|

!|SWATFixture||OpenBrowser||NavigateBrowser|www.google.com||CloseBrowser|

Page 17: 11 Introduction to UI testing with SWAT 2/12/2011

1717

Standard command parameters

• Identifier Type– http://ulti-swat.wikispaces.com/QS_Fitnesse_IdentifierTypes– ID– Name– InnerHTML– Expression (we will get to this one in a moment)

• Identifier– Example <label id=“myID”>my label</label>– |id|myID|– |InnerHTML|my label|– NOTE* when using an identifier other then Expression must be exact

• Tagname– Optional– Speeds up tests– Recommended

Page 18: 11 Introduction to UI testing with SWAT 2/12/2011

1818

Bread and Butter commands

• Checking for an item on the page– AssertElementExists– Used to determine if an element is on the screen– |AssertElementExists|IdentifierType|identifier| tagName(optional)|

• Setting the value of an attribute– SetElementAttribute– Could be used to set a textbox– |SetElementAttribute|IdentifierType|identifier|attributeName|attributeValue|

tagName(optional)| – Attribute

• The Attribute that will be set• Could be value, class, style, etc

– Attribute Value• Value you want to set it to

Page 19: 11 Introduction to UI testing with SWAT 2/12/2011

1919

Bread and Butter continued

• Firing an attributes events– StimulateElement– Could be used to click a button or change a drop down– |StimulateElement|IdentifierType|identifier|eventName| tagName(optional)| – EventName

• Onclick, OnChange, OnBlur, etc

Page 20: 11 Introduction to UI testing with SWAT 2/12/2011

2020

Where we are now (C#)

var _browser = new WebBrowser(BrowserType.InternetExplorer) _browser.OpenBrowser(); _browser.NavigateBrowser("www.google.com");_browser.SetElementAttribute(IdentifierType.Name, "q", AttributeType.Custom, "value", "South

Florida Code Camp", "INPUT"); _browser.StimulateElement(IdentifierType.Name, "btnG", "onclick", "INPUT");_browser.CloseBrowser();

Page 21: 11 Introduction to UI testing with SWAT 2/12/2011

2121

Where we are now (Fitnesse \ Editor)

!|InternetExplorerSWATFixture|

!|SWATFixture||OpenBrowser||NavigateBrowser|www.google.com|

!|SWATFixture||SetElementAttribute|name|q|value|Ultimate Software|input||StimulateElement|name|btnG|onclick|input|

!|SWATFixture||CloseBrowser|

Page 22: 11 Introduction to UI testing with SWAT 2/12/2011

2222

Expressions

• Allow more powerful searches• http://ulti-swat.wikispaces.com/Expressions+Explained• Can string together multiple attributes• : vs =

– : means contains– = means exact

• ‘;’ used to break up attributes• Example

– <label id=“myId”>my label</label>– Expression|id=myID;innerHTML:my lab|

• Uses regular expressions• NOTE*

– Period ‘.’ is a wild card, can mean anything

Page 23: 11 Introduction to UI testing with SWAT 2/12/2011

2323

Expressions continued

• Matchcount– Check for multiple instances– Example: innerHTML#2:ulti

• Reads as, “ulti” must be contained twice in the HTML

• ParentElement– Can use the parent element– Example parentElement.id:pid;class:hide

• <tr id=“pid”><td class=“hide”></td></tr>

Page 24: 11 Introduction to UI testing with SWAT 2/12/2011

2424

Variables (Fitnesse \ Editor)

• Can be used as part of an expression or as an identifier• Design time

– Used to create a variable when your writing the tests– When to use

• When something is likely to change• When something is repeated often

– To Set• !define loginUserName (atnipj)

– To Use• ${loginUserName}• Expression|id:${myID}

• Run Time– Variables that are populated when running the test– When to use

• When a variable is needed that can only be set at the time of running– To Set

• |GetElementAttribute|IdentifierType|identifier|attributeName|YourVariableName|tagName| – To Use

• >>YourVariableName<<• Expression|id:>>myID<<

Page 25: 11 Introduction to UI testing with SWAT 2/12/2011

2525

Macros (Fitnesse \ Editor)

• In C# would be known as methods• Very powerful• In fitnesse each test can be used in any other test• Macros can take in variables• Reasons to use

– Make tests less brittle• Any time an action is done in multiple tests, if the action changes can break all the tests

– Example: log in– Make tests more readable

• Can turn 5-30 lines of code into a single readable line– Example : login macro

– Make tests more easily updatable• Turn the InternetExplorerSWATFixture line into a macro

– Changing this to Firefox will update all tests to run in firefox• How to call a macro

– !include .SwatMacros.Login

• Macros are VERY Important and Useful

Page 26: 11 Introduction to UI testing with SWAT 2/12/2011

2626

SQL

• SWAT has a host of SQL functions built in• Connecting to a SQL Server

!|SWATFixture||ConnectToMssql|dbServer|username|password||SetDatabase|dbName|

Page 27: 11 Introduction to UI testing with SWAT 2/12/2011

2727

SQL Commands

• SetQuery– Used to run a query against the sql server– Results are stored in memory

• Assert Record Count– Verifys how many rows were returned against an expected result– |AssertRecordCount|ExpectedNumber|

• AssertRecordValuesByColumnName– Used to verify values in the database– |AssertRecordValuesByColumnName|[RowIndex]|ColumnName|ExpectedValue|

• GetDbRecordByColumnName– Used to place the value of a sql check into a variable– |GetDbRecordByColumnName|VariableName|[RowIndex]|ColumnName|

• Others available

Page 28: 11 Introduction to UI testing with SWAT 2/12/2011

2828

SWAT Editor

• Included in SWAT download from sourceforge• Up to date walk-throughs here:

– http://ulti-swat.wikispaces.com/QS_SwatEditor• Tests can be run\written in the editor• SQL query editor

– Included Database query editor allows you to create Select, Update, Insert, and Delete commands

• UI recorder is contained in the editor

Page 29: 11 Introduction to UI testing with SWAT 2/12/2011

2929

Final Words

• UI tests should be a part of your test plan, but not the only part

• Recorders are meant to help and be training wheels. They are not meant to do all the work

• When using Fitnesse as a runner, open it in a browser (IE, Firefox, etc) that is NOT the one you will be running tests against

• In order to use SWAT to test in Internet Explorer using C# the Apartment State has to be set to STA(Single Threaded Apartment)

Page 30: 11 Introduction to UI testing with SWAT 2/12/2011

3030

Where to get help

• Questions– https://sourceforge.net/projects/ulti-swat/– Open forum on sourceforge

• Websites– http://ulti-swat.wikispaces.com/– http://devxero.wordpress.com/

• Email– [email protected]

Page 31: 11 Introduction to UI testing with SWAT 2/12/2011

3131

Questions?

• Thank you for your attention