A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

32
1 A UNIVERSAL AUTOMATION FRAMEWORK BASED ON BDD CUCUMBER AND RUBY ON RAILS SPEAKER: Anh Pham INFOdation Viet Nam

Transcript of A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Page 1: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

1

A UNIVERSAL AUTOMATION

FRAMEWORK BASED ON BDD

CUCUMBER AND RUBY ON RAILS

SPEAKER: Anh Pham

INFOdation Viet Nam

Page 2: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

AGENDA

2

Behavior-Driven Development

Automation Testing with Cucumber

BDD/Cucumber – Pros & Cons

Our Solutions: A Universal Test Automation

Framework

Demos

Future work

Q & A

Page 3: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

3

Behavior Driven Development

Page 4: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Behavior Driven Development

4

Given When Then

to set up the context where the scenario

happens

to interact with the system somehow

to check that the outcome of that interaction

was what we expected

An Example

Given I am on Amazon site

When I search for an Ipad

Then I should receive a list of Ipads

with various prices

Page 5: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

5

Automation Testing With BDD Cucumber

Page 6: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Given(/^I am on the "([^"]*)" page$/) do |page|

visit(page)

end

And /^I set text on "(.*?)" with "(.*?)"$/ do |object,

text|

fill_in object, :with => text

end

Automation Testing With BDD

Cucumber

6

Feature: Login to the system

As a User role

I want to login into system with provided

username and password

Scenario: Verify that user can login system

Given I am on “localhost” page

When I set text on “UserName” with “usertest”

And I set text on “Password” with “Passwordtest”

And I click on “login” button

Then I verify that I am on “Dashboard” page

Page 7: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

7

BDD/CUCUMBER – PROS & CONS

Page 8: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

BDD/CUCUMBER - PROS

8

BDD is FRIENDLY and UNDERSTANDABLE by non-

technical User.

It is OPEN-SOURCE and large community supported. Multiple programing languages supported: Java,Ruby

Groovy, etc. Support on MULTIPLE PLATFORM, OS and different

browsers.

Page 9: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

BDD/CUCUMBER - CONS

9

Lacking of tool for managing Features, Scenario, Report effectively.

Need to set-up Ruby environment on each User’s PC. IN- COMPATIBILITY among Gem versions.

Page 10: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

10

OUR SOLUTIONS – A Universal

Automation Framework Based BDD

Cucumber – Ruby on Rails - Appium

Page 11: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

…Web and Web Services Testing

11

Feature: Login to the system

As a user, I want to login the system when I provide username and password.

Scenario: Verify user can login to the system successfully with valid account

Given I am on Login Page

When I login into system with username "[email protected]" and password "123456"

Then I am on Dashboard page

When /^I login into system with username "(.*)" and password "(.*)"$/ do |username, password|

step %{I set text on "textbox_username" with "#{username}"}

step %{I set text on "textbox_password" with "#{password}"}

step %{I click on "button_login"}

end

default_browser: chrome

wait_time: 30

test_page_address: http://mymethods.dev-infodation.com/

textbox_username: {xpath_selector: '//*[@id="login_user"]'}

textbox_password: {xpath_selector: '//*[@id="login_pass"]'}

And /^I click on "([^\"]*)"$/ do |object|

execute_click(object)

end

When /^I send a POST XML request to "(.*?)" with the following file "(.*?)"$/ do |type, file|

file = Util.bind_with_dyn_vars(file)

url = Util.bind_with_dyn_vars($WS_URL)

# url=$WS_URL

data = File.read($test_data_dir + file)

$result=IFD_WS.send_XML_post_webservice(url,type,data)

end

def self.get_mysql_db_connection(schema)

begin

puts ("Connecting to database...");

data_source_schema = schema.downcase

return Mysql2::Client.new(host: $data_source_url, username: $data_source_username, password:

$data_source_password,database:data_source_schema);

rescue Exception => e

raise "Cannot connect to database [username: %s; password: %s, dbUrl: %s, dbName: %s] with error %s"

%

[$data_source_username, $data_source_password, $data_source_url,data_source_schema,

e.message]

end

end

Page 12: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Demo - Scenario Example

in BDD Format

12

Feature: Create a new user

In order to create new user account

As a User role

I want to create new user account

So that new user can be created successfully

Background: Clean up data before creating new user

Given I delete user email [email protected] if it is already existed on

database portal

Scenario: Create a new user

Given I am on Sign-up page

When I register new user name Anh Pham with email [email protected]

password 123456, password confirmation 123456

Then I verify user email [email protected] exists on database portal

Page 13: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

…Web and Web Services Testing

13

Page 14: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Feature: Login to Bedder App

As a User role

I want to login into system with provided username and password

Scenario: Verify that user can login to Bedder mobile application

Given I have App running with appium

When I login to Bedder app with username "[email protected]" and password "111111"

Then I am on Dashboard Page

…Mobile Testing

14

JSON WIRE OVER HTTP

When /^I login to Bedder app with username "(.*)" and password "(.*)"$/ do |username, password|

step %{I input text "#{username}" on "bedder_signin_username"}

step %{I wait for 1 seconds}

step %{I input text "#{password}" on "bedder_signin_password"}

step %{I wait for 1 seconds}

step %{I click on "bedder_signin_login_button"}

end

And /^I input text "(.*)" on "(.*)"$/ do |text,object|

execute_settext(object,text)

end

And /^I click on "(.*)"$/ do |object|

execute_click object

end

def execute_click element

found_element = find_object element

if found_element != nil

startTime = Time.new.to_i

begin

sleep(1)

currentTime= Time.new.to_i

end while (currentTime - startTime) < $_CONFIG['Wait Time']

# selenium.execute_script('mobile: scroll', found_element)

found_element.click

else

put_log "\nERROR: *** not found object: #{element}"

end

end

Page 15: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Demo - Scenario Example

in BDD Format

15

Feature: Login to Bedder App

As a User role

I want to login into system with provided username and password

Scenario: Verify that user can login to Bedder mobile

application

Given I have App running with appium

When I login to Bedder app with username

"[email protected]" and password "111111"

Then I am on Dashboard Page

Page 16: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

…Mobile Testing

16

Page 17: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

17

So, What Does This Universal Automation

Framework Resolve?

Page 18: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Universal Automation Framework

18

Page 19: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Universal Automation Framework

19

Simplify the installation process and automation scripting. Quick adaptability when GUI elements changed. Ability to version Features, Scenarios and Reports. System deployment and Test management system

integrated.

Page 20: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

20

Now, Let’s See The Architecture

Page 21: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Packaging Automation to RUBYGEM

Universal Automation Framework

21

Page 22: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

22

Finally, It’s Universal...

Page 23: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Universal Automation Framework

23

Login to System

Define Features, Scenarios

Pull Code

Commit & Push code

Page 24: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Universal Automation Framework

24

Page 25: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Universal Automation Framework

25

Page 26: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Universal Automation Framework

26

Page 27: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

27

Summary

Page 28: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Summary

Automation Framework (Core)

Portal System

Jan - 2016 Apr - 2016 Jun - 2016

Resource Allocation Man - days

Dev 1 70

Automation Tester 1 90

Total 2 160

28

Page 29: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

29

Future Work

Page 30: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Future Work

Jira Integration

Confluence IntegrationRequirement Management

30

Page 31: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

Q & A

31

Page 32: A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Pham Quoc Anh

© 2014 HCMC Software Testing Club

THANK YOU