a universal automation framework based on bdd cucumber and ruby on rails - pham quoc anh
TRANSCRIPT
1
A UNIVERSAL AUTOMATION
FRAMEWORK BASED ON BDD
CUCUMBER AND RUBY ON RAILS
SPEAKER: Anh Pham
INFOdation Viet Nam
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
3
Behavior Driven Development
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
5
Automation Testing With BDD Cucumber
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
7
BDD/CUCUMBER – PROS & CONS
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.
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.
10
OUR SOLUTIONS – A Universal
Automation Framework Based BDD
Cucumber – Ruby on Rails - Appium
…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
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
…Web and Web Services Testing
13
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
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
…Mobile Testing
16
17
So, What Does This Universal Automation
Framework Resolve?
Universal Automation Framework
18
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.
20
Now, Let’s See The Architecture
Packaging Automation to RUBYGEM
Universal Automation Framework
21
22
Finally, It’s Universal...
Universal Automation Framework
23
Login to System
Define Features, Scenarios
Pull Code
Commit & Push code
Universal Automation Framework
24
Universal Automation Framework
25
Universal Automation Framework
26
27
Summary
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
29
Future Work
Future Work
Jira Integration
Confluence IntegrationRequirement Management
30
Q & A
31
© 2014 HCMC Software Testing Club
THANK YOU