New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cucumber_helper

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cucumber_helper

  • 0.0.8
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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

  1. Clone this repository
git clone https://bitbucket.org/mid-kelola-indonesia/cucumber-helper.git

# or using ssh
git clone git@bitbucket.org:mid-kelola-indonesia/cucumber-helper.git
  1. 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 # cucumber_helper-0.0.1.gem should be written as in File output in gem build

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

  1. Go to your test automation Repo and open the Gemfile (eg: Nemo) using you file editor and add this line:
# Gemfile 

gem 'cucumber_helper', git: 'https://bitbucket.org/mid-kelola-indonesia/cucumber-helper.git'
# or by tag/branch
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

  1. Import the library in env.rb
# env.rb

# for API
require 'cucumber_helper/api' 
# or for WEB 
require 'cucumber_helper/web'

# if you want to add general code for setup env like setup browser
# you need to add this
require 'cucumber_helper/support'
.....
# setup browser using cucumber_helper support module, put after set SHORT_TIMEOUT and DEFAULT_TIMEOUT
path = create_report_path
create_browser path
config_rspec
.....
  1. Add helper function in hooks.rb
# hooks.rb
Before do |scenario|
  ....
  @tags = scn_tags(scenario)
  ....
end

After do |scenario|
  .....
  capture_screenshot(scenario)
  handle_continue(scenario)
  delete_downloaded_file
  .....
end
  1. If using docker make sure using the latest version by using bundle update command after bundle install
# docker.sh

....
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
# hooks.rb
Before do |scenario|
  @tags = scn_tags(scenario)
end

After do |scenario|
  # .... Your Automation Script .....
  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:

# your_step.rb
When('user save the data variable to {string}') do |name|
  save_variable(name, @data)
end

# your_feature.feature
Scenario: Scenario 1
.....

# to save as Global Variable
When user save the data variable to "$test"
# it will save as instance variable
When user save the data variable to "test"
.....
Then user validate "test" data

Scenario: Scenario 2
.....
# the $test is variable from Scenario 1
Then user validate "$test" data
....


  • production?

    basically it check for @production tag and the base_url contains mekari.com

# your_step.rb
if production? 
  # do something...
else
  # do something else ...
end

  • TestDataHelper class

    It help you load your data in yml format if you have different data in staging or production. e.g you have different note id in staging and production to test. by default, this helper will load file: features/data/test/test_data.yml in variable @test_data

# test_data.yaml file:
note_id:
  staging: 11
  production: 5

# your_step.rb
When('User open note of employee') do
  # if need to declare @enviroment to 'staging' or 'production'
  # in this case, if it run on staging, @test_data['note_id'] = 11,
  # if it run in production @test_data['note_id'] = 5
  @pages.employee_page.notes_id.find { |x| x.text == @test_data['note_id'] }.click
  waiting_for_page_ready
end

  • DataHelper class

    used for load email / password, generally it used to handle stored credentials

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

  • pretty_json(response)

    log your json pretty format

log pretty_json(@response)
# >> will write in log file:
# { 
#   "message" : "message .....",
# }
# instead : { "message" : "message ...." }

WEB Automation Helper

Many general function are included in this gem

# you can open file in ./lib/cucumber_helper/web/helpers.rb
# this include:
waiting_for_page_ready
short_wait
wait_for_download
waiting_for_xhr_complete
adjust_comma_number
parse_rp
# and many more ...

  • TableSection class helper

    This is to help automation of table in an page example your page have table:

nameDescriptionPackage
Benefit AHR DeptPackage A
Benefit BQualityPackage B

the functions are:

click_header(name)
# argument:
# - name: Header name in column, example: name, Description, Package
# - exact_text: true or false
# - sort_arrow: true or false
# - sort_path: css path of the element
# example: @pages.employee_page.employee_table.click_header('Employee name')
#          @pages.employee_page.employee_table.click_header('Employee name', sort_arrow: true) # if using sort arrow to sort table

data_column(name)
# argument:
# - name: Header name in column, example: name, Description, Package
# - exact_text: true or false

data_row_as_text(row_number)
# argument:
# - row_number: row number

data_column_as_text(name)
# argument:
# - name: Header name in column, example: name, Description, Package
# - exact_text: true or false

data_column(name)
# argument:
# - name: Header name in column, example: name, Description, Package
# - exact_text: true or false

click_data_column(col_name, text)
# argument:
# - col_name: Header name in column, example: name, Description, Package
# - text: Cell text in table example: Quality, Package A
# - exact_text: true or false
# your_page_class.rb
class BenefitPage < SitePrism::Page
  .....
  # TableSection is in our Gem, so no need to declare it in our repo
  # do rather than defining each column, we only need to define the table once
  # if you want to add more like button or something you can do:
  # section :table_benefit, TableSection, '#benefitTable' do
  #   elements :btn_action, '#actionButton'
  # end    
  section :table_benefit, TableSection, '#benefitTable'
  .....
end

# your_step.rb
....

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

FAQs

Package last updated on 23 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc