automated testing with cucumber, phantomjs and selenium
DESCRIPTION
Intro to Automated Testing with Cucumber, PhantomJS and SeleniumTRANSCRIPT
Cucumber, PhantomJS, and
SeleniumDustin Barnes
Solutions Architect
Cucumber• Behavior-driven development (BDD)• Originally a Ruby project• Cucumber-jvm for Java projects• Language called Gherkin• Natural-language specification
BDD• Alternative to TDD• Response to issues with TDD:– Where to start in process?– What to test and what not to test?– How much to test at once– What to call the tests– Understand why a test fails
• Specifies the *behavior* of your unit.
Why BDD?• PM/BA write cucumber features– Test first!– Easy when test == spec
• Developers write step definitions
Cucumber Nomenclature• Feature – Single file, ideally
describing a single feature• Scenario – A test case• Given-When-Then: Test preconditions,
execution, and postconditions• And, But – Additional test constructs
Cucumber Example
Cucumber Step Definitions
Cucumber Parameterization
Cucumber Step Definitions
Details, details…• Doesn’t need to be frontend-based• Can use TestNG, JUnit, etc. • You write all the step details• Compose steps for more powerful
statements
Selenium• Does it even need an introduction? • Browser driver for acceptance tests• Requires a real browser
Selenium
Selenium + Cucumber
Continuous Integration• Selenium WebDriver requires a browser• Your CI server probably doesn’t have
Chrome or Firefox installed– Or even a GUI…
• How can we run these tests without setting up a remote runner or selenium grid?
PhantomJS• PhantomJS to the rescue!• Headless WebKit browser• Scriptable through JavaScript• Now a PhantomJS Driver in
WebDriver
PhantomJS
PhantomJS Driver
Demo• We’ve offered 4 PMs as sacrifice to
the demo gods…
• Project available on the dev9 GitHub– https://github.com/dev9com/cucumber-java-selenium-example
What have we done?• Textual language description of tests• As frontend-driven acceptance tests–Written by PM/BA…?
• Running on every commit on our CI server
Gotchas• PhantomJS cannot test browser quirks– Use a separate test suite just for browser-
specific testing. Manual, or with BrowserStack. – Usually <10% of issues need specific browser
testing
• Textual language may give people a false sense of security– Only as strong as the step definitions
Q&A