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
450
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
220
Lessons Learned From 10 Years Of Testing
grumpycanuck
4
130
Learn To Test Like A Grumpy Programmer
grumpycanuck
0
240
Time Management For Grumpy Programmers
grumpycanuck
0
220
Learn To Test Like A Grumpy Programmer
grumpycanuck
1
250
Learn To Test Like A Grumpy Programmer
grumpycanuck
2
210
Grumpy Testing Patterns
grumpycanuck
1
990
Embrace Your Inner Grumpy: Metatesting in 2016
grumpycanuck
0
150
Smelly Tests
grumpycanuck
0
98
Other Decks in Programming
See All in Programming
イベントストーミングのはじめかた / Getting Started with Event Storming
nrslib
1
740
分散DBって何者なんだ... Spannerから学ぶRDBとの違い
iwashi623
0
110
Java_プロセスのメモリ監視の落とし穴_NMT_で見抜けない_glibc_キャッシュ問題_.pdf
ntt_dsol_java
0
230
Stay Hacker 〜九州で生まれ、Perlに出会い、コミュニティで育つ〜
pyama86
2
2.6k
データファイルをAWSのDWHサービスに格納する / 20251115jawsug-tochigi
kasacchiful
2
100
全員アーキテクトで挑む、 巨大で高密度なドメインの紐解き方
agatan
8
10k
Building AI Agents with TypeScript #TSKaigiHokuriku
izumin5210
5
1k
[SF Ruby Conf 2025] Rails X
palkan
0
360
GraalVM Native Image トラブルシューティング機能の最新状況(2025年版)
ntt_dsol_java
0
170
Flutterチームから作る組織の越境文化
findy_eventslides
0
600
FlutterKaigi 2025 システム裏側
yumnumm
0
1.2k
OSS開発者の憂鬱
yusukebe
13
11k
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Java REST API Framework Comparison - PWX 2021
mraible
34
9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.8k
Done Done
chrislema
186
16k
Into the Great Unknown - MozCon
thekraken
40
2.2k
Agile that works and the tools we love
rasmusluckow
331
21k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Speed Design
sergeychernyshev
33
1.3k
Unsuck your backbone
ammeep
671
58k
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