Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Web Acceptance Testing For Grumpy Programmers
Search
Chris Hartjes
May 15, 2013
Programming
3
410
Web Acceptance Testing For Grumpy Programmers
How you can bend Behat + Mink + PhantomJS to your will to create web acceptance tests
Chris Hartjes
May 15, 2013
Tweet
Share
More Decks by Chris Hartjes
See All by Chris Hartjes
Confessions of a not-so-accidental leader
grumpycanuck
0
170
Lessons Learned From 10 Years Of Testing
grumpycanuck
4
120
Learn To Test Like A Grumpy Programmer
grumpycanuck
0
220
Time Management For Grumpy Programmers
grumpycanuck
0
190
Learn To Test Like A Grumpy Programmer
grumpycanuck
1
220
Learn To Test Like A Grumpy Programmer
grumpycanuck
2
190
Grumpy Testing Patterns
grumpycanuck
1
920
Embrace Your Inner Grumpy: Metatesting in 2016
grumpycanuck
0
120
Smelly Tests
grumpycanuck
0
83
Other Decks in Programming
See All in Programming
Rubyでつくるパケットキャプチャツール
ydah
0
170
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1.4k
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
390
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
9
2.3k
Package Traits
ikesyo
1
210
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
280
Azure AI Foundryのご紹介
qt_luigi
1
170
混沌とした例外処理とエラー監視に秩序をもたらす
morihirok
13
2.2k
Beyond ORM
77web
11
1.6k
Lookerは可視化だけじゃない。UIコンポーネントもあるんだ!
ymd65536
1
130
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
140
ASP.NET Core の OpenAPIサポート
h455h1
0
110
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
98
18k
RailsConf 2023
tenderlove
29
970
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
570
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Facilitating Awesome Meetings
lara
51
6.2k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
Agile that works and the tools we love
rasmusluckow
328
21k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Transcript
Web Acceptance Testing For Grumpy Programmers php|tek 2013 May 15,
2013 Chris Hartjes
whoami
Test vs. Test
A New Test Type
A New Test Type “BDD is a second-generation, outside–in, pull-based,
multiple-stakeholder, multiple- scale, high-automation, agile methodology. It describes a cycle of interactions with well- defined outputs, resulting in the delivery of working, tested software that matters”
A New Test Type
A New Test Type Behavior-driven development specifies that tests of
any unit of software should be specified in terms of the desired behavior of the unit.
What’s The Scenario Given I am in a talk When
the speaker is presenting And he glares at me I remain quiet
What’s The Scenario Tests are readable by people first Non-technical
people can be taught the DSL
Getting Started?
Behat
What Is It? “A PHP framework for testing your business
expectations” http://behat.org
How Do I Use It 1. Install it via Composer
2. ??? 3. Profit!
How Do I Use It? 1. Install via Composer 2.
Create a Feature with a Scenario 3. Run your test 4. Profit!
Installing
Create Your Feature File
What Is A Scenario? A test that covers specific behavior
you wish to test
What Is A Scenario?
First Run
Steps To Implement
Steps To Implement
Write Some Code
Scenario Passes!
What About Web Testing?
Mink Framework for doing web acceptance testing Sits between Behat
and browser emulator http://mink.behat.org
Installing
Browser Emulation
How does it help? Provides a common API for browser
interaction Provides built-in functionality for common tasks
Goutte Pure PHP browser emulator Great for testing non-Javascript functionality
Installing Goutte
Behat + Goutte Config
Sample Mink Feature
Proof!
What About JavaScript?
PhantomJS
PhantomJS Headless browser based on WebKit Node app (don’t worry,
npm will save you)
Installing PhantomJS Good instructions at http://slid.es/gimler/behat-mink-phantomjs Install npm (Node Package
Manager) `npm install -g phantomjs`
Selenium2 + PHPUnit
Why Selenium2? PhantomJS can pretend to be a standalone Selenium2
server Configure Behat to send JavaScript scenarios to it
Behat + PhantomJS
Behat + PHPUnit Adds support for generic assertions
Adding in PHPUnit
Run PhantomJS `phantomjs --phantomjs --webdriver=8643`
Our first JS Scenario
Proof!
Now it gets grumpier
CSS Selectors Best way to locate specific elements on a
page If you disliked CSS before, this might push you over the edge
Y U MAD CHRIS? 'html body div.container div.row div.span9 section#modals
div#myModal.modal div.modal-header h3#myModalLabel' TOTALLY INTUITIVE Learn your browser debugger tools well
Pro Tip #1 Give all your elements ID’s Make it
easier for CSS selectors to find them
Waiting For JavaScript Behat steps will need wait() commands for
JS Gives time for browser to render Acceptance tests are not supposed to be fast
Pro Tip #2 Be conservative in your waiting estimates
Breaking down the steps
Breaking down the steps
Lessons Learned WAT is definitely “test-after” Learn CSS really well
or else Twitter Rage ensues Good ratio is 90% unit - 10% WAT
Lessons Learned Keep your feature files focused to scenario groups
Create app-critical scenarios
Advanced Level Different Behat configuration files for different environments `behat
---config <path to config file>`
Advanced Level Use Behat Gearman extension to run scenarios in
parallel http://extensions.behat.org/gearman/
Building Testable Apps http://grumpy-testing.com
PHPUnit Cookbook http://grumpy-phpunit.com
Testing Screencasts
Thank You! https://github.com/chartjes/wat-tek13 https://joind.in/8167 @grmpyprogrammer