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.

License: GPL v3 Made with Ruby StackOverflow Contributions Welcome email me

alt text

Supports

Setup

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

  1. Add Locators to the that are going to be used inside the project inside the Locators module
    module Locators
     # Add a class for each page and add the locators
    end
    
  2. 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
  1. 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 be home_page.rb inside locators folder and the class name should be HomePage inside Locators module.

Adding page methods to the project

  1. Add page specific methods inside the Pages module.
module Pages
  # add the page class here
end
  1. 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
  1. 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 be home_page.rb inside pages folder and the class name should be HomePage inside Pages module.

Creating a new feature file in the project

  1. 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
  1. 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
  1. Now declare the feature steps inside the step definitions file, the name of the step definition file should be same as the feature file.

  2. 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
  1. Cucumber allows us to use in an extensive way. So we can define 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
  1. 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

Contributing

  1. Clone the repo!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. 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