but i know what i like: abstraction is the key to automation
TRANSCRIPT
But I Know What I LikeAbstraction is the Key to Automation
(@dylanlacey -- Sauce Labs)
Preheat the oven to 375 Degrees
Cream 250g of butter and 1 cup of sugarin a mixing bowl
Mix in 2 cups of flour and 1 cup of milk,and combine
Mix in 2 tsp of vanilla extract
Pour into prepared tins and bake 1 hour
••
•
••
The Exhausting Reality
Set the Temperature Dial of the Oven to 375 Degrees Fahrenheit
Place 250g of butter into the bowl of a mixer
Place 1 cup of sugar into the same bowl
Turn the mixer onto “7”
Mix until the mixture is pale yellow
Turn the Mixer down to “1”
Add 2 cups of flour to the mixing bowl
Add 1 cup of milk to the mixing bowl
Allow the mixer to run until the mixture looks the same colour throughout
Add 2tsp of Vanilla to the mixing bowl
Mix in 2 cups of flour and 1 cup of milk, and combine
•
•
•
•
•
•
•
•
•
•
•
The Exhausting Reality
Set the Temperature Dial of the Oven to 375 Degrees Fahrenheit
Place a bowl on a scale
Turn the scale on by pressing the “on” button
Use a knife to cut a stick of butter into 100 slices
Place one slice into the bowl on the scale
Read the Scale
Continue to place slices of butter into the bowl until the scale reads ‘250g’
Open a container of sugar
Get a dry cup measure from the drawer
Scoop sugar from the container into the measuring cup until it reaches the topof the cup
Draw the back of a knife across the surface of the measuring cup, allowing theexcess sugar to fall back into the canister
Place the measuring cup on the counter
Take the mixer out of the cupboard
Place the mixer on the bench
Insert the square blade into the right hand blade hole on the mixer
Insert the round blade into the left hand blade hole on the mixer
The Exhausting Reality
Being Specific is Reliable
PFFT WHATEVER
You Have Questions.
Who is this loudmouth?
Why am I even listening to him?
What time is Morning Tea?
Gee I love bacon.
••••
Who is this guy?
What is he talkingabout?
What is a Good Abstraction?
How Abstraction makes for Automation
Abstraction of Scripts
Abstraction of Infrastructure
•
•
•
•
What AreAbstractions?
Good Abstractions Are:
Not “Leaky”
Understanding Enhancing
(For our purposes) Shareable
•••
Abstraction is TotesGreat
Set the Temperature Dial of the Oven to 375 Degrees Fahrenheit
Place a bowl on a scale
Turn the scale on by pressing the “on” button
Use a knife to cut a stick of butter into 100 slices
Place one slice into the bowl on the scale
Read the Scale
Continue to place slices of butter into the bowl until the scale reads ‘250g’
Open a container of sugar
Get a dry cup measure from the drawer
Scoop sugar from the container into the measuring cup until it reaches the topof the cup
Draw the back of a knife across the surface of the measuring cup, allowing theexcess sugar to fall back into the canister
Place the measuring cup on the counter
Take the mixer out of the cupboard
Place the mixer on the bench
Insert the square blade into the right hand blade hole on the mixer
Insert the round blade into the left hand blade hole on the mixer
The Exhausting Reality
Actually, screw cake.
Go to Chucks
Drink a Lowenbrau Dunkel
Take a shot of Tequila
Drink a White Rabbit Pale Ale
Take a sip of Natural Ice
Grimace and Skoll The Rest
Wash it out with a Stein ofWiheinstephaner
Sleep in a doorway
Experience Regret
•
•
•
•
•
•
•
•
•
Go to Chucks
Drink a Lowenbrau Dunkel
Take a shot of Tequila
Drink a White Rabbit Pale Ale
Take a sip of Natural Ice
Grimace and Skoll The Rest
Wash it out with a Stein ofWiheinstephaner
Sleep in a doorway
Experience Regret
•
•
•
•
•
•
•
•
•
Go to Chucks
Drink 4 Beers
Take a shot
Sleep in a doorway
Experience Regret
•
•
•
•
•
Abstraction for Scripts
Maintenance(Easier)
Creation(Faster) /
Abstraction forInfrastructure
Execution(Faster)
Maintenance(Easier) /
TESTINGIS ALREADY
ABSTRACTION
Abstraction forScripting
(2ish minutes of PageObjects)
PageObjects areAbstract
Methods for “Doin’ Stuff” on a page
Should return Page Objects when givingnew pages
Encapsulate functionality and providesingle-line access to tasks
Ruby has SitePrism, page_objects_gem
••
•
•
Abstraction forScripting
(15 minutes of Capybara)
Go to Chucks
Drink a Lowenbrau Dunkel
Take a shot of Tequila
Drink a White Rabbit Pale Ale
Take a sip of Natural Ice
Grimace and Skoll The Rest
Wash it out with a Stein ofWiheinstephaner
Sleep in a doorway
Experience Regret
•
•
•
•
•
•
•
•
•
Go to Chucks
Drink 4 Beers
Take a shot
Sleep in a doorway
Experience Regret
•
•
•
•
•
That’s what Capybaradoes. No, really.
Capybara for Everyone!
Free, open source tool, widely used bythe Ruby Community
Able to run “headless” for JS-free testing
Able to use Selenium to drive browsers
•
••
Capybara Basics
find_xpath ‘//table tr’
find_css ‘table.tr.beer’find_field(‘mixer’).valuefind(#pantry).find(‘vermouth’)
•
•••
Capybara Basics
has_css? ‘#sobriety’has_xpath? ‘//table tr’has_content? ‘shaken’
•••
Capybara Basics
click_link ‘http://www.hendricksgin.com’click_button ‘skoll’click_on ‘blender’
•••
Capybara exact &match
Capybara.exact = true All future matches must be exact Default false -> Gin matches Gin and Tonic click_link(“jigger”, exact: true)
Capybara.match = prefer_exact Sets strategy for multiple matches Default ‘smart’, also one, first, prefer_exact click_link(“shout”, match: one)
Capybara with Forms
visit ‘/login’fill_in ‘first_name’, :with => “Dylan”fill_in ‘last_name’, :with => “Lacey”select(‘Ruby’), :from => “Languages”check ‘Awesome’attach_file(‘Beer’, ‘/Path/To/Beer’)
Scopes Save you fromSelector Hell
within ‘party’ do fill_in :pint, :with => “Kilkenny”end
find(‘#barfridge’).click_link ‘open’
Human Readable?
Human Readable.
Abstraction forScripting
(15 minutes of Cucumber)
Write Tests InEngl“ish”
(Technically it’s ‘gherkin’)
Scenario: I am Sober Given I am on http://en.wikipedia.org/wiki/Main_Page When I enter "Old Fashioned" into the search box And I click the searchButton Then I should see "The Old Fashioned is an IBA Official Cocktail"
It’s not Magic
Features in Gherkin are implemented by‘step definitions’
You/r team write the step definitions
Step definitions can be any code
Step definitions can be many programminglanguages
•
•••
That feature SUCKED
Scenario: I am Sober Given I am on Wikipedia’s Main Page When I search for “Old Fashioned” Then I should see the “Old Fashioned” entry
Abstractions AllowMaintenance
Given there is a user JackAnd Jack owns a breweryAnd Jack has a paid accountAnd Jack enters his passwordAnd Jack enters his usernameWhen he logs inThen I should take a shot BRITTLE
BRITTLE
Abstractions AllowMaintenance
When A Brewer Logs InThen I should take a shot
AWESOME
Don’t Hide Too MuchBackgrounds => Steps run before each feature
background: Given Jack is a Brewer And Jack has not paid his bill
Scenario: Jack orders something delicious When Jack orders Woodford Reserve Then Jack sees “Shove Off”
Scenario: Jack orders something gross When Jack orders Tequila Then Jack sees “This time, but pay up!”
Cucumber meansmaking nice with
Developers
Developer Facts:
Developers get really involved in theirwork
We’re sorry about the time we got madat you for that one thing
Developers want the same thing youwant: Better Product
Y’all are as smart as them, if not smarter(don’t tell them I said that)
•
•
•
•
Sell to Developers:
You’re both focused on Customer Quality
You both want to do excellent work
“My Job is to make *YOU* look good”(Thanks, JeanAnn Harrison!)
•••
Test + Dev with Cuke
Work together to build good tests
Devs give step support and get tests anddiagnostics
Testers give expert advice and get flexibletools
You can use different dev & test languages
DANGER: Don’t let the devs make setup
••
•
••
Abstraction forInfrastructure
Execution(Faster)
Maintenance(Easier) /
Selenium requiresALL THE THINGS
Chrome, Safari, Opera,IE, Firefox
MULTIPLIED BY
Mac 10.8, WindowsXP/7/8, Linux, iOS?!
MULTIPLIED BY
Versions!
•
•
•
Make it someone else’sproblem
Selenium Grid
Virtual Machines
Third Party Services
•••
Selenium Grid
CHEAP EASY FAST
To ObtainTo Operate
To DistributeTo Parallelize
To SetupTo Deploy
(EC2)
(Abstract Browsers)
I <3 VMs
CHEAP EASY FASTTo Run
To ReplicateTo Share
To RestoreTo UpdateTo Backup
To DuplicateTo Setup
To Destroy
(Abstract Computers)
Why Not Both?
Easy Parallelization
Platforms you otherwise can’t support
Significantly lower staff & infrastructurecosts
•••
3rd Party Services
CHEAP EASY FASTCapacity
Xtra Features (?)Maintenance
Integration (?)Updating
Team Work (?)
Access To NewParalleling (?)
CI
(Abstract Solutions)
(?) = Dependant on Provider?
Selenium Grid+
3rd Party VMs=
Parallel Heaven
Bonus!
Abstraction forInfrastructure
Bonus!
Appium
Appium(Abstract ...Devices?!)
Native App Automation withSelenium
Any Selenium Webdriver ToolNo App modifications
Totally Free and Open Source!
(Mac client only ATM. Sorry >.>)
How to Appium
Download and Install Appium fromhttp://www.appium.io
Run Appium with your App
Write your tests using the SeleniumWebdriver JSON Subset:https://github.com/appium/appium/wiki/JSON-Wire-Protocol:-Supported-Methods
Run your tests
•
••
•
WAAAAA I Don’tHave a Mac!
Contributes to theAppium Project
Runs Appium in theirCloud
Is working onAndroid support
•
•
•
Questions?(@dylanlacey)
Resources
Play with Sauce Labs:
1000 Manual Minutes
200 Automated Minutes
Promo Code: TestLearnPlay (exp3/14)
Our Blog: http://www.sauceio.com
••••
•
Tools & Links
Capybara: https://github.com/jnicklas/capybara
Cucumber: http://cukes.info/
Appium: http://appium.io/
Supported methods: http://goo.gl/MiPcH
Ruby examples: http://goo.gl/uQGh5
Sauce Labs Sign Up: http://goo.gl/uBTXX
(Don’t forget to click ‘I Have a Promo
•••
•••
•