bdd approach with selenium rc

42
Behavior Driven Development (BDD) with Selenium RC Presented by: Mykola Kolisnyk

Upload: mykola-kolisnyk

Post on 11-Jul-2015

10.394 views

Category:

Spiritual


2 download

TRANSCRIPT

Page 1: BDD approach with Selenium RC

Behavior Driven Development (BDD) with Selenium RC

Presented by: Mykola Kolisnyk

Page 2: BDD approach with Selenium RC

About me

Mykola Kolisnyk

Overall experience: 6+ yearsPositions: QA Lead

Senior Automation Consultant Test Automation Architect

Tools: SilkTestTestCompleteSeleniumRFTSoapUI

Co-author: “SilkTest manual” book (http://silktutorial.ru)Portal http://automated-testing.info

Page 3: BDD approach with Selenium RC

About presentation

Behavior-Driven

Development

Page 4: BDD approach with Selenium RC

Typical toolset

Page 5: BDD approach with Selenium RC

Test Designer

xUnit Solution difficulties

Test Automation Engineer

Business AnalystDeveloper

Not all people read tests code

Page 6: BDD approach with Selenium RC

xUnit Solution difficulties

Complex code constructions are hard to maintain

If it works don't touch it!

Page 7: BDD approach with Selenium RC

xUnit Solution difficulties

Low informative report

What exactly has happened?

Page 8: BDD approach with Selenium RC

We gonna make it better

How to improve it

Page 9: BDD approach with Selenium RC

We gonna make it better

It should be clear to everyone

Page 10: BDD approach with Selenium RC

We gonna make it better

More people should be involved

Page 11: BDD approach with Selenium RC

We gonna make it better

Profit

Page 12: BDD approach with Selenium RC

New approach?

Behavior-Driven Development?

Page 13: BDD approach with Selenium RC

How about tests like that?

Behavior description prior to implementation

Page 14: BDD approach with Selenium RC

List of BDD engines

Cucumber

Freshen

NBehave

JBehave

Behat

Page 15: BDD approach with Selenium RC

BDD tests structure

FeatureBackground

Scenario

Background

Scenario 1

Scenario 2

Scenario N

Given

When

Then

Given

When

Then

Page 16: BDD approach with Selenium RC

When I log into the system as “login”/”password”

When /log into the system as “(.*)”\/”(.*)”/ do |login,password|app.login( login , password )

end

class Appdef login( username , password )

# Some actionsend

end

Connections to code

Actual Code

Text instruction

Explicit Selenium calls

Page 17: BDD approach with Selenium RC

BDD project structure

Main working folder

Keyword implementations

Core library

Initialization module

Tests storage

Page 18: BDD approach with Selenium RC

What BDD brings?

Natural language instructions

I can get it!

Page 19: BDD approach with Selenium RC

What BDD brings?

Reports show steps to reproduce

I see where the problem occurs!

Page 20: BDD approach with Selenium RC

What BDD brings? Process optimization

On-demand runs

Writes user stories

BA

Test Automation pipeline

Page 21: BDD approach with Selenium RC

What BDD brings? Process optimization

Test Automation pipeline

On-demand runs

Write simple tests

Dev

Page 22: BDD approach with Selenium RC

What BDD brings? Process optimization

Test Automation pipeline

Analyze results

Designs tests

Tester

Page 23: BDD approach with Selenium RC

What BDD brings? Process optimization

Test Automation pipeline

Results analysis

Implementation & code maintenance

ATE

Page 24: BDD approach with Selenium RC

Who participates in automation?

Page 25: BDD approach with Selenium RC

Stages to framework migration

Decompose code by details level

Extract Selenium object and wrap it into global object

Wrap each function with appropriate keyword

Re-design existing tests

Page 26: BDD approach with Selenium RC

Framework decomposition

Business Functions level

Pages level

Core level

Explicit Selenium

calls

Explicit Selenium

calls

We care what we do only

We care where we are

We care how to do it

Page 27: BDD approach with Selenium RC

Framework re-organization to BDD

Code layer

Business Functions level

Pages level

Core levelGlobal Selenium Object

Page 28: BDD approach with Selenium RC

Code layer

Framework re-organization to BDDImplementation layer

BF level

Pages level

Core level

Tests layerBF level

Pages level

Core levelSelenium

When /click on “(.*)” element/ do |locator|selenium.click( locator )

end

selenium.click( locator );

When I click on “Test” element

Page 29: BDD approach with Selenium RC

Call Command

Stop

Start

Selenium place

Collect all resources

Initialize shell

Run instructions

Finalize execution

Generate report

Global Selenium Object

DefaultSelenium.new

selenium.stop()

selenium.start()

Page 30: BDD approach with Selenium RC

There’re still some questions

How to locate elements?

How to avoid duplicates?

How to storevalues? How to use

random data?

Page 31: BDD approach with Selenium RC

UI elements mapping. What for?

When I click on "//div[@id='some_div']/button[text()='Add']" button

When I click on "Add" button on "Home Page"

When I click on “Search" link

When I create “test.txt" file in “C:\\Temp” folder

When I create “test.txt" file in “%USERPROFILE%” folder

Which way is more reliable and informative?

Page 32: BDD approach with Selenium RC

UI elements mapping. How?

Page

Title

Name

Item

Alias

Locator

Examples:Ini file

XML file

Page 33: BDD approach with Selenium RC

UI Mapping. Trivial case

Text instruction:

When I click on the “Updates” link

Actual code:

selenium.click( “link=Updates” );

Page 34: BDD approach with Selenium RC

UI Mapping. Specific page

When I click on the “Apply Button” on the “Links Page”

Will look into this section

Explicit Selenium calls

Similar elements on different

pages

Will take this locator

Will click here:

selenium.click(“links_apply_btn”)

Page 35: BDD approach with Selenium RC

UI Mapping. Current page

Explicit Selenium calls

Similar elements on different

pages

When I click on the “Apply Button” element

Will find section with matching header

Will take this locator

Will click here:

selenium.click(“links_apply_btn”)

Will read current page title

Page 36: BDD approach with Selenium RC

Main challenges

Different keywords can do the same things

Examples:

When /click on the “(.*)” link/

When /click on “(.*)” link/

When /click on (.*) link/

Page 37: BDD approach with Selenium RC

Main challenges

Resolution:

Standards & Naming Conventions!!!

Trainings & Review!!!

Page 38: BDD approach with Selenium RC

Main challenges

After that:

Examples:

When /click on the “(.*)” link/ #Valid as conforms the rules

When /click on “(.*)” link/ #Invalid. Violates Rule #1

Rule #1: each field, element, page name should have “the” article

Page 39: BDD approach with Selenium RC

Main challenges

Too many keywords Resolution: organize keywords vocabulary

Page 40: BDD approach with Selenium RC

Main challenges

Data exchange between steps

Resolution: use external hash for data storage

“My Folder” field now contains actual path

Page 41: BDD approach with Selenium RC

Main challenges

Random data generation Resolution:

Is necessary?

Is needed?

Use explicit value

Do not pass a value

Pass alias

Yes

Yes

No

No

Page 42: BDD approach with Selenium RC

Questions?