Teber-Ruby
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.
Supports
- Multiple browser automation
- Multi browser automation
- Allure reports
- Jenkins Integration
- Modes of run via CLI command
- Headless run
- Docker Execution
- Failed Screenshots
- Testdata driven tests
- Multi Thread run
Setup
- Clone this repository
- Navigate to the cloned folder
- Install bundler using
gem install bundler
- Install the dependencies by
bundle install
To Run the tests
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
To open allure results
allure serve reports/allure
Multiple Browser
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.,).
Multi Browser
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.
Reports
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.
Jenkins Integration with Docker images
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
}
}
}
}
Headless Run
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.
Break down into end to end tests
Adding Locators to the project
- Add Locators to the that are going to be used inside the project inside the
Locators
modulemodule Locators # Add a class for each page and add the locators end
- For each page add a new class inside the
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
- Ideally each web page should have a new file inside locators folder (with the same name as the web page) and all the locators inside a web page has to be declared inside a page class(Class name also should be same as the web page name).
- If the web page name is
home page
then the locator file name should behome_page.rb
insidelocators
folder and the class name should beHomePage
insideLocators
module.
- If the web page name is
Adding page methods to the project
- Add page specific methods inside the
Pages
module.
module Pages
# add the page class here
end
- For each page add a new class inside
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
- Ideally each web page should have a new page file inside
pages
folder with the class name same as the web page name.- If the web page name is
home page
then the pages file name should behome_page.rb
insidepages
folder and the class name should beHomePage
insidePages
module.
- If the web page name is
Creating a new feature file in the project
- Define the tests in the feature file in gherkin language.
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
- Ideally tags has to be used for each feature and each scenario to identify the test cases in the unique way.
@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
- Cucumber allows us to use in an extensive way. So we can define
Before
andAfter
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
- Define the steps after the before/after block.
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
Built With
- Cucumber - Automation core framework
- Parallel_tests - To run automation parallely at the same time.
- Allure Cucumber - For Detailed reporting.
- Selenium - For web browser automation.
Contributing
- Clone the repo!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Create a pull request.
Please read CONTRIBUTING.md for details on code of conduct, and the process for submitting pull requests.
Authors
License
This project is licensed under the GNU GPL-3.0 License - see the LICENSE file for details
Acknowledgments
- To all the open source contributors whose code has been referred in this project.