12
Practical aspects of UI automation using Cucumber and Capybara by Alex Polovinko 3/14/2105

Cucumber_Capybara

Embed Size (px)

Citation preview

Page 1: Cucumber_Capybara

Practical aspects of UI automation using Cucumber and Capybara

by Alex Polovinko3/14/2105

Page 2: Cucumber_Capybara

Automation frameworks

• What is all this about?

#Software with additional functionality: run:

pass/fail

• From complexity to simplicity

#Abstraction is the point.

• Cucumber

# Simple, human collaboration: BDD that talks to

domain experts first and code second

# Cucumber lets software development teams

describe how software should behave in plain text.

The text is written in a 

business-readable domain-specific language and

serves as documentation, automated tests and

development-aid – all rolled into one format.

• Platforms and permutations

#https://cukes.info/platforms

Page 3: Cucumber_Capybara

Gherkin and Cucumber architecture

1. Format for Cucumber Specifications.#small computer language with a well-defined syntax

2. When you run Cucumber, it will generate

a report that verifies whether or not the

software behaves the way the Gherkin

document says.

3. Gherkin DSL and units#features/scenarios/steps

4. How that works?

5. Additional capabilities:#flexible step definitions

#tables

#examples

#calling steps from steps

#I18N

Page 4: Cucumber_Capybara

Capybarahttp://www.rubydoc.info/github/jnicklas/capybara

#Capybara is a library (Gem) written in the Ruby

programming language which makes it easy to simulate how a

user interacts with your application

#Capybara is acting as an abstraction layer over the driver.

Agnostic about the driver running your tests and comes with

Selenium support built in

#Capybara also comes with a built in DSL for creating

descriptive acceptance tests (Intuitive API which mimics the

language an actual user would use):

Navigating/Clicking links and buttons/Interacting with

forms/Querying/Finding/Scoping/Working with

windows/Scripting/Modals/Debugging

https://gist.github.com/zhengjia/428105

http://www.rubydoc.info/github/jnicklas/capybara/master

#Drivers

Capybara uses the same DSL to drive a variety of browser and headless

drivers.

Webdriver, native events.

Page 5: Cucumber_Capybara

Ruby• Ruby

Gems

Rails• Gemfile

CucumberGherkin

Capybara• Registerin

g drivers

First scenario• It’s

working!!!

Setup

+ RSpec to wrap it up

Page 6: Cucumber_Capybara

Challenges and Lessons learned

• Locators and browser specific Xpaths

• Iframes/windows

• Asynchronous JavaScript (Ajax and friends)

• Cross-site scripting prevention

• SSL alerts/modals handling

• FF profile settings

• Arbitrary JS (visibility of elements, mouse hover), JS engines

• Assertions (RSpec)/soft assertions handling

• State transitioning between steps/execution metadata

• Uniq scenarios and special chars in scenarios

Page 7: Cucumber_Capybara

Things you need to think of while developing scripts

o Good automation candidate:

#positive

#saving time

#robust

#false negatives

#cost of execution

o Critical/Smoke/Sanity/Regression

o Concept of orthogonal testing/coverage.

o Concept of tags: (wip, stories)

o Environmental variables, scalability, modularity

o Reusablity, common libraries. D(on’t)R(epeat)Y(ouself)

Page 8: Cucumber_Capybara

Platform/browsers/SauceLabs

Before/after hooks

Screenshots

Scenarios metadata and

cli

Scripts enhancements

Page 9: Cucumber_Capybara

Dev:

While developing

feature / autocommit

IDE integration

QA:

Functional testing

debugging

reproducing

Sandbox:

UAT

Integration/Regression

Scheduling/batch files

Parallel/consequent

CI integration/Jenkins

rerun

Scripts execution in different environments

Page 10: Cucumber_Capybara

Reporting or How to make your manager be happy

Report

Pretty

JSON

Custom formats

Plugins/Jenkings

HTML

Page 11: Cucumber_Capybara

Looking Ahead

• Questions?