Skip to content

Commit

Permalink
Merge pull request #14 from prashanth-sams/delete_run
Browse files Browse the repository at this point in the history
delete previous test runs, warning message on invalid config
  • Loading branch information
prashanth-sams authored Mar 18, 2020
2 parents 3a7775e + b9f2ce1 commit 7e3956c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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: [email protected]
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
Expand Down
39 changes: 37 additions & 2 deletions lib/testrail-rspec/update-testrails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def initialize(scenario)
end

setup_testrail_client
config_validator if $config_validator.nil?
end

def upload_result
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/testrail-rspec/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TestrailRspec
VERSION = '0.1.5'.freeze
VERSION = '0.1.6'.freeze
end
1 change: 1 addition & 0 deletions testrail_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ testrail:
user: your_username
password: your_password
run_id: <run_id>
clean_testrun: false
project_id: <project_id>
suite_id: <suite_id>

0 comments on commit 7e3956c

Please sign in to comment.