+ All Categories
Transcript
Page 1: Automated UI testing done right (DDDSydney)

Automated UI Testing

Done Right

Page 2: Automated UI testing done right (DDDSydney)

Mehdi KhaliliSenior Developer at Readify

Active Open Source Projects:• BDDfy• Seleno• Humanizer

Blog: www.mehdi-khalili.comTwitter: @MehdiKhalili

Page 3: Automated UI testing done right (DDDSydney)

These practices are performed by professional developers and testers.

Please DO try this at home

Authorized and written by Mehdi Khalili

Page 4: Automated UI testing done right (DDDSydney)

framework agnostic ideas and patterns

Page 5: Automated UI testing done right (DDDSydney)

can apply these with any UI and UI Testing framework

Page 6: Automated UI testing done right (DDDSydney)

… but for this talk we are going to use

Page 7: Automated UI testing done right (DDDSydney)

Seleniuman awesome automated UI testing

framework

Page 8: Automated UI testing done right (DDDSydney)

Seleniumhttp://seleniumhq.org/projects/webdriver/

PM> Install-Package

Selenium.WebDriver

Page 9: Automated UI testing done right (DDDSydney)

BDDfyA simple BDD framework to use and extend!

BDDfy turns your traditional unit testsinto BDD behaviours

Page 10: Automated UI testing done right (DDDSydney)

BDDfyhttp://teststack.github.com/TestStack.BDDfy/

PM> Install-Package

TestStack.BDDfy

Page 11: Automated UI testing done right (DDDSydney)

Selenohelps you write

Automated UI Tests the RIGHT way!

Page 12: Automated UI testing done right (DDDSydney)

Selenohttp://teststack.github.com/TestStack.Seleno/

PM> Install-Package TestStack.Seleno

Page 13: Automated UI testing done right (DDDSydney)

samples are from Seleno codebase and can be found at

https://github.com/TestStack/TestStack.Seleno

Page 14: Automated UI testing done right (DDDSydney)

In a nutshell

• UI Testing: a likely failure• From horrid to awesome in three steps• A few tips (time permitting)• Q&A

Page 15: Automated UI testing done right (DDDSydney)

UI Testing!a likely failure

Page 16: Automated UI testing done right (DDDSydney)

speaking of experience

Page 17: Automated UI testing done right (DDDSydney)

a lot of teamsdo

UI Testing

Page 18: Automated UI testing done right (DDDSydney)

a lot of teamshave a “great start” at

UI Testing

Page 19: Automated UI testing done right (DDDSydney)

a lot of teamsthen struggle with

UI Testing

Page 20: Automated UI testing done right (DDDSydney)

a lot of teamsthen fail atUI Testing

Page 21: Automated UI testing done right (DDDSydney)

because UI Tests are

Page 22: Automated UI testing done right (DDDSydney)

because UI Tests are

hard to maintain

Page 23: Automated UI testing done right (DDDSydney)

because UI Tests are

brittle

Page 24: Automated UI testing done right (DDDSydney)

but

you can

mitigatethese issues

Page 25: Automated UI testing done right (DDDSydney)

If you

do it

RIGHT

Page 26: Automated UI testing done right (DDDSydney)

test codeis

code

Page 27: Automated UI testing done right (DDDSydney)

apply

S.R.P. on your

code?

Page 28: Automated UI testing done right (DDDSydney)

apply

S.R.P.on your

tests

Page 29: Automated UI testing done right (DDDSydney)

apply

D.R.Y.on your

tests

Page 30: Automated UI testing done right (DDDSydney)

care about your

tests as much as you care about your

code

Page 31: Automated UI testing done right (DDDSydney)

or you willwaste a lot of time

Page 32: Automated UI testing done right (DDDSydney)

or you willfail

Page 33: Automated UI testing done right (DDDSydney)

from horrid to awesomein four three steps

Page 34: Automated UI testing done right (DDDSydney)

a quick look at the sample

https://github.com/TestStack/TestStack.Seleno

Page 35: Automated UI testing done right (DDDSydney)

guaranteed to

fail

Page 36: Automated UI testing done right (DDDSydney)
Page 37: Automated UI testing done right (DDDSydney)

proceduralduplicated logicduplicated selectorsmagic strings

Page 38: Automated UI testing done right (DDDSydney)

Step 1:

D.R.Y.your tests with

Page Object

Page 39: Automated UI testing done right (DDDSydney)

Page Objectbrings

OO to tests)

Page 40: Automated UI testing done right (DDDSydney)

a Page Object per page under test

Page 41: Automated UI testing done right (DDDSydney)

a link on the page becomes a

method on the Page Object

Page 42: Automated UI testing done right (DDDSydney)

clicking a link on the pageturns into calling a method

on the Page Object

Page 43: Automated UI testing done right (DDDSydney)

instead of

you will get

Page 44: Automated UI testing done right (DDDSydney)

a textboxon the page becomes a

string propertyon the Page Object

Page 45: Automated UI testing done right (DDDSydney)

filling a textbox on the page turns into setting a string property on the

Page Object

Page 46: Automated UI testing done right (DDDSydney)

instead of

you will get

Page 47: Automated UI testing done right (DDDSydney)

a checkboxon the page becomes a

bool propertyon the Page Object

Page 48: Automated UI testing done right (DDDSydney)

ticking a checkbox on the page turns into setting a

bool property on the Page Object

Page 49: Automated UI testing done right (DDDSydney)

any actionon the page becomes a

method on the Page Object

Page 50: Automated UI testing done right (DDDSydney)

… and you will get another Page Object as the return

value of the method

Page 51: Automated UI testing done right (DDDSydney)

chain your calls

Page 52: Automated UI testing done right (DDDSydney)
Page 53: Automated UI testing done right (DDDSydney)

proceduralduplicating logicduplicating selectorsmagic strings

Page 54: Automated UI testing done right (DDDSydney)

step 2:

Page Components

Compose your Page Objects of smaller pieces

Page 55: Automated UI testing done right (DDDSydney)

some pages are

big

Page 56: Automated UI testing done right (DDDSydney)

some pages are

complex

Page 57: Automated UI testing done right (DDDSydney)

remember

S.R.P.?

Page 58: Automated UI testing done right (DDDSydney)

would you write

big and

complex classes in your

code?

Page 59: Automated UI testing done right (DDDSydney)

care about your tests

as much as you care about your

code

Page 60: Automated UI testing done right (DDDSydney)

do NOT write

big and

complex Page Objects

Page 61: Automated UI testing done right (DDDSydney)

use

Page Componentsto break down your

Page Objects

Page 62: Automated UI testing done right (DDDSydney)

use

Page Componentsfor

gridspanels

rows inmodal pop-ups

menus

Page 63: Automated UI testing done right (DDDSydney)

Page ComponentsD.R.Y.

your tests even more

Page 64: Automated UI testing done right (DDDSydney)

instead of

you will get

Page 65: Automated UI testing done right (DDDSydney)

and you can compose other

Page Objectsusing these

Page Components

Page 66: Automated UI testing done right (DDDSydney)
Page 67: Automated UI testing done right (DDDSydney)

Page Object &Page Component

lead into

S.R.P.

Page 68: Automated UI testing done right (DDDSydney)

Page Object &Page Component

D.R.Y.your test

Page 69: Automated UI testing done right (DDDSydney)

... but

Page 70: Automated UI testing done right (DDDSydney)

what about magic strings?

Page 71: Automated UI testing done right (DDDSydney)

proceduralduplicating logicduplicating selectorsmagic strings

Page 72: Automated UI testing done right (DDDSydney)
Page 73: Automated UI testing done right (DDDSydney)

it is not only about

magic strings

Page 74: Automated UI testing done right (DDDSydney)

the code is still ugly

Page 75: Automated UI testing done right (DDDSydney)
Page 76: Automated UI testing done right (DDDSydney)
Page 77: Automated UI testing done right (DDDSydney)

step 3:

Strongly typedPage Object

Page 78: Automated UI testing done right (DDDSydney)

you use view models

in your code

Page 79: Automated UI testing done right (DDDSydney)
Page 80: Automated UI testing done right (DDDSydney)

why not use view models

in your tests?

Page 81: Automated UI testing done right (DDDSydney)
Page 82: Automated UI testing done right (DDDSydney)

(unofficial) step 4:

Tests as Living Documentation

Page 83: Automated UI testing done right (DDDSydney)

write your UI Tests based on

acceptance criteria

Page 84: Automated UI testing done right (DDDSydney)

use a BDD framework to implement your

acceptance criteria

Page 85: Automated UI testing done right (DDDSydney)

use a BDD framework to turn your tests into

living documentation

Page 86: Automated UI testing done right (DDDSydney)
Page 87: Automated UI testing done right (DDDSydney)

use the test results

as a progress report

Page 88: Automated UI testing done right (DDDSydney)

use the test results

as a support for manual testing

Page 89: Automated UI testing done right (DDDSydney)

A few tips

Page 90: Automated UI testing done right (DDDSydney)

Do NOT use Thread.Sleep

Page 91: Automated UI testing done right (DDDSydney)

Thread.Sleepis slow

Page 92: Automated UI testing done right (DDDSydney)

Thread.Sleepis brittle

Page 93: Automated UI testing done right (DDDSydney)

often need to wait a bit longer for things to load?

Page 94: Automated UI testing done right (DDDSydney)

use implicit waits

Page 95: Automated UI testing done right (DDDSydney)

need to wait longer for specific elements to load?

Page 96: Automated UI testing done right (DDDSydney)

use explicit waits

Page 97: Automated UI testing done right (DDDSydney)

need to wait for an AJAX call to finish?

Page 98: Automated UI testing done right (DDDSydney)

use javascript

Page 99: Automated UI testing done right (DDDSydney)

chooseright selectors

Page 100: Automated UI testing done right (DDDSydney)

page structure changes

Page 101: Automated UI testing done right (DDDSydney)

do NOT

be fuzzywith your selectors

Page 102: Automated UI testing done right (DDDSydney)

do NOT

rely on the structure of your

page

Page 103: Automated UI testing done right (DDDSydney)

do NOT

rely on the surrounding elements

Page 104: Automated UI testing done right (DDDSydney)

By.XPath("//ul[@id='album-list']/li[3]/a/span")

you’re kidding, right?!

Page 105: Automated UI testing done right (DDDSydney)

we use interfaces and DI all over our code to make it unit testable

Page 106: Automated UI testing done right (DDDSydney)

do what it takes to

support your tests

Page 107: Automated UI testing done right (DDDSydney)

be explicit:add id on your elements to

support your tests

Page 108: Automated UI testing done right (DDDSydney)

TARGET your elements

directlywhen possible

Page 109: Automated UI testing done right (DDDSydney)

only one test

per action

Page 110: Automated UI testing done right (DDDSydney)

do you have workflows?

Page 111: Automated UI testing done right (DDDSydney)

do one test per page/action

Page 112: Automated UI testing done right (DDDSydney)

then do one test for entire flow

Page 113: Automated UI testing done right (DDDSydney)

do NOT setup your required

state through UI

Page 114: Automated UI testing done right (DDDSydney)

that will be slow and brittle

Page 115: Automated UI testing done right (DDDSydney)

setup your data through code

Page 116: Automated UI testing done right (DDDSydney)

and navigate to the page under

test directly

Page 117: Automated UI testing done right (DDDSydney)

use strongly typed actions for that

Page 118: Automated UI testing done right (DDDSydney)

design byinterface!

when you need it

Page 119: Automated UI testing done right (DDDSydney)

do you support multiple devices?

Page 120: Automated UI testing done right (DDDSydney)

do you doA/B testing?

Page 121: Automated UI testing done right (DDDSydney)

create interface for your Page Objects and

use the interface in your test scripts

Page 122: Automated UI testing done right (DDDSydney)

ISomePage

PCPage A/B testing pages iPadPage

Page 123: Automated UI testing done right (DDDSydney)

… and use one test script for all page variations

Page 124: Automated UI testing done right (DDDSydney)

apply

YAGNIin your

test code

Page 125: Automated UI testing done right (DDDSydney)

do

NOTcreate a

Page Object

until you need it

Page 126: Automated UI testing done right (DDDSydney)

do

NOTadd an action to

Page Object

until you need it

Page 127: Automated UI testing done right (DDDSydney)

do

NOTadd a property to

Page Object

until you need it

Page 128: Automated UI testing done right (DDDSydney)

do

NOTadd a getter to your property

until you need it

Page 129: Automated UI testing done right (DDDSydney)

run and maintain your tests

Page 130: Automated UI testing done right (DDDSydney)

run your tests

frequently

Page 131: Automated UI testing done right (DDDSydney)

fix the broken test right

when it breaks

Page 132: Automated UI testing done right (DDDSydney)

tests you do not run

===broken tests

Page 133: Automated UI testing done right (DDDSydney)

broken tests you do not fix

===ignored tests

Page 134: Automated UI testing done right (DDDSydney)

… and finally

Page 135: Automated UI testing done right (DDDSydney)

Confucius says …

Page 136: Automated UI testing done right (DDDSydney)

UI Testing is hard

Page 137: Automated UI testing done right (DDDSydney)

and could be a waste of time

Page 138: Automated UI testing done right (DDDSydney)

so

do NOT do itor

do it RIGHT

Page 139: Automated UI testing done right (DDDSydney)

when Done Right it is

well worth it

Page 140: Automated UI testing done right (DDDSydney)

thanks for attending

Page 141: Automated UI testing done right (DDDSydney)

time for a few Qs & hopefully few As

Blog: www.mehdi-khalili.comTwitter: @MehdiKhalili

http://www.mehdi-khalili.com/presentations/automated-ui-testing-done-right-at-dddsydney

Page 142: Automated UI testing done right (DDDSydney)

With thanks to our sponsors

Page 143: Automated UI testing done right (DDDSydney)

Please complete your feedback forms, and return

them to the registration desk for a chance to win a

Nokia Lumia


Top Related