Created
April 14, 2019 08:08
-
-
Save prashanth-sams/556419b249528d0e0e33cd62a282d9a3 to your computer and use it in GitHub Desktop.
Upload test results in TestRail app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative '../../features/helpers/testrail' | |
class ResultUploader | |
attr_accessor :client | |
def initialize(scenario) | |
@scenario = scenario | |
@config = TestrailConfig.new.config['testrail'] | |
setup_testrail_client | |
end | |
def upload_result | |
response = {} | |
case_id = @scenario.name.split(' ').first.scan(/\d+/).first rescue nil | |
status_id = get_status_id @scenario.status | |
run_id = @config['run_id'] | |
if case_id && run_id | |
response = client.send_post( | |
"add_result_for_case/#{run_id}/#{case_id}", | |
{ status_id: status_id } | |
) | |
else | |
raise 'unable to get case id or run id' | |
end | |
response | |
end | |
def fetch_status_ids | |
client.send_get('get_statuses') | |
end | |
private | |
def setup_testrail_client | |
@client = TestRail::APIClient.new(@config['url']) | |
@client.user = @config['user'] | |
@client.password = @config['password'] | |
end | |
def get_status_id(status) | |
case status | |
when :passed | |
1 | |
when :blocked | |
2 | |
when :untested | |
3 | |
when :retest | |
4 | |
when :failed | |
5 | |
when :undefined | |
raise 'missing step definition' | |
else | |
raise 'unexpected scenario status passed' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment