diff --git a/README.md b/README.md index d926f17..099acad 100755 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ - [x] Create dynamic test run and update test results in it - [x] Update multi-testrail cases from a single automation scenario - [x] Static status comments on all the scenarios +- [x] Support for RSpec `shared examples` ## Installation @@ -30,7 +31,7 @@ $ gem install testrail-rspec require 'testrail-rspec' ``` -## #Usage outline +## Usage outline #### Update one case at a time Prefix TestRail Case ID on start of your rspec scenario; say, `C845` @@ -54,8 +55,7 @@ Prefix TestRail Case ID on start of your rspec scenario; say, `C845` ``` #### Update multi-cases at a time - -Prefix multiple TestRail Case IDs on start of your rspec scenario; say, `C845 C845 your scenario description` +Prefix multiple testrail case id(s) on start of your rspec scenario; say, `C845 C845 your scenario description` ```ruby describe 'Verify Google Home Page' do @@ -75,38 +75,68 @@ Prefix multiple TestRail Case IDs on start of your rspec scenario; say, `C845 C8 end ``` -#### TestRail details - -Provide TestRail details by creating a config file, `testrail_config.yml` in the project parent folder +#### Use context blocks to update cases +`Context blocks` with testrail case id(s) to make use of `Shared Examples` -> With existing `Test Run` +```ruby +shared_examples 'log in' do + it 'logs in' +end -- Add testrail details (`url`, `user`, `password`, and `run_id`) -- `run_id` is the dynamically generated id from your testrail account (say, `run_id: 111`) +shared_examples 'log out' do + it 'logs out' +end -```yaml -testrail: - url: https://your_url.testrail.io/ - user: your@email.com - password: ****** - run_id: 111 -``` +describe 'User login' do + context 'Regular user' do + let(:user) { create(:regular_user) } + context 'C845 single case' do + include_examples 'log in' + end -> Create dynamic `Test Run` and update results + context 'C847' do + include_examples 'log out' + end + end -- 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 + context 'Admin user' do + let(:user) { create(:admin_user) } + context 'C850 C853 multi cases' do + include_examples 'log in' + end -```yaml -testrail: - url: https://your_url.testrail.io/ - user: your@email.com - password: ****** - project_id: 10 - suite_id: 110 + context 'nothing to update in test-rail' do + include_examples 'log out' + end + end +end ``` +#### Configuration + +1. Create a config file, `testrail_config.yml` in the project's parent folder +2. Enter the testrail details based on demand +3. To execute tests against the existing `Test Run`, + ```yaml + testrail: + url: https://your_url.testrail.io/ + user: your@email.com + password: ****** + run_id: 111 + ``` + Here, `run_id` is the dynamically generated id from your testrail account (say, `run_id: 111`) + +4. To create a dynamic `Test Run` and to update results, + ```yaml + testrail: + url: https://your_url.testrail.io/ + user: your@email.com + password: ****** + project_id: 10 + suite_id: 110 + ``` + Here, `project_id` and `suite_id` are the dynamically generated id from your testrail account; `run_id` is optional in this case. + #### Hooks Update the results through `Hooks` on end of each test @@ -116,7 +146,7 @@ config.after(:each) do |scenario| end ``` -**Is there a demo available for this gem?** +**Is there any demo available for this gem?** Yes, you can use this `capybara` demo as an example, https://github.com/prashanth-sams/testrail-rspec diff --git a/Rakefile b/Rakefile index c6e4def..7a5b37e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,3 @@ task :test do |_task| - system "rspec spec/features/*_spec.rb" + system "rspec spec/features/google_search_spec.rb" end \ No newline at end of file diff --git a/lib/testrail-rspec/api-client.rb b/lib/testrail-rspec/api-client.rb index a0f4b6b..0387fa3 100644 --- a/lib/testrail-rspec/api-client.rb +++ b/lib/testrail-rspec/api-client.rb @@ -86,6 +86,8 @@ def _send_request(method, uri, data) end response = conn.request(request) + return if response.code == "400" + if response.body && !response.body.empty? result = JSON.parse(response.body) return result['id'] if @add_test diff --git a/lib/testrail-rspec/update-testrails.rb b/lib/testrail-rspec/update-testrails.rb index 48c7e53..7d07500 100644 --- a/lib/testrail-rspec/update-testrails.rb +++ b/lib/testrail-rspec/update-testrails.rb @@ -22,7 +22,7 @@ def upload_result response = {} case_list = [] - @scenario.metadata[:description].split(' ').map do |e| + @scenario.full_description.split(' ').map do |e| val = e.scan(/\d+/).first next if val.nil? case_list << val diff --git a/spec/features/google_search_spec.rb b/spec/features/google_search_spec.rb index e0b29eb..6fc6ac0 100644 --- a/spec/features/google_search_spec.rb +++ b/spec/features/google_search_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - feature 'Verify Google Home Page' do before do @app.google_home.load diff --git a/spec/features/shared_examples_spec.rb b/spec/features/shared_examples_spec.rb new file mode 100644 index 0000000..dcf3fe7 --- /dev/null +++ b/spec/features/shared_examples_spec.rb @@ -0,0 +1,33 @@ +shared_examples 'pass' do + it 'pass' do + expect(true).to be true + end +end + +shared_examples 'fail' do + it 'fail' do + expect(false).to be true + end +end + +describe 'Generic scenarios' do + context 'A regular user can' do + context 'C845' do + include_examples 'pass' + end + + context 'C847' do + include_examples 'fail' + end + end + + context 'Complex scenarios' do + context 'C850 C853 multi cases' do + include_examples 'pass' + end + + context 'Not going to update in test-rail' do + include_examples 'fail' + end + end +end \ No newline at end of file