Class: BatchGetResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/tabbyx/helpers/http_batch_handler.rb

Overview

使用方法:

1. 将API的url,参数,action等按照模板 inputs/api_testcases.xlsx 填写
TESTCASE	ACTION	URL	PARAMS
2. 运行测试,接口请求返回的结果会填回表格
example:
RunTestCases.new("api_testcases.xlsx",0).run_test_cases
3. 运行完毕后打开excel文件查看返回数据

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, worksheet = 0) ⇒ BatchGetResponse

Returns a new instance of BatchGetResponse.



17
18
19
20
21
# File 'lib/tabbyx/helpers/http_batch_handler.rb', line 17

def initialize(filename,worksheet=0)
  @testcases = ExcelHelper.read_from_excel(filename,worksheet)
  @filename = filename
  @worksheet = worksheet
end

Instance Attribute Details

#testcasesObject

Returns the value of attribute testcases.



15
16
17
# File 'lib/tabbyx/helpers/http_batch_handler.rb', line 15

def testcases
  @testcases
end

Instance Method Details

#run_test_casesObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tabbyx/helpers/http_batch_handler.rb', line 23

def run_test_cases
  testresults = []
  @testcases.each do |testcase|
    testresult = []
    unless testcase[1].nil?
      (0..3).each { |i| testresult[i] = testcase[i] }
      action = testcase[1].strip
      url = testcase[2].strip
      params = testcase[3]
    end

    case action
      when 'GET'
        res = HTTPHelper.new.get_response(HOST+url,params)
        testresult << res << res.code << res["Data"]
      when 'POST'
        res = HTTPHelper.new.post_response(HOST+url,params)
        testresult << res << res.code << res["Data"]
      when 'ACTION'
        testresult << "RESPONSE" << "RESPONSE CODE" << "DATA"
    end

    testresults.push testresult
  end
  ExcelHelper.write_dictionary_to_excel(testresults,"testresult1.xlsx",@worksheet) unless testresults.nil?
end