Class: ATM::Services::TestRun

Inherits:
Base
  • Object
show all
Defined in:
lib/atm_ruby/services/test_run.rb

Overview

ATM::Services::TestRun provides methods for working with test runs

Instance Attribute Summary collapse

Attributes inherited from Base

#[], #auth_header, #header, #project_id, #response

Instance Method Summary collapse

Methods inherited from Base

#set_response

Constructor Details

#initialize(**options) ⇒ TestRun

Returns a new instance of TestRun.



10
11
12
13
14
# File 'lib/atm_ruby/services/test_run.rb', line 10

def initialize(**options)
  @test_run_id = options.delete(:test_run_id)
  @environment = options.delete(:environment)
  super(options)
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



8
9
10
# File 'lib/atm_ruby/services/test_run.rb', line 8

def environment
  @environment
end

#test_run_idObject (readonly)

Returns the value of attribute test_run_id.



8
9
10
# File 'lib/atm_ruby/services/test_run.rb', line 8

def test_run_id
  @test_run_id
end

Instance Method Details

#create(test_run_data) ⇒ Object

Creates new test run

Examples:

Create new test case

ATM::Client.new.TestRun.create({"name": "Full regression","projectKey": "JQA"})

Parameters:

  • test_run_data (Hash)


23
24
25
26
27
28
# File 'lib/atm_ruby/services/test_run.rb', line 23

def create(test_run_data)
  self.class.post("/rest/kanoahtests/1.0/testrun", body: test_run_data.to_json, headers: auth_header).tap do |res|
    set_response(res)
    raise ATM::TestRunError, response unless code == 201
  end
end

#create_new_test_run_result(test_run_id = @test_run_id, test_case_id, test_data) ⇒ Object

Create new result for a test run

}

ATM::Client.new.TestRun.create_new_test_run_result('DD-R123','DD-T123', test_data)

Examples:

test_data = {
"status": "Fail",
"scriptResults": [
  {
    "index": 0,
    "status": "Fail",
    "comment": "This steps has failed."
  }
]

Parameters:

  • test_run_id (String) (defaults to: @test_run_id)
  • test_case_id (String)
  • test_data (Hash)


91
92
93
94
95
96
# File 'lib/atm_ruby/services/test_run.rb', line 91

def create_new_test_run_result(test_run_id = @test_run_id, test_case_id, test_data)
  self.class.post("/rest/kanoahtests/1.0/testrun/#{test_run_id}/testcase/#{test_case_id}/testresult", body: test_data.to_json, headers: auth_header).tap do |res|
    set_response(res)
    # raise ATM::TestRunError, response unless code == 201
  end
end

#delete(test_run_id) ⇒ Object

Delete specific test run

Examples:

Create new test case

ATM::Client.new.TestRun.delete('DD-R123')

Parameters:

  • test_run_id (String)


51
52
53
54
55
56
# File 'lib/atm_ruby/services/test_run.rb', line 51

def delete(test_run_id)
  self.class.delete("/rest/kanoahtests/1.0/testrun/#{test_run_id}", headers: auth_header).tap do |res|
    set_response(res)
    raise ATM::TestRunError, response unless code == 204
  end
end

#find(test_run_id) ⇒ Object

Retrive specific test run

Examples:

Create new test case

ATM::Client.new.TestRun.find('DD-R123')

Parameters:

  • test_run_id (String)


37
38
39
40
41
42
# File 'lib/atm_ruby/services/test_run.rb', line 37

def find(test_run_id)
  self.class.get("/rest/kanoahtests/1.0/testrun/#{test_run_id}", headers: auth_header).tap do |res|
    set_response(res)
    raise ATM::TestRunError, response unless code == 200
  end
end

#process_result(test_data) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/atm_ruby/services/test_run.rb', line 124

def process_result(test_data)
  {
      'status'        => test_data[:status],
      'environment'   => test_data.fetch(:environment, @environment),
      'comment'       => test_data.fetch(:comment, nil),
      'userKey'       => test_data.fetch(:username, nil),
      'executionTime' => test_data.fetch(:execution_time, nil),
      'executionDate' => test_data.fetch(:execution_date, nil),
      'scriptResults' => test_data[:script_results]
  }.delete_if { |k, v| v.nil? }
end

#search(query_string) ⇒ Object

Searches for a testrun based on the provided quiry

Examples:

Create new test case

ATM::Client.new.TestRun.search('projectKey = "JQA"')

Parameters:

  • test_run_id (String)


65
66
67
68
69
70
# File 'lib/atm_ruby/services/test_run.rb', line 65

def search(query_string)
  self.class.get("/rest/kanoahtests/1.0/testrun/search?query=#{query_string}", headers: auth_header).tap do |res|
    set_response(res)
    raise ATM::TestRunError, response unless code == 200
  end
end

#update_last_test_run_result(test_run_id = @test_run_id, test_case_id, test_data) ⇒ Object

Update latest result for a test run

}

ATM::Client.new.TestRun.update_last_test_run_result('DD-R123','DD-T123', test_data)

Examples:

test_data = {
"status": "Fail",
"scriptResults": [
  {
    "index": 0,
    "status": "Fail",
    "comment": "This steps has failed."
  }
]

Parameters:

  • test_run_id (String) (defaults to: @test_run_id)
  • test_case_id (String)
  • test_data (Hash)


117
118
119
120
121
122
# File 'lib/atm_ruby/services/test_run.rb', line 117

def update_last_test_run_result(test_run_id = @test_run_id, test_case_id, test_data)
  self.class.post("/rest/kanoahtests/1.0/testrun/#{test_run_id}/testcase/#{test_case_id}/testresult", body: test_data.to_json, headers: auth_header).tap do |res|
    set_response(res)
  end
    # raise ATM::TestRunError, response unless response.code == 200
end