Selenium, Ruby, Cucumber framework in Page Object model with Allure as reporting
Teber-Ruby is a Page Object Model (POM) framework for selenium automation with ruby Cucumber
. In order to make the testing faster used ‘parallel_tests’ gem to run multiple threads to run the tests at the same time. For reporting ‘allure’ is being adapted.
gem install bundler
bundle install
For a simple run of all the feature files in normal mode, try
cucumber
To Run the tests in parallel mode for the available feature files, try
parallel_cucumber features/
To Run the tests in parallel mode for the available feature files along with tags, try
parallel_cucumber features/ -o "-t "@scenario_001""
To Run the tests in parallel mode for the available feature files along with tags and environment variables, try
parallel_cucumber features/ -o "-t "@scenario_001" MODE=headless"
This will run the tests in headless mode
allure serve reports/allure
Currently supports for Chrome browser, but handled in such a way that framework can be easily configured to support multiple browsers. I used webdriver manager to resolve the driver-browser compatibility issues, use the same to add your designated browser (firefox, edge, ie, safari etc.,).
Initiate the driver class inside support package mutiple times with different WebDriver objects. You can execute the actions in multiple browsers at the same time by executing actions against each driver object.
For better illustration on the testcases, allure reports has been integrated. Allure reports can also be integrated with jenkins to get a dashboard view. Apart from allure, cucumber’s default reporting such as html, pretty, progress, rerun files has been added to the reports/
folder.
Get any of the linux with ruby docker image as the slaves in jenkins and use the same for executing the UI automation with this framework (Sample docker image - https://hub.docker.com/_/ruby
). From the jenkins bash Execute the following to get the testcases to run,
#!/bin/bash -l
rvm list
ls
cd <path_to_the_project>
bundle install
cucumber #or custom commands
for complete guide to setup in linux check Cloud Setup for Ruby
In Jenkins pipeline, try to add the following snippet to execute the tests,
pipeline {
agent { docker { image 'ruby' } }
stages {
stage('build') {
steps {
sh 'cd project/'
sh 'gem install bundler'
sh 'bundle install'
sh 'cucumber' # or custom methods
}
}
}
}
In global-data/global.yml
file, if the mode is headless
, the chrome will be initialized in headless mode which can be used to run in server. Screenshots will be added even if the browser runs in headless mode.
Locators
module
module Locators
# Add a class for each page and add the locators
end
Locators
module.
module Locators
class TestPage
# All the Locators in the initialize block need to be declared here for read write permission.
attr_accessor :TEST_LOCATOR
def initialize
# Locators can be declared here by mentioning {how?(xpath,css,id) and what?(identifier)}
@TEST_LOCATOR = Locator.new(:id, "")
end
# Dynamic locators can be declared here as a seperate method (This method doesnot need to be declared with attr_accessor)
def TEST_DYNAMIC_LOCATOR(variable)
@TEST_DYNAMIC_LOCATOR = Locator.new(:xpath,"//*[text()=#{variable}]")
end
end
end
home page
then the locator file name should be home_page.rb
inside locators
folder and the class name should be HomePage
inside Locators
module.Pages
module.
module Pages
# add the page class here
end
Pages
module and each page class should inherit the locators class of the same page
module Pages
class TestPage < Locators::TestPage
def initialize()
super()
end
def test_method(attribute_text)
puts "#{attribute_text}"
end
end
end
pages
folder with the class name same as the web page name.home page
then the pages file name should be home_page.rb
inside pages
folder and the class name should be HomePage
inside Pages
module.
Feature: Sample project setup
To get to know the sample cucumber project
Scenario: This test will pass
Given true eql true
When false eql false
Then string eql string
@before_feature @test_feature
Feature: Sample project setup
To get to know about the basic flows in this framework
@before_scenario @test_id=001
Scenario: This test will pass
Given true eql true
When false eql false
Then string eql string
Now declare the feature steps inside the step definitions file, the name of the step definition file should be same as the feature file.
In the step definitions file, initially declare the before and after action block.
Before do
puts "before each "
end
After do |s|
puts "after each "
end
Before
and After
for each specific tags that we defined in the feature file.
Before('@test_tag') do
puts "before each "
end
After('@test_tag') do |s|
puts "after each "
end
Given("true eql true") do
expect(true).to eql true
end
When("false eql false") do
expect(false).to eql false
end
Then("string eql string") do
expect("test").to eql "test"
end
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
Please read CONTRIBUTING.md for details on code of conduct, and the process for submitting pull requests.
This project is licensed under the GNU GPL-3.0 License - see the LICENSE file for details