Cucumber Helper for Automation
You can install this gem locally directly by clone this repo or using bundle.
by using this we don't need to handle per-repo if there is code changes/update, instead we only update this gem.
Local Installation
Build Gem from repo
- Clone this repository
git clone https://bitbucket.org/mid-kelola-indonesia/cucumber-helper.git
git clone git@bitbucket.org:mid-kelola-indonesia/cucumber-helper.git
- Go to the repo root folder and build and install the gem
cd cucumber-helper
gem build cucumber_helper.gemspec
gem install ./cucumber_helper-0.0.1.gem
Using specific_install gem
gem install specific_install
gem specific_install https://bitbucket.org/mid-kelola-indonesia/cucumber-helper.git
Integrate with Your Automation Repo
- Go to your test automation Repo and open the Gemfile (eg: Nemo) using you file editor and add this line:
gem 'cucumber_helper', git: 'https://bitbucket.org/mid-kelola-indonesia/cucumber-helper.git'
gem 'cucumber_helper', git: 'https://bitbucket.org/mid-kelola-indonesia/cucumber-helper.git', tag: '0.0.3'
gem 'cucumber_helper', git: 'https://bitbucket.org/mid-kelola-indonesia/cucumber-helper.git', branch: 'update-dalt'
Usage
- Import the library in env.rb
require 'cucumber_helper/api'
require 'cucumber_helper/web'
require 'cucumber_helper/support'
.....
path = create_report_path
create_browser path
config_rspec
.....
- Add helper function in hooks.rb
Before do |scenario|
....
@tags = scn_tags(scenario)
....
end
After do |scenario|
.....
capture_screenshot(scenario)
handle_continue(scenario)
delete_downloaded_file
.....
end
- If using docker make sure using the latest version by using bundle update command after bundle install
....
bundle install
bundle update cucumber_helper
....
Hooks Helper
- scn_tags(scenario) : get the scenario tags into array of tags
- capture_screenshot(scenario) : capture screenshot if the scenario failed
- handle_continue(scenario) : make scenario with @continue tag didn't delete its cookies/cache data
- delete_downloaded_file : delete all downloaded file at ./features/data/downloaded
Before do |scenario|
@tags = scn_tags(scenario)
end
After do |scenario|
capture_screenshot(scenario)
handle_continue(scenario)
delete_downloaded_file
end
Common Helper
This Repo contains many function that generally help to setup automation:
-
save_variable(name, value)
This to save the variable to instance variable or global variable.
Instance Variable is variable that can used in 1 scenario but different step.
Global Variable is variable that can used in different scenario and/or different step.
to save as global variable you need to add $
in front of variable name, ex: (save_variable('$test', 1234)
-> result in $test = 1234)
For instance variable no need to add @
but the result will have @
front of its name, ex: (save_variable('test', 1234)
-> result in @test = 1234)
example:
When('user save the data variable to {string}') do |name|
save_variable(name, @data)
end
Scenario: Scenario 1
.....
When user save the data variable to "$test"
When user save the data variable to "test"
.....
Then user validate "test" data
Scenario: Scenario 2
.....
Then user validate "$test" data
....
if production?
else
end
note_id:
staging: 11
production: 5
When('User open note of employee') do
@pages.employee_page.notes_id.find { |x| x.text == @test_data['note_id'] }.click
waiting_for_page_ready
end
When(/^user login using "(.*)" account$/) do |credential_type|
@data_login = DataHelper.new(@user_yml_data).prepare_credentials(credential_type)
@pages.login_page.input_email.set @data_login['email']
@pages.login_page.input_password.set @data_login['password']
end
API Automation Helper
log pretty_json(@response)
WEB Automation Helper
Many general function are included in this gem
waiting_for_page_ready
short_wait
wait_for_download
waiting_for_xhr_complete
adjust_comma_number
parse_rp
name | Description | Package |
---|
Benefit A | HR Dept | Package A |
Benefit B | Quality | Package B |
the functions are:
click_header(name)
data_column(name)
data_row_as_text(row_number)
data_column_as_text(name)
data_column(name)
click_data_column(col_name, text)
class BenefitPage < SitePrism::Page
.....
section :table_benefit, TableSection, '#benefitTable'
.....
end
....
Then(/^user successfully sort column "(.*)" benefit group table$/) do |column|
@pages.benefit_page.table_benefit.click_header(column)
waiting_for_page_ready
data = @pages.benefit_page.table_benefit.data_column_as_text(column)
expect(data).to eq data.sort
end