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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Chris Hartjes
May 15, 2013
Programming
470
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
More Decks by Chris Hartjes
See All by Chris Hartjes
Confessions of a not-so-accidental leader
grumpycanuck
0
260
Lessons Learned From 10 Years Of Testing
grumpycanuck
4
160
Learn To Test Like A Grumpy Programmer
grumpycanuck
0
270
Time Management For Grumpy Programmers
grumpycanuck
0
240
Learn To Test Like A Grumpy Programmer
grumpycanuck
1
280
Learn To Test Like A Grumpy Programmer
grumpycanuck
2
230
Grumpy Testing Patterns
grumpycanuck
1
1k
Embrace Your Inner Grumpy: Metatesting in 2016
grumpycanuck
0
160
Smelly Tests
grumpycanuck
0
120
Other Decks in Programming
See All in Programming
Creating Composable Callables in Contemporary C++
rollbear
0
170
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
900
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
280
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.6k
AIで効率化できた業務・日常
ochtum
0
150
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.8k
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.5k
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
270
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
180
スマートグラスで並列バイブコーディング
hyshu
0
270
act1-costs.pdf
sumedhbala
0
130
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
610
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
How to Talk to Developers About Accessibility
jct
2
270
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Being A Developer After 40
akosma
91
590k
Exploring anti-patterns in Rails
aemeredith
3
430
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
210
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Tell your own story through comics
letsgokoyo
1
980
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
380
How to Ace a Technical Interview
jacobian
281
24k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Typedesign – Prime Four
hannesfritz
42
3.1k
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