Module: Itriagetestrail::TestCases

Included in:
TestRailInterface
Defined in:
lib/itriagetestrail/testrail_objects/test_cases.rb

Instance Method Summary collapse

Instance Method Details

#add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id) ⇒ Object

add the test case if it doesn’t exist



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/itriagetestrail/testrail_objects/test_cases.rb', line 39

def add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
  body = {
    title: scenario_title,
    custom_external_case_id: external_id,
    custom_steps: scenario_steps,
    type_id: 3
  }

  @client.send_post("add_case/#{section_id}", body)

  # refresh test case ids
  testrail_ids false
end

#app_version_labelObject



53
54
55
56
57
58
59
# File 'lib/itriagetestrail/testrail_objects/test_cases.rb', line 53

def app_version_label
  if @app_version.nil? || @app_version.empty?
    ''
  else
    "App Version:#{@app_version}"
  end
end

#associate_result(external_id) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/itriagetestrail/testrail_objects/test_cases.rb', line 27

def associate_result(external_id)
  test_case_id = testrail_test_case_id(external_id)
  # store the test case id with the local result
  @results[:results].each do |result|
    next unless result[:external_id] == external_id
    @external_results[:results] << { case_id: test_case_id,
                                     status_id: result['status_id'],
                                     comment: result['comment'] }
  end
end

#jenkins_build_labelObject



61
62
63
64
65
66
67
# File 'lib/itriagetestrail/testrail_objects/test_cases.rb', line 61

def jenkins_build_label
  if @jenkins_build .nil? || @jenkins_build.empty?
    ''
  else
    " Jenkins Build:#{@jenkins_build}"
  end
end

#test_nameObject



73
74
75
76
77
78
79
80
81
# File 'lib/itriagetestrail/testrail_objects/test_cases.rb', line 73

def test_name
  ci_label = "#{app_version_label}#{jenkins_build_label}"

  if ci_label.dup.strip.empty?
    'Regression' + time_zone_label
  else
    ci_label + time_zone_label
  end
end

#testrail_ids(read_cache = true) ⇒ Object

TestRail Cases



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/itriagetestrail/testrail_objects/test_cases.rb', line 6

def testrail_ids(read_cache = true)
  case @suite_mode
  when 2, 3
    @test_cases = @client.send_get("get_cases/#{@project_id}&suite_id=#{@suite_id}&type_id=3", read_cache)
  else
    @test_cases = @client.send_get("get_cases/#{@project_id}&type_id=3", read_cache)
  end

  @test_case_ids = []

  @test_cases.each { |test_case| @test_case_ids << test_case['id'] }
end

#testrail_test_case_id(external_id) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/itriagetestrail/testrail_objects/test_cases.rb', line 19

def testrail_test_case_id(external_id)
  res = -1
  @test_cases.each do |test_case|
    res = test_case['id'] if test_case['custom_external_case_id'] == external_id
  end
  res
end

#time_zone_labelObject



69
70
71
# File 'lib/itriagetestrail/testrail_objects/test_cases.rb', line 69

def time_zone_label
  ' (' + @time_zone.now.strftime('%-I:%M %p') + ')'
end