项目作者: nareshnavinash

项目描述 :
Selenium, Ruby, Cucumber framework in Page Object model with Allure as reporting
高级语言: Ruby
项目地址: git://github.com/nareshnavinash/Teber-Ruby.git
创建时间: 2019-11-28T13:35:08Z
项目社区:https://github.com/nareshnavinash/Teber-Ruby

开源协议:GNU General Public License v3.0

下载


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

  • 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

  1. cucumber

To Run the tests in parallel mode for the available feature files, try

  1. parallel_cucumber features/

To Run the tests in parallel mode for the available feature files along with tags, try

  1. 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

  1. parallel_cucumber features/ -o "-t "@scenario_001" MODE=headless"

This will run the tests in headless mode

To open allure results

  1. 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,

  1. #!/bin/bash -l
  2. rvm list
  3. ls
  4. cd <path_to_the_project>
  5. bundle install
  6. 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,

  1. pipeline {
  2. agent { docker { image 'ruby' } }
  3. stages {
  4. stage('build') {
  5. steps {
  6. sh 'cd project/'
  7. sh 'gem install bundler'
  8. sh 'bundle install'
  9. sh 'cucumber' # or custom methods
  10. }
  11. }
  12. }
  13. }

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
    1. module Locators
    2. # Add a class for each page and add the locators
    3. end
  2. For each page add a new class inside the Locators module.
  1. module Locators
  2. class TestPage
  3. # All the Locators in the initialize block need to be declared here for read write permission.
  4. attr_accessor :TEST_LOCATOR
  5. def initialize
  6. # Locators can be declared here by mentioning {how?(xpath,css,id) and what?(identifier)}
  7. @TEST_LOCATOR = Locator.new(:id, "")
  8. end
  9. # Dynamic locators can be declared here as a seperate method (This method doesnot need to be declared with attr_accessor)
  10. def TEST_DYNAMIC_LOCATOR(variable)
  11. @TEST_DYNAMIC_LOCATOR = Locator.new(:xpath,"//*[text()=#{variable}]")
  12. end
  13. end
  14. 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.
  1. module Pages
  2. # add the page class here
  3. 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
  1. module Pages
  2. class TestPage < Locators::TestPage
  3. def initialize()
  4. super()
  5. end
  6. def test_method(attribute_text)
  7. puts "#{attribute_text}"
  8. end
  9. end
  10. 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.
  1. Feature: Sample project setup
  2. To get to know the sample cucumber project
  3. Scenario: This test will pass
  4. Given true eql true
  5. When false eql false
  6. 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.
  1. @before_feature @test_feature
  2. Feature: Sample project setup
  3. To get to know about the basic flows in this framework
  4. @before_scenario @test_id=001
  5. Scenario: This test will pass
  6. Given true eql true
  7. When false eql false
  8. 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.

  1. Before do
  2. puts "before each "
  3. end
  4. After do |s|
  5. puts "after each "
  6. 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.
  1. Before('@test_tag') do
  2. puts "before each "
  3. end
  4. After('@test_tag') do |s|
  5. puts "after each "
  6. end
  1. Define the steps after the before/after block.
  1. Given("true eql true") do
  2. expect(true).to eql true
  3. end
  4. When("false eql false") do
  5. expect(false).to eql false
  6. end
  7. Then("string eql string") do
  8. expect("test").to eql "test"
  9. 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

  • To all the open source contributors whose code has been referred in this project.