RoboTest
Robotest is a Page Object Model (POM) framework for selenium automation with ruby 'rspec'. In order to make the testing faster, robotest included the 'parallel_tests' gem to make multiple process testing at the same time. For reporting 'allure' is being adapted.
Getting Started
For faster onboarding sample project has been added to this gem. Just try
robotest example
to get a sample project loaded in to your current directry.
Note: This will work for linux and mac machines. For windows machines try to copy paste the sample project folder Full_Suite
from the installation directory.
Prerequisites
- Install Sublime, Atom, Code or Xcode based on your preference
- Install homebrew from http://brew.sh/
- Install ruby and rvm with
brew install ruby
andcurl -sSL https://get.rvm.io | bash -s stable --ruby
- Install chrome driver using
brew cask install chromedriver
Note: The above all is for linux and mac machines. For windows machines the installation may vary.
Installing
Install using gem install
command
gem install robotest
or
- Clone this project to your local.
- Inside the cloned project directory do
bash build.sh
Running the tests
At first you need to describe your tests in the spec folder with .rb extention. Then need to add your spec file directory in the yaml file as given in the example file. Now run the tests with the following command
robotest <Directory to your yaml file>
In the example project you can try
robotest yaml/test.yml
in the directory where the example project is placed.
To run the tests in parallel mode using parallel_tests
try running
robotest yaml/test_parallel.yml
in the directory where the example project is placed.
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
3. 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
2. 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(driver)
super()
@driver = driver
end
def test_method(attribute_text)
puts "#{attribute_text}"
end
end end
3. 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 spec file in the project**
1. Require the spec_helper file.
require 'spec_helper'
2. Describe the test case with a unique name.
describe "Testing" do
end
3. Declare the before all, before each, after all, after each if needed inside the describe. *check out the spec_helper file to have a global before and after blocks*
before(:all) do # Initialize all the constants here. # Code which has to be run before starting all the test cases are placed here. end
before(:each) do # any specfic steps that needs to be done before each testcase can be done here # Example : Moving to the home page after all the test case will be an idle one. end
after(:all) do # Steps that is to be run after all the test cases are done can be given here. # Usual steps will be quiting all the drivers, but that is handled in the spec_helper.rb so any other specific steps other than quit can be given here. end
after(:each) do |e| # any specfic steps that needs to be done after each testcase can be done here # Usually taking screen shots after each test case when there is a failure is done here, but that is covered in spec_helper.rb # Any other steps than taking screenshot can be given here. end
4. Now declare your tests after the before and after block within the descibe block.
it 'Test 1',:tag_string => "tag_name", :tag_boolean => true, :tag_number => '001' do |e| #use e.step to have the reporting in the allure. e.step "test reporting 1" do expect(true).to eql true end # Best practice is to have more e.step and have all the code inside any of the e.step so that any failure happend in the test case will be reported with screenshots. end
*For more check the sample files after doing `robotest example`*
## Built With
* [Rspec](https://rubygems.org/gems/rspec/versions/3.4.0) - Automation core framework
* [Parallel_tests](https://rubygems.org/gems/parallel_tests) - To run automation parallely at the same time.
* [Allure Rspec](https://rubygems.org/gems/allure-rspec) - For Detailed reporting.
* [Selenium](https://www.seleniumhq.org/) - For web browser automation.
## Contributing
1. Fork it!
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. Submit a pull request :D
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on code of conduct, and the process for submitting pull requests.
## Authors
* **[Naresh Sekar](https://github.com/nareshnavinash)**
## License
This project is licensed under the GNU GPL-3.0 License - see the [LICENSE](LICENSE) file for details
## Acknowledgments
* To all the open source contributors whose code has been used in this project.