Top Banner
Cucumber, PhantomJS, and Selenium Dustin Barnes Solutions Architect
21

Automated Testing with Cucumber, PhantomJS and Selenium

Jan 15, 2015

Download

Software

Dev9Com

Intro to Automated Testing with Cucumber, PhantomJS and Selenium
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Automated Testing with Cucumber, PhantomJS and Selenium

Cucumber, PhantomJS, and

SeleniumDustin Barnes

Solutions Architect

Page 2: Automated Testing with Cucumber, PhantomJS and Selenium

Cucumber• Behavior-driven development (BDD)• Originally a Ruby project• Cucumber-jvm for Java projects• Language called Gherkin• Natural-language specification

Page 3: Automated Testing with Cucumber, PhantomJS and Selenium

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.

Page 4: Automated Testing with Cucumber, PhantomJS and Selenium

Why BDD?• PM/BA write cucumber features– Test first!– Easy when test == spec

• Developers write step definitions

Page 5: Automated Testing with Cucumber, PhantomJS and Selenium

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

Page 6: Automated Testing with Cucumber, PhantomJS and Selenium

Cucumber Example

Page 7: Automated Testing with Cucumber, PhantomJS and Selenium

Cucumber Step Definitions

Page 8: Automated Testing with Cucumber, PhantomJS and Selenium

Cucumber Parameterization

Page 9: Automated Testing with Cucumber, PhantomJS and Selenium

Cucumber Step Definitions

Page 10: Automated Testing with Cucumber, PhantomJS and Selenium

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

Page 11: Automated Testing with Cucumber, PhantomJS and Selenium

Selenium• Does it even need an introduction? • Browser driver for acceptance tests• Requires a real browser

Page 12: Automated Testing with Cucumber, PhantomJS and Selenium

Selenium

Page 13: Automated Testing with Cucumber, PhantomJS and Selenium

Selenium + Cucumber

Page 14: Automated Testing with Cucumber, PhantomJS and Selenium

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?

Page 15: Automated Testing with Cucumber, PhantomJS and Selenium

PhantomJS• PhantomJS to the rescue!• Headless WebKit browser• Scriptable through JavaScript• Now a PhantomJS Driver in

WebDriver

Page 16: Automated Testing with Cucumber, PhantomJS and Selenium

PhantomJS

Page 17: Automated Testing with Cucumber, PhantomJS and Selenium

PhantomJS Driver

Page 18: Automated Testing with Cucumber, PhantomJS and Selenium

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

Page 19: Automated Testing with Cucumber, PhantomJS and Selenium

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

Page 20: Automated Testing with Cucumber, PhantomJS and Selenium

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

Page 21: Automated Testing with Cucumber, PhantomJS and Selenium

Q&A