diff --git a/README.md b/README.md index 099acad..5db7beb 100755 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ - [x] Update test results in the existing test run - [x] Create dynamic test run and update test results in it - [x] Update multi-testrail cases from a single automation scenario +- [x] Delete/clean all the existing test runs in a project's suite before test run - [x] Static status comments on all the scenarios - [x] Support for RSpec `shared examples` @@ -137,6 +138,18 @@ end ``` Here, `project_id` and `suite_id` are the dynamically generated id from your testrail account; `run_id` is optional in this case. +5. To delete all test-runs before execution, + ```yaml + testrail: + url: https://your_url.testrail.io/ + user: your@email.com + password: ****** + clean_testrun: true + project_id: 10 + suite_id: 110 + ``` + Set, `clean_testrun: false` if you don't want to clean the existing test runs; but this keyword is optional. + #### Hooks Update the results through `Hooks` on end of each test diff --git a/lib/testrail-rspec/update-testrails.rb b/lib/testrail-rspec/update-testrails.rb index 7d07500..712d18e 100644 --- a/lib/testrail-rspec/update-testrails.rb +++ b/lib/testrail-rspec/update-testrails.rb @@ -15,6 +15,7 @@ def initialize(scenario) end setup_testrail_client + config_validator if $config_validator.nil? end def upload_result @@ -46,12 +47,13 @@ def upload_result @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? + @run_id = @@run_id = client.create_test_run("add_run/#{@config['project_id']}", {"suite_id": @config['suite_id']}) if @run_id.nil? case_list.map do |case_id| + check_avail(:case_id, case_id) response = client.send_post( "add_result_for_case/#{@run_id}/#{case_id}", - { status_id: status_id, comment: message } + {status_id: status_id, comment: message} ) end @@ -70,6 +72,17 @@ def setup_testrail_client @client.password = @config['password'] end + def config_validator + config_hash = {:project_id => @config['project_id'], :suite_id => @config['suite_id'], :run_id => @config['run_id']} + config_hash.map do |key, value| + next if value.nil? + check_avail(key, value) + end + + cleaner if [@config['project_id'], @config['clean_testrun'], @config['run_id'].nil?].all? + $config_validator = true + end + def get_status_id(status) case status when :passed @@ -88,5 +101,27 @@ def get_status_id(status) raise 'unexpected scenario status passed' end end + + def cleaner + test_run_list = client.send_get("get_runs/#{@config['project_id']}") + test_run_list.map do |list| + client.send_post("delete_run/#{list['id']}", {"suite_id": @config['suite_id']}) + end + end + + def check_avail(label, id) + case label + when :project_id + warn("\n###################### \ninvalid #project_id: #{id} \n######################") if client.send_get("get_project/#{id}").nil? + when :suite_id + warn("\n###################### \ninvalid #suite_id: #{id} \n######################") if client.send_get("get_suite/#{id}").nil? + when :run_id + warn("\n###################### \ninvalid #run_id: #{id} \n######################") if client.send_get("get_run/#{id}").nil? + when :case_id + warn("\n###################### \ninvalid #case_id: #{id} \n######################") if client.send_get("get_case/#{id}").nil? + else + p "no config available" + end + end end end diff --git a/lib/testrail-rspec/version.rb b/lib/testrail-rspec/version.rb index d59cd00..bb9a54f 100644 --- a/lib/testrail-rspec/version.rb +++ b/lib/testrail-rspec/version.rb @@ -1,3 +1,3 @@ module TestrailRspec - VERSION = '0.1.5'.freeze + VERSION = '0.1.6'.freeze end \ No newline at end of file diff --git a/testrail_config.yml b/testrail_config.yml index f046b7f..4c0b8ff 100644 --- a/testrail_config.yml +++ b/testrail_config.yml @@ -3,5 +3,6 @@ testrail: user: your_username password: your_password run_id: + clean_testrun: false project_id: suite_id: \ No newline at end of file