selenium and cucumber selenium conf 2011

70

Upload: dimakovalenko

Post on 14-Jan-2015

3.387 views

Category:

Technology


6 download

DESCRIPTION

Presentation given during 2011 Selenium Conference in San Francisco

TRANSCRIPT

Page 1: Selenium and Cucumber Selenium Conf 2011
Page 2: Selenium and Cucumber Selenium Conf 2011

Dima Kovalenko

@dimacuswww.agilesoftwaretesting.comwww.dimakovalenko.comlinkedin.com/in/dimakovalenko

Page 3: Selenium and Cucumber Selenium Conf 2011

Past Experience

Page 4: Selenium and Cucumber Selenium Conf 2011

Disclaimer

> Dima.kind_of?(Developer)=> false

Page 5: Selenium and Cucumber Selenium Conf 2011

Why automated tests?

Page 6: Selenium and Cucumber Selenium Conf 2011

Why automated tests?

•Too expensive

•Too much work to create

•Not enough staff to maintain

•Never know the coverage level

•No one but developers knows what is being tested

Page 7: Selenium and Cucumber Selenium Conf 2011

We don’t need Automated Tests!

Page 8: Selenium and Cucumber Selenium Conf 2011

We don’t need Automated Tests!

The EndSee You all at Selenium 2012!

Page 9: Selenium and Cucumber Selenium Conf 2011
Page 10: Selenium and Cucumber Selenium Conf 2011

Selenium and Cucumber

Img Source: http://pickledillies.homestead.com/

Page 11: Selenium and Cucumber Selenium Conf 2011

Overview

•Set the stage

•Introduce Cucumber

•Good features

•Bad features

•???

•Profit!

Page 12: Selenium and Cucumber Selenium Conf 2011

Assumptions

•Startup or small business

•Understaffed

•Inadequate test coverage

•Need to defend existence of having automated tests to business.

Page 13: Selenium and Cucumber Selenium Conf 2011

The Stage

Page 14: Selenium and Cucumber Selenium Conf 2011

The Stage

•First casualty of an agile development environment is documentation. - me

Page 15: Selenium and Cucumber Selenium Conf 2011

The Stage

•First casualty of an agile development environment is documentation. - me

•No written test cases to speak of

Page 16: Selenium and Cucumber Selenium Conf 2011

The Stage

•First casualty of an agile development environment is documentation. - me

•No written test cases to speak of

•Need to deliver features, NOW!!!

Page 17: Selenium and Cucumber Selenium Conf 2011

The Stage

•First casualty of an agile development environment is documentation. - me

•No written test cases to speak of

•Need to deliver features, NOW!!!

•Groupon: Weekly deployments

Page 18: Selenium and Cucumber Selenium Conf 2011

The Stage•First casualty of an agile

development environment is documentation. - me

•No written test cases to speak of

•Need to deliver features, NOW!!!

•Groupon: Weekly deployments

•IMVU: Up to 50 deploys a day• http://timothyfitz.wordpress.com/2009/02/10/continuous-d

eployment-at-imvu-doing-the-impossible-fifty-times-a-day/

Page 19: Selenium and Cucumber Selenium Conf 2011

Why automated tests?

•Too expensive

•Too much work to create

•Not enough staff to maintain

•Never know the coverage level

•No one but developers knows what is being tested

Page 20: Selenium and Cucumber Selenium Conf 2011

Cucumber

Page 21: Selenium and Cucumber Selenium Conf 2011

Cucumber

•A BDD framework to help with TDD and other TLAs

Page 22: Selenium and Cucumber Selenium Conf 2011

Cucumber

•A BDD framework to help with TDD and other TLAs

•It’s Agile, Promotes Synergy, Enterprise, will shift Paradigms and completely Web 2.0

Page 23: Selenium and Cucumber Selenium Conf 2011

Cucumber

•A BDD framework to help with TDD and other TLAs

•It’s Agile, Promotes Synergy, Enterprise, will shift Paradigms and completely Web 2.0

•You too can be BUZZ WORD compliant!

Page 24: Selenium and Cucumber Selenium Conf 2011

Img Source: http://www.themoreyouknow.com/

Page 25: Selenium and Cucumber Selenium Conf 2011

Natural Language@searchFeature: Searching For Hello World, and some more overview of the feature that we are trying to test

@google Scenario: User Searches for Hello World on Google.com Given I'm on Google's Home Page And I search for Hello World

Then I should see Wikipedia's Hello World article as 1st result

@bing Scenario: User Searches for Hello World on Bing.com Given I'm on Bing's Home Page And I search for Hello World

Then I should see car videos as first result

Page 26: Selenium and Cucumber Selenium Conf 2011

Step DefinitionsGiven /^I'm on Google's Home Page$/ do @selenium.open "www.google.com"end

Given /^I'm on Bing's Home Page$/ do @selenium.open "www.bing.com"end

When /^I search for Hello World$/ do @selenium.type "q", "Hello World"end

Then /^I should see Wikipedia's Hello World article as 1st result$/ do assert_stuffend

Then /^I should see car videos as first result$/ do assert_stuffend

Page 27: Selenium and Cucumber Selenium Conf 2011

Why automated tests?

•Too expensive

•Too much work to create

•Not enough staff to maintain

•Never know the coverage level

•No one but developers knows what is being tested

Page 28: Selenium and Cucumber Selenium Conf 2011

Who should be writing tests?

Page 29: Selenium and Cucumber Selenium Conf 2011

Who should be writing tests?

•Developers

•Unit, Integration, Functional

Page 30: Selenium and Cucumber Selenium Conf 2011

Who should be writing tests?

•Developers

•Unit, Integration, Functional

•QAs

•Functional, End-To-End

Page 31: Selenium and Cucumber Selenium Conf 2011

Who should be writing tests?

•Developers

•Unit, Integration, Functional

•QAs

•Functional, End-To-End

•Everyone else

•At least the feature definitions

Page 32: Selenium and Cucumber Selenium Conf 2011

Why automated tests?

•Too expensive

•Too much work to create

•Not enough staff to maintain

•Never know the coverage level

•No one but developers knows what is being tested

Page 33: Selenium and Cucumber Selenium Conf 2011

Mind Map Solution

Page 34: Selenium and Cucumber Selenium Conf 2011

Why automated tests?

•Too expensive

•Too much work to create

•Not enough staff to maintain

•Never know the coverage level

•No one but developers knows what is being tested

Page 35: Selenium and Cucumber Selenium Conf 2011

Good Features•Tags

•Encourages BDD/TDD

•Supports multiple test drivers

•Selenium 1 and Selenium 2 support

•Multilingual

• i18n support

•Readable test results

Page 36: Selenium and Cucumber Selenium Conf 2011

Tags@searchFeature: Searching For Hello World, and some more overview of the feature that we are trying to test

@google @selenium Scenario: User Searches for Hello World on Google.com Given I'm on Google's Home Page And I search for Hello World

Then I should see Wikipedia's Hello World article as 1st result

@bing Scenario: User Searches for Hello World on Bing.com Given I'm on Bing's Home Page And I search for Hello World

Then I should see car videos as first result

Page 37: Selenium and Cucumber Selenium Conf 2011

Tags@searchFeature: Searching For Hello World, and some more overview of the feature that we are trying to test

@google @selenium Scenario: User Searches for Hello World on Google.com Given I'm on Google's Home Page And I search for Hello World

Then I should see Wikipedia's Hello World article as 1st result

@bing Scenario: User Searches for Hello World on Bing.com Given I'm on Bing's Home Page And I search for Hello World

Then I should see car videos as first result

Page 38: Selenium and Cucumber Selenium Conf 2011

Encourages BDD/TDD

•Write feature description first

•Run test see it fail

•Create one step definition at the time

•Write functionality for the step

•Run test see it pass

Page 39: Selenium and Cucumber Selenium Conf 2011

First run

Page 40: Selenium and Cucumber Selenium Conf 2011

First run

Page 41: Selenium and Cucumber Selenium Conf 2011

Write Step Definitions

Page 42: Selenium and Cucumber Selenium Conf 2011

Write More Step Definitions

Page 43: Selenium and Cucumber Selenium Conf 2011

Even More Step Definitions

Page 44: Selenium and Cucumber Selenium Conf 2011

Multiple Test Drivers

Steam

CelerityCulerity

FireWatirSafariWatir

ChromeWatir Img Source: Wikipedia

Page 45: Selenium and Cucumber Selenium Conf 2011

Selenium 1 supportBefore do |scenario| @selenium = Selenium::Client::Driver.new( :host => "localhost", :port => 4444, :browser => “firefox”, :url => “www.google.com”)end

Page 46: Selenium and Cucumber Selenium Conf 2011

Selenium 1 Tip

Use Hpricot Or Nokogiri!!!

page = Hpricot(@selenium.get_html_source)

Page 47: Selenium and Cucumber Selenium Conf 2011
Page 48: Selenium and Cucumber Selenium Conf 2011
Page 49: Selenium and Cucumber Selenium Conf 2011

Selenium 2 support

Page 50: Selenium and Cucumber Selenium Conf 2011

Selenium 2 support

•Capybara + Selenium = Love

Page 51: Selenium and Cucumber Selenium Conf 2011

Selenium 2 support

•Capybara + Selenium = Love

•Capybara + Selenium + Rails = .......

Page 52: Selenium and Cucumber Selenium Conf 2011

Capybara

•Uses Nokogiri

•Uses XPath outside of browser

•Works outside of rails

Page 53: Selenium and Cucumber Selenium Conf 2011

MultilingualJVM: JRuby, Java

.NET: IronRuby, IronRuby .NET, MonoAdoby Flex: FunFX, Melomel

PythonErlangGroovyScala

ClosureJavascript

Spring

Page 54: Selenium and Cucumber Selenium Conf 2011

Java Step Definitionpackage cukes;

import cuke4duke.annotation.I18n.EN.Given;import java.util.List;import java.util.ArrayList;

public class BellySteps { private List<String> belly = new ArrayList<String>();

@Given("I have (\\d+) cukes in my belly") public void bellyCukes(int cukes) { for(int i = 0; i < cukes; i++) { belly.add("cuke " + i); } }}

Page 55: Selenium and Cucumber Selenium Conf 2011

i18n

Page 56: Selenium and Cucumber Selenium Conf 2011

i18nФункционал: Сложение чисел Чтобы не складывать в уме Все, у кого с этим туго Хотят автоматическое сложение целых чисел

Сценарий: Сложение двух целых чисел Допустим я ввожу число 50 И затем ввожу число 70 Если я нажимаю "+" То результатом должно быть число 120

Page 57: Selenium and Cucumber Selenium Conf 2011

i18n Chinese

功能 : 加法 為了避免愚蠢的錯誤 作為一個數學白痴 我希望有人能告訴我兩個數相加的結果

場景大綱 : 將兩個數相加 假設我已經在計算機上輸入 < 數值 _1> 而且我已經在計算機上輸入 < 數值 _2> 當我按下 < 按鈕 > 那麼螢幕上應該顯示 < 結果 >

Page 58: Selenium and Cucumber Selenium Conf 2011

i18n LOLz

OH HAI: STUFFING

MISHUN: CUCUMBR I CAN HAZ IN TEH BEGINNIN 3 CUCUMBRZ WEN I EAT 2 CUCUMBRZ DEN I HAS 2 CUCUMBERZ IN MAH BELLY AN IN TEH END 1 CUCUMBRZ KTHXBAI

Page 59: Selenium and Cucumber Selenium Conf 2011

Readable Test Results

Page 60: Selenium and Cucumber Selenium Conf 2011

Bad Features

•Regex step definitions

•Hard To find Step Definitions

•Slower

•Natural language parser

•Messy directory structure

Page 61: Selenium and Cucumber Selenium Conf 2011

Regex Step Definitions

•Good: Reuse Definitions

•Bad:

• Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do

Page 62: Selenium and Cucumber Selenium Conf 2011

Hard to find Step Definitions

cucumber-tmbundle

Vim Rails

Page 63: Selenium and Cucumber Selenium Conf 2011

Bad Features

•Regex step definitions

•Hard To find Step Definitions

•Slower

•Natural language parser

•Messy directory structure

Page 64: Selenium and Cucumber Selenium Conf 2011

Conclusion

•Cucumber is a great tool to

•Describe Features

•Document Features

•Get the whole team involved

•However, it has downsides also

Page 65: Selenium and Cucumber Selenium Conf 2011

@dhhRSpec offends me aesthetically with no discernible benefit for its added complexity over test/unit.

Page 66: Selenium and Cucumber Selenium Conf 2011

@dhhRSpec offends me aesthetically with no discernible benefit for its added complexity over test/unit.

Cucumber makes no sense to me unless you have clients reading the tests. Why would you build a test-specific parser for English?

Page 67: Selenium and Cucumber Selenium Conf 2011

@dhhRSpec offends me aesthetically with no discernible benefit for its added complexity over test/unit.

Cucumber makes no sense to me unless you have clients reading the tests. Why would you build a test-specific parser for English?

The important thing is of course that we get people testing, so tools shouldn't matter too much....

Page 68: Selenium and Cucumber Selenium Conf 2011

Work @ Groupon

www.groupon.com/techjobs

Page 69: Selenium and Cucumber Selenium Conf 2011

The End

Page 70: Selenium and Cucumber Selenium Conf 2011