diff --git a/Gemfile b/Gemfile index 03a4c0e..cd8aa9e 100755 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,3 @@ source 'https://rubygems.org' -gem 'rspec' -gem 'capybara' -gem 'selenium-webdriver' -gem 'site_prism' -gem "rake" -gem 'byebug' -gem 'testrail-rspec' \ No newline at end of file +gemspec \ No newline at end of file diff --git a/README.md b/README.md index 17cb2fb..9253409 100755 --- a/README.md +++ b/README.md @@ -2,21 +2,39 @@ [![Gem Version](https://badge.fury.io/rb/testrail-rspec.svg)](http://badge.fury.io/rb/testrail-rspec) > Sync `Rspec` test results with your `testrail` suite. Discover an example with Capybara in this gem source. -**Install gem file** -``` +### Features +- [x] Update test results in the existing test run +- [x] Create dynamic test run and update test results in it + +## Installation + +Add this line to your application's Gemfile: +```ruby gem 'testrail-rspec' ``` +And then execute: +```bash +$ bundle +``` + +Or install it yourself as: +```bash +$ gem install testrail-rspec +``` + **Import the library in your `spec_helper.rb` file** ``` require 'testrail-rspec' ``` -**Sync Case ID in your RSpec scenario** +## #Usage outline -Prefix TestRail Case ID on start of your rspec scenario; say, `C860` +#### Sync Case ID -``` +Prefix TestRail Case ID on start of your rspec scenario; say, `C845` + +```ruby describe 'Verify Google Home Page' do scenario 'C845 verify the Google home page' do @@ -27,10 +45,6 @@ Prefix TestRail Case ID on start of your rspec scenario; say, `C860` expect(page).to have_content('Goo gle') end - scenario 'C850 verify the Google home page to be pending' do - pending - end - scenario 'C853 verify the Google home page to skip' do skip "skipping this test" end @@ -38,12 +52,16 @@ Prefix TestRail Case ID on start of your rspec scenario; say, `C860` end ``` -**Config TestRail details** +#### TestRail details -- Create a testrail config file, `testrail_config.yml` in the project parent folder -- Fill up the testrail details on right hand side of the fields (`url`, `user`, `password`, and `run_id`); `run_id` is the dynamically generated id from your testrail account (say, `run_id: 111`) +Provide TestRail details by creating a config file, `testrail_config.yml` in the project parent folder -``` +> With existing `Test Run` + +- Add testrail details (`url`, `user`, `password`, and `run_id`) +- `run_id` is the dynamically generated id from your testrail account (say, `run_id: 111`) + +```yaml testrail: url: https://your_url.testrail.io/ user: your@email.com @@ -51,7 +69,24 @@ testrail: run_id: 111 ``` -**Update the results through `Hooks` on end of each test** +> Create dynamic `Test Run` and update results + +- Add testrail details following `project_id` and `suite_id` +- `project_id` and `suite_id` are the dynamically generated id from your testrail account +- `run_id` is optional here; you may (or) may not have it in this case + +```yaml +testrail: + url: https://your_url.testrail.io/ + user: your@email.com + password: ****** + project_id: 10 + suite_id: 110 +``` + +#### Hooks + +Update the results through `Hooks` on end of each test ``` config.after(:each) do |scenario| TestrailRSpec::UpdateTestRails.new(scenario).upload_result diff --git a/lib/testrail-rspec/api-client.rb b/lib/testrail-rspec/api-client.rb index a879a95..a0f4b6b 100644 --- a/lib/testrail-rspec/api-client.rb +++ b/lib/testrail-rspec/api-client.rb @@ -62,6 +62,11 @@ def send_post(uri, data) _send_request('POST', uri, data) end + def create_test_run(uri, data) + @add_test = true + _send_request('POST', uri, data) + end + private def _send_request(method, uri, data) url = URI.parse(@url + uri) @@ -83,6 +88,7 @@ def _send_request(method, uri, data) if response.body && !response.body.empty? result = JSON.parse(response.body) + return result['id'] if @add_test else result = {} end diff --git a/lib/testrail-rspec/update-testrails.rb b/lib/testrail-rspec/update-testrails.rb index 4d826f4..e8a7aac 100644 --- a/lib/testrail-rspec/update-testrails.rb +++ b/lib/testrail-rspec/update-testrails.rb @@ -36,11 +36,13 @@ def upload_result message = "This test scenario was automated and passed successfully" end - run_id = @config['run_id'] + @run_id ||= @config['run_id'] + @run_id = @@run_id rescue @@run_id = nil unless @config['run_id'] + @run_id = @@run_id = client.create_test_run("add_run/#{@config['project_id']}", { "suite_id": @config['suite_id']}) if @run_id.nil? - if case_id && run_id + if case_id && @run_id response = client.send_post( - "add_result_for_case/#{run_id}/#{case_id}", + "add_result_for_case/#{@run_id}/#{case_id}", { status_id: status_id, comment: message } ) else diff --git a/lib/testrail-rspec/version.rb b/lib/testrail-rspec/version.rb index f6911ce..8dd0c32 100644 --- a/lib/testrail-rspec/version.rb +++ b/lib/testrail-rspec/version.rb @@ -1,3 +1,3 @@ module TestrailRspec - VERSION = '0.1.2'.freeze + VERSION = '0.1.3'.freeze end \ No newline at end of file diff --git a/spec/features/google_search_spec.rb b/spec/features/google_search_spec.rb index 5b34f6a..560a00b 100644 --- a/spec/features/google_search_spec.rb +++ b/spec/features/google_search_spec.rb @@ -13,11 +13,7 @@ expect(page).to have_content('Goo gle') end - scenario 'C850 verify the Google home page to be pending' do - pending - end - - scenario 'C853 verify the Google home page to skip' do + scenario 'C850 verify the Google home page to skip' do skip "skipping this test" end diff --git a/testrail-rspec.gemspec b/testrail-rspec.gemspec index cc9d3a8..7aafd75 100644 --- a/testrail-rspec.gemspec +++ b/testrail-rspec.gemspec @@ -1,11 +1,24 @@ +lib = File.expand_path("lib", __dir__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require "testrail-rspec/version" + Gem::Specification.new do |s| s.name = "testrail-rspec" - s.version = "0.1.2" - s.licenses = ['MIT'] - s.author = ["Prashanth Sams"] + s.version = TestrailRspec::VERSION + s.authors = ["Prashanth Sams"] s.email = ['sams.prashanth@gmail.com'] s.summary = "Sync Rspec test results with your testrail suite. Discover an example with Capybara in this gem source" + s.homepage = "https://github.com/prashanth-sams/testrail-rspec" + s.licenses = ['MIT'] s.files = ["lib/testrail-rspec.rb", "lib/testrail-rspec/api-client.rb", "lib/testrail-rspec/update-testrails.rb", "lib/testrail-rspec/version.rb"] s.require_paths = ["lib"] s.metadata = { "documentation_uri" => "https://www.rubydoc.info/github/prashanth-sams/testrail-rspec/master", "source_code_uri" => "https://github.com/prashanth-sams/testrail-rspec", "bug_tracker_uri" => "https://github.com/prashanth-sams/testrail-rspec/issues" } + + s.add_development_dependency "bundler" + s.add_development_dependency "rake" + s.add_development_dependency "rspec", "~> 3.0" + s.add_development_dependency "capybara", "~> 3.0" + s.add_development_dependency "selenium-webdriver", "~> 3.0" + s.add_development_dependency "site_prism", "~> 3.0" + s.add_development_dependency "byebug", "~> 11.0" end \ No newline at end of file diff --git a/testrail_config.yml b/testrail_config.yml index 534319c..f046b7f 100644 --- a/testrail_config.yml +++ b/testrail_config.yml @@ -2,4 +2,6 @@ testrail: url: https://your_url.testrail.io/ user: your_username password: your_password - run_id: your_run_id \ No newline at end of file + run_id: + project_id: + suite_id: \ No newline at end of file