Class: TestrailHelper::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/testrail_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
# File 'lib/testrail_helper.rb', line 10

def initialize(params = {})
  @client = TestRail::APIClient.new(params[:url])
  @client.user = params[:username]
  @client.password = params[:password]
  @client
end

Instance Method Details

#add_plan_entry(plan_id, params = {}) ⇒ Object



155
156
157
158
# File 'lib/testrail_helper.rb', line 155

def add_plan_entry(plan_id, params={})
  uri = "add_plan_entry/#{plan_id}"
  @client.send_post(uri, params)
end

#create_test_plan(project_id, params = {}) ⇒ Object



150
151
152
153
# File 'lib/testrail_helper.rb', line 150

def create_test_plan(project_id, params={})
  uri = "add_plan/#{project_id}"
  @client.send_post(uri, params)
end

#filter_by_fields_and(list, params = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/testrail_helper.rb', line 46

def filter_by_fields_and(list, params={})
  @master_list = list
  @temp_list = []
  h = params.map
  h.each do |par|
    puts par
    @master_list.each do |x|
      puts x
      if x.fetch(par[0].to_s) == par[1]
        @temp_list << x
      end
    end
    @master_list = @temp_list
    @temp_list = []
  end
  @master_list
end

#filter_by_fields_or(list, params = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/testrail_helper.rb', line 64

def filter_by_fields_or(list, params={})
  @temp_list = list
  h = params.map
  h.each do |par|
    puts par
    @master_list.each do |x|
      puts x
      if x.fetch(par[0].to_s) == par[1]
        @temp_list << x
      end
    end
  end
  @master_list = @temp_list.uniq
  @master_list
end

#get_all_active_usersObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/testrail_helper.rb', line 94

def get_all_active_users
  puts "getting all active_users"
  uri = "get_users"
  users = @client.send_get(uri)
  active_users = []
  users.each do |x|
    active_users << x if x.fetch('is_active') == true
  end
  active_users
end

#get_all_test_cases_in_section(params = {}) ⇒ Object



17
18
19
20
21
# File 'lib/testrail_helper.rb', line 17

def get_all_test_cases_in_section(params={})
  uri = "get_cases/#{params[:section_id]}&suite_id=#{params[:suite_id]}"
  uri = uri + "&priority_id=#{params[:priority]}" if params[:priority]
  @client.send_get(uri)
end

#get_all_usersObject



88
89
90
91
92
# File 'lib/testrail_helper.rb', line 88

def get_all_users
  puts "getting all users"
  uri = "get_users"
  @client.send_get(uri)
end

#get_plan(plan_id) ⇒ Object



41
42
43
44
# File 'lib/testrail_helper.rb', line 41

def get_plan(plan_id)
  uri = "get_plan/#{plan_id}"
  @client.send_get(uri)
end

#get_results_for_run(run_id) ⇒ Object



140
141
142
143
# File 'lib/testrail_helper.rb', line 140

def get_results_for_run(run_id)
  uri = "get_results_for_run/#{run_id}"
  @client.send_get(uri)
end

#get_run_info(run_id) ⇒ Object



31
32
33
34
# File 'lib/testrail_helper.rb', line 31

def get_run_info(run_id)
  uri = "get_run/#{run_id}"
  @client.send_get(uri)
end

#get_sections(project_id, suite_id) ⇒ Object



145
146
147
148
# File 'lib/testrail_helper.rb', line 145

def get_sections(project_id, suite_id)
  uri = "get_sections/#{project_id}&suite_id=#{suite_id}"
  @client.send_get(uri)
end

#get_test_cases(params = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/testrail_helper.rb', line 23

def get_test_cases(params={})
  uri = "get_cases/#{params[:project_id]}&suite_id=#{params[:project_id]}"
  uri = uri + "&suite_id=#{params[:suite_id]}" if params[:suite_id]
  uri = uri + "&section_id=#{params[:section_id]}" if params[:section_id]
  uri = uri + "&priority_id=#{params[:priority_id]}" if params[:priority_id]
  @client.send_get(uri)
end

#get_test_plan(plan_id) ⇒ Object



129
130
131
132
# File 'lib/testrail_helper.rb', line 129

def get_test_plan(plan_id)
  uri = "get_plan/#{plan_id}"
  @client.send_get(uri)
end

#get_test_run(run_id) ⇒ Object



135
136
137
138
# File 'lib/testrail_helper.rb', line 135

def get_test_run(run_id)
  uri = "get_run/#{run_id}"
  @client.send_get(uri)
end

#get_tests(run_id) ⇒ Object



36
37
38
39
# File 'lib/testrail_helper.rb', line 36

def get_tests(run_id)
  uri = "get_tests/#{run_id}"
  @client.send_get(uri)
end

#get_title(case_id) ⇒ Object



117
118
119
120
121
# File 'lib/testrail_helper.rb', line 117

def get_title(case_id)
  puts "getting title"
  uri = "get_case/#{case_id}"
  @client.send_get(uri)
end

#get_user(user_id) ⇒ Object



105
106
107
108
109
# File 'lib/testrail_helper.rb', line 105

def get_user(user_id)
  puts "getting title"
  uri = "get_user/#{user_id}"
  @client.send_get(uri)
end

#get_user_by_email(email) ⇒ Object



111
112
113
114
115
# File 'lib/testrail_helper.rb', line 111

def get_user_by_email(email)
  puts "getting title"
  uri = "get_user_by_email&email=#{email}"
  @client.send_get(uri)
end

#update_test_case(case_id, params = {}) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/testrail_helper.rb', line 80

def update_test_case(case_id, params={})
  puts "updating"
  params.merge({title:get_title(case_id)})
  puts params
  uri = "update_case/#{case_id}"
  puts @client.send_post(uri, params)
end

#write_to_file(list, filename) ⇒ Object



123
124
125
126
127
# File 'lib/testrail_helper.rb', line 123

def write_to_file(list, filename)
  File.open(filename, "w+") do |f|
    list.each { |element| f.puts(element) }
  end
end