Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. require_relative '../../features/helpers/testrail'
  2.  
  3. class ResultUploader
  4.  
  5. attr_accessor :client
  6.  
  7. def initialize(scenario)
  8. @scenario = scenario
  9. @config = TestrailConfig.new.config['testrail']
  10. setup_testrail_client
  11. end
  12.  
  13. def upload_result
  14.  
  15. response = {}
  16. case_id = @scenario.name.split(' ').first.scan(/\d+/).first rescue nil
  17. status_id = get_status_id @scenario.status
  18. run_id = @config['run_id']
  19.  
  20. if case_id && run_id
  21. response = client.send_post(
  22. "add_result_for_case/#{run_id}/#{case_id}",
  23. { status_id: status_id }
  24. )
  25. else
  26. raise 'unable to get case id or run id'
  27. end
  28.  
  29. response
  30. end
  31.  
  32. def fetch_status_ids
  33. client.send_get('get_statuses')
  34. end
  35.  
  36. private
  37.  
  38. def setup_testrail_client
  39. @client = TestRail::APIClient.new(@config['url'])
  40. @client.user = @config['user']
  41. @client.password = @config['password']
  42. end
  43.  
  44. def get_status_id(status)
  45. case status
  46. when :passed
  47. 1
  48. when :blocked
  49. 2
  50. when :untested
  51. 3
  52. when :retest
  53. 4
  54. when :failed
  55. 5
  56. when :undefined
  57. raise 'missing step definition'
  58. else
  59. raise 'unexpected scenario status passed'
  60. end
  61. end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement