Class: TestRail::API
- Inherits:
-
Object
- Object
- TestRail::API
- Defined in:
- lib/test_rail/api.rb
Constant Summary collapse
- TESTRAIL =
'testrail.com'
- HEADERS =
{ "Content-Type" => "application/json" }
- STATUSES =
{ :passed => 1, :pass => 1, :blocked => 2, :untested => 3, :retest => 4, :failed => 5, :fail => 5 }
Instance Attribute Summary collapse
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #add_case(args) ⇒ Object
-
#add_result_for_case(args) ⇒ Object
Results API.
-
#add_run(args) ⇒ Object
Creates a new run api.add_run( :project_id => project_id, :suite_id => suite_id ) Optional parameters: name: Name to give the run description: Description of the run.
-
#add_section(args) ⇒ Object
Section API Calls.
-
#add_suite(args) ⇒ Object
Add a new suite (If suite already exists, a new one is created with the same name) api.add_suite( :project_id => 1, :name => ‘Cucumber features’, :description => ‘BDD Tests’ ) Returns the suite object.
-
#find_project(args) ⇒ Object
Search for a project by name testrail.find_project(:name => ‘Amazing project’).
- #get_case(args) ⇒ Object
-
#get_case_types ⇒ Object
Get all the case types defined for this testrail instance.
-
#get_cases(args) ⇒ Object
Testcase API.
-
#get_plan(args) ⇒ Object
Given a plan id, returns a plan (and populates internal run objects).
-
#get_priorities ⇒ Object
Get all the priorities defined for this testrail instance.
-
#get_project(args) ⇒ Object
Return a specific project by id api.get_project( :id => 1 ).
-
#get_projects ⇒ Object
Return a list of projects.
-
#get_run(args) ⇒ Object
Given a run id, retrieve a plan.
- #get_sections(args) ⇒ Object
-
#get_suite(args) ⇒ Object
Get an existing suite by id testrail.get_suite( :id => 1 ) Returns the suite object.
-
#get_suites(args) ⇒ Object
Get a list of suites for a project api.get_suites( :project_id => 1 ) Returns a list of suite objects.
- #get_tests(args) ⇒ Object
-
#initialize(args) ⇒ API
constructor
Initialize a new tesrail interface TestRail.new( :user => ‘[email protected]’, :password => ‘passw0rd’, :namespace => ‘yourteam’ ).
- #update_case(args) ⇒ Object
- #update_section(args) ⇒ Object
- #update_suite(args) ⇒ Object
Constructor Details
#initialize(args) ⇒ API
Initialize a new tesrail interface TestRail.new( :user => ‘[email protected]’,
:password => 'passw0rd',
:namespace => 'yourteam' )
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/test_rail/api.rb', line 23 def initialize(args) raise "Need to provide arguments to constructor" if !args @user = args[:user] or raise "Missing username (:user => '[email protected]')" @password = args[:password] or raise "Missing password (:password => 'abc123')" @namespace = args[:namespace] or raise "Missing namespace (:namespace => 'testteam')" @server = @namespace + "." + TESTRAIL @host = URI('https://' + @server) @api = "/index.php?/api/v2/" @port = 443 end |
Instance Attribute Details
#server ⇒ Object
Returns the value of attribute server.
3 4 5 |
# File 'lib/test_rail/api.rb', line 3 def server @server end |
Instance Method Details
#add_case(args) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/test_rail/api.rb', line 166 def add_case(args) section_id = args[:section_id] or raise 'Missing section id (:section_id => 1)' title = args[:title] or raise 'Missing title (:title => "Use logs in")' steps = args[:steps] type_id = args[:type_id] priority_id = args[:priority_id] test_case = post('add_case', [section_id], { :title => title, :custom_steps => steps, :type_id => type_id, :priority_id => priority_id }) TestRail::TestCase.new(test_case.merge({ :api => self })) end |
#add_result_for_case(args) ⇒ Object
Results API
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/test_rail/api.rb', line 198 def add_result_for_case(args) run_id = args[:run_id] or raise "Missing test run id (:run_id => 1)" case_id = args[:case_id] or raise "Missing test case id (:case_id => 1)" status_id = args[:status_id] if !status_id status_id = STATUSES[args[:status].to_sym] raise "Couldn't determine result status '#{args[:status]}'" if !status_id end result = { :status_id => status_id, :comment => args[:comment], :version => args[:version], :elapsed => args[:elapsed] } test_rail_result = post('add_result_for_case', [run_id, case_id], result) #TODO new this into a relevant TestRails object end |
#add_run(args) ⇒ Object
Creates a new run api.add_run( :project_id => project_id, :suite_id => suite_id ) Optional parameters: name: Name to give the run description: Description of the run
232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/test_rail/api.rb', line 232 def add_run(args) project_id = args[:project_id] or raise "Missing project id ( :project_id => 1)" suite_id = args[:suite_id] or raise "Missing suite id ( :suite_id => 1)" params = { :suite_id => suite_id, :name => args[:name], :description => args[:description] } result = post('add_run', [project_id], params) TestRail::Run.new(result.merge({ :api => self })) end |
#add_section(args) ⇒ Object
Section API Calls
117 118 119 120 121 122 123 124 125 |
# File 'lib/test_rail/api.rb', line 117 def add_section(args) project_id = args[:project_id] or raise 'Missing project id (:project_id => 1)' name = args[:name] or raise 'Missing name (:name => "UI features")' suite_id = args[:suite_id] or raise 'Missing suite id (:suite_id => 1)' parent_id = args[:parent_id] section = post('add_section', [project_id], { :suite_id => suite_id, :name => name, :parent_id => parent_id }) TestRail::Section.new(section.merge({ :api => self, :project_id => project_id, :suite_id => suite_id })) end |
#add_suite(args) ⇒ Object
Add a new suite (If suite already exists, a new one is created with the same name) api.add_suite( :project_id => 1, :name => ‘Cucumber features’, :description => ‘BDD Tests’ ) Returns the suite object
76 77 78 79 80 81 82 83 |
# File 'lib/test_rail/api.rb', line 76 def add_suite(args) project_id = args[:project_id] or raise 'Missing project id (:project_id => 1)' name = args[:name] or raise 'Missing name (:name => "Cucumber features")' description = args[:description] suite = post('add_suite', [project_id], { :name => name, :description => description }) TestRail::Suite.new(suite.merge({ :api => self })) end |
#find_project(args) ⇒ Object
Search for a project by name testrail.find_project(:name => ‘Amazing project’)
58 59 60 61 62 63 64 65 66 |
# File 'lib/test_rail/api.rb', line 58 def find_project(args) name = args[:name] or raise "Missing name (:name => 'Amazing Project')" projects = get_projects projectexists = projects.select { |p| p.name == name }.first if (!projectexists) raise "Project Not Found." end return projectexists end |
#get_case(args) ⇒ Object
160 161 162 163 164 |
# File 'lib/test_rail/api.rb', line 160 def get_case(args) case_id = args[:case_id] or raise 'Missing test case id (:case_id => 1)' testcase = get('get_case', [case_id]) TestRail::TestCase.new(testcase.merge({ :api => self })) end |
#get_case_types ⇒ Object
Get all the case types defined for this testrail instance
270 271 272 273 274 275 276 |
# File 'lib/test_rail/api.rb', line 270 def get_case_types result = get('get_case_types') result.collect do |type| TestRail::CaseType.new(type.merge({ :api => self })) end end |
#get_cases(args) ⇒ Object
Testcase API
150 151 152 153 154 155 156 157 158 |
# File 'lib/test_rail/api.rb', line 150 def get_cases(args) project_id = args[:project_id] or raise 'Missing project id (:project_id => 1)' suite_id = args[:suite_id] or raise 'Missing suite id (:suite_id => 1)' section_id = args[:section_id] list = get('get_cases', [project_id], { :suite_id => suite_id, :section_id => section_id }) list.collect do |item| TestRail::TestCase.new(item.merge({ :api => self })) end end |
#get_plan(args) ⇒ Object
Given a plan id, returns a plan (and populates internal run objects)
247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/test_rail/api.rb', line 247 def get_plan(args) plan_id = args[:plan_id] or raise "Missing plan id (:plan_id => 1)" result = get('get_plan', [plan_id]) raw_runs = result['entries'].collect { |e| e['runs'] }.flatten runs = raw_runs.each.collect { |r| TestRail::Run.new(r.merge({ :api => self })) } plan = TestRail::Plan.new(result.merge({ :api => self, :runs => runs })) plan end |
#get_priorities ⇒ Object
Get all the priorities defined for this testrail instance
279 280 281 282 283 284 285 |
# File 'lib/test_rail/api.rb', line 279 def get_priorities result = get('get_priorities') result.collect do |priority| TestRail::Priority.new(priority.merge({ :api => self })) end end |
#get_project(args) ⇒ Object
Return a specific project by id api.get_project( :id => 1 )
50 51 52 53 54 |
# File 'lib/test_rail/api.rb', line 50 def get_project(args) id = args[:id] or raise "Missing id (:id => 1)" project = get('get_project', [id]) TestRail::Project.new(project.merge({ :api => self })) end |
#get_projects ⇒ Object
Return a list of projects
41 42 43 44 45 46 |
# File 'lib/test_rail/api.rb', line 41 def get_projects list = get('get_projects') list.collect do |item| TestRail::Project.new(item.merge({ :api => self })) end end |
#get_run(args) ⇒ Object
Given a run id, retrieve a plan
220 221 222 223 224 225 |
# File 'lib/test_rail/api.rb', line 220 def get_run(args) run_id = args[:run_id] or raise "Missing run id ( :run_id => 1)" result = get('get_run', [run_id]) TestRail::Run.new(result.merge({ :api => self })) end |
#get_sections(args) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/test_rail/api.rb', line 127 def get_sections(args) project_id = args[:project_id] or raise 'Missing project id (:project_id => 1)' suite_id = args[:suite_id] or raise 'Missing suite id (:suite_id => 1)' list = get('get_sections', [project_id], { :suite_id => suite_id }) list.collect do |item| TestRail::Section.new(item.merge({ :api => self, :project_id => project_id })) end end |
#get_suite(args) ⇒ Object
Get an existing suite by id testrail.get_suite( :id => 1 ) Returns the suite object
99 100 101 102 103 |
# File 'lib/test_rail/api.rb', line 99 def get_suite(args) id = args[:id] or raise "Missing suite id (:id => 1)" suite = get('get_suite', [id]) TestRail::Suite.new(suite.merge({ :api => self })) end |
#get_suites(args) ⇒ Object
Get a list of suites for a project api.get_suites( :project_id => 1 ) Returns a list of suite objects
88 89 90 91 92 93 94 |
# File 'lib/test_rail/api.rb', line 88 def get_suites(args) id = args[:project_id] or raise "Missing project id (:project_id => 1)" list = get('get_suites', [id]) list.collect do |item| TestRail::Suite.new(item.merge({ :api => self })) end end |
#get_tests(args) ⇒ Object
260 261 262 263 264 265 266 267 |
# File 'lib/test_rail/api.rb', line 260 def get_tests(args) run_id = args[:run_id] or raise "Missing run id (:run_id => 1)" list = get('get_tests', [run_id]) list.collect do |item| TestRail::Test.new(item.merge({ :api => self })) end end |
#update_case(args) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/test_rail/api.rb', line 180 def update_case(args) case_id = args[:case_id] or raise "Missing case id (:case_id => 1)" new_values = {} new_values[:title] = args[:title] if args[:title] new_values[:custom_steps] = args[:steps] if args[:steps] new_values[:priority_id] = args[:priority_id] if args[:priority_id] new_values[:type_id] = args[:type_id] if args[:type_id] test_case = post('update_case', [case_id], new_values ) TestRail::TestCase.new(test_case.merge({ :api => self })) end |
#update_section(args) ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/test_rail/api.rb', line 136 def update_section(args) section_id = args[:section_id] or raise 'Missing section id (:section_id => 1)' project_id = args[:project_id] or raise 'Missing project id (:project_id => 1)' name = args[:name] or raise 'Missing name (:name => "UI features")' suite_id = args[:suite_id] or raise 'Missing suite id (:suite_id => 1)' parent_id = args[:parent_id] section = post('update_section', [section_id], { :suite_id => suite_id, :name => name, :parent_id => parent_id }) TestRail::Section.new(section.merge({ :api => self, :project_id => project_id })) end |
#update_suite(args) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/test_rail/api.rb', line 105 def update_suite(args) id = args[:id] or raise "Missing suite id (:id => 1)" name = args[:name] description = args[:description] suite = post('update_suite', [id], { :name => name, :description => description }) TestRail::Suite.new(suite.merge({ :api => self })) end |