actir 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6222ddd12feb24d688c141761ba44c100b4be875
4
- data.tar.gz: f7c3479902e9fa4f6bcbd677851f1b610a4aa907
3
+ metadata.gz: 111066ba4bcff7cf8ef706a6e62cd33a1c42583d
4
+ data.tar.gz: 2995ee75054abb76fe64a8a61dd48ffb551675dd
5
5
  SHA512:
6
- metadata.gz: 89a0b6c0d3175ac48e64bf1ed8aa4757841cdc14d58720bfb3924d9a6f7b5df5f16392effba49d4ab93f885e85f979d83e54439a95a7b65bfa2a603858be32ca
7
- data.tar.gz: c573cc277cce26993a2c97b01a95e2c0c8a8106c424694e69972ddfaa63ea15eabbc5d191c30d710cad37fa1b86922e224c63e8dc1fa927d6f1aeccd8b6d6b04
6
+ metadata.gz: 9b1ce4c3f177719da45f3617c6c8fe8793ccac438f4b3c780c3e92a011897a4cd32a2f150eca3b25dae1352a15e3f31fa394c25109048c5fba45c56cbe4cabfe
7
+ data.tar.gz: c71e3d4df39cb5b28867ef4b84951dcbe3cf69be431660a83bbe0daca32a13ca4d89bfc6ca8500adaeef502210570d0e351be4bbec3659ea06ff1ed41093b73b
@@ -284,11 +284,11 @@ module Actir
284
284
  runs = (0...num_processes).to_a
285
285
  results = if options[:non_parallel]
286
286
  runs.map do |i|
287
- Actir::ParallelTests::Test::Runner.execute_command(command, i, num_processes, options)
287
+ @runner.execute_command(command, i, num_processes, options)
288
288
  end
289
289
  else
290
290
  execute_in_parallel(runs, num_processes, options) do |i|
291
- Actir::ParallelTests::Test::Runner.execute_command(command, i, num_processes, options)
291
+ @runner.execute_command(command, i, num_processes, options)
292
292
  end
293
293
  end.flatten
294
294
 
@@ -34,7 +34,7 @@ module Actir
34
34
 
35
35
  def print_testcase_failed(testcase_name, backtrace, failure_number)
36
36
  @file.puts " <dd class=\"testcase failed\">"
37
- @file.puts " <span class=\"failed_spec_name\">[testcase]: #{h(testcase_name)}</span>"
37
+ @file.puts " <span class=\"failed_spec_name\">[Testcase]: #{h(testcase_name)}</span>"
38
38
  @file.puts " <div id=\"testtab_#{failure_number}\" style=\"float:right\"><a class=\"expand\" href=\"#\" onClick=\"Effect('failure_#{failure_number}',this.parentNode.id);\" >+</a> </div>"
39
39
  @file.puts " <div class=\"failure\" id=\"failure_#{failure_number}\" style=\"display:none;\">"
40
40
  @file.puts " <div class=\"backtrace\"><pre>#{h(backtrace)}</pre></div>"
@@ -27,25 +27,26 @@ module Actir
27
27
  # @return [String] 执行结果字符串
28
28
  #
29
29
  def re_run_tests(test_result, process_number, num_processes, options, address, times)
30
- #根据重跑次数重新执行失败用例
31
- result = re_run(test_result, process_number, num_processes, options, address, times)
32
- #从老的执行结果输出中提取出相关数据
33
- old_result = summarize_results(find_results(test_result[:stdout]))
34
- #puts "old_result : " + old_result
35
- #从新的执行结果中提取出数据,并算出总数
36
- #因为若有多个失败用例就有多个执行结果
37
- new_result = summarize_results(find_results(result[:stdout]))
38
- #puts "new_result : " + new_result
39
- #刷新最终的执行结果
40
- if old_result == nil || old_result == ""
41
- puts "[Debug] test_result : "
42
- puts test_result
43
- end
44
- if new_result == nil || new_result == ""
45
- puts "[Debug] result : "
46
- puts result
47
- end
48
- combine_tests_results(old_result, new_result)
30
+ @result = load_result
31
+ #根据重跑次数重新执行失败用例
32
+ result = re_run(test_result, process_number, num_processes, options, address, times)
33
+ #从老的执行结果输出中提取出相关数据
34
+ old_result = summarize_results(find_results(test_result[:stdout]))
35
+ #puts "old_result : " + old_result
36
+ #从新的执行结果中提取出数据,并算出总数
37
+ #因为若有多个失败用例就有多个执行结果
38
+ new_result = summarize_results(find_results(result[:stdout]))
39
+ #puts "new_result : " + new_result
40
+ #刷新最终的执行结果
41
+ if old_result == nil || old_result == ""
42
+ puts "[Debug] test_result : "
43
+ puts test_result
44
+ end
45
+ if new_result == nil || new_result == ""
46
+ puts "[Debug] result : "
47
+ puts result
48
+ end
49
+ combine_tests_results(old_result, new_result)
49
50
  end
50
51
 
51
52
  private
@@ -56,7 +57,10 @@ module Actir
56
57
  #先获取失败用例信息
57
58
  tests = capture_failures_tests(test_result)
58
59
  cmd = ""
59
- tests.each do |testcase, testfile|
60
+ tests.each do |unique_testname|
61
+ # 从combine的测试用例名称中获取测试文件名称和测试用例名称
62
+ testfile = @result.get_testfile_from_unique(unique_testname)
63
+ testcase = @result.get_testcase_from_unique(unique_testname)
60
64
  #输出一些打印信息
61
65
  puts "[ Re_Run ] - [ #{testfile} -n #{testcase} ] - Left #{times-1} times - in Process[#{process_number}]"
62
66
  cmd += "#{executable} #{testfile} #{address} -n #{testcase};"
@@ -77,35 +81,42 @@ module Actir
77
81
  end
78
82
 
79
83
  #从result中获取执行结果用于生成测试报告
80
- Actir::ParallelTests::Test::Result.get_testsuite_detail(result, :rerunner)
84
+ @result.get_testsuite_detail(result, :rerunner)
81
85
 
82
86
  return result
83
87
  end
84
88
 
85
89
  #从输出内容中获取失败用例文件名以及用例名称
86
90
  def capture_failures_tests(test_result)
87
- result_array = test_result[:stdout].split("\n")
88
- failure_tests_hash = {}
89
- testcase = ""
90
- testfile = ""
91
- result_array.each do |result|
92
- #取出执行失败的用例文件名称和用例名称
93
- if (result =~ failure_tests_name_reg) || (result =~ error_tests_name_reg)
94
- #范例:"testhehe(TestHehe)"
95
- testcase = $1
96
- end
97
- if result =~ failure_tests_file_reg
98
- #范例:"testcode/test_tt/test_hehe.rb:8:in `xxxx'"
99
- testfile = $1
100
- end
101
- #至于为什么采用testcase => testfile的形式是因为…文件名会重复
102
- if testcase != "" && testfile != ""
103
- failure_tests_hash[testcase] = testfile
104
- testcase = ""
105
- testfile = ""
106
- end
107
- end
108
- failure_tests_hash
91
+ failure_tests = []
92
+ failure_tests_hash = @result.get_testfailed_info(test_result)
93
+ # 过滤报错信息,只需要用例名称和文件名称
94
+ failure_tests_hash.each do |testcase, failure_info|
95
+ failure_tests << testcase
96
+ end
97
+ failure_tests
98
+ # result_array = test_result[:stdout].split("\n")
99
+ # failure_tests_hash = {}
100
+ # testcase = ""
101
+ # testfile = ""
102
+ # result_array.each do |result|
103
+ # #取出执行失败的用例文件名称和用例名称
104
+ # if (result =~ failure_tests_name_reg) || (result =~ error_tests_name_reg)
105
+ # #范例:"testhehe(TestHehe)"
106
+ # testcase = $1
107
+ # end
108
+ # if result =~ failure_tests_file_reg
109
+ # #范例:"testcode/test_tt/test_hehe.rb:8:in `xxxx'"
110
+ # testfile = $1
111
+ # end
112
+ # #至于为什么采用testcase => testfile的形式是因为…文件名会重复
113
+ # if testcase != "" && testfile != ""
114
+ # failure_tests_hash[testcase] = testfile
115
+ # testcase = ""
116
+ # testfile = ""
117
+ # end
118
+ # end
119
+ # failure_tests_hash
109
120
  end
110
121
 
111
122
  #组合出最新的执行结果
@@ -130,17 +141,17 @@ module Actir
130
141
 
131
142
  #判断是否有用例失败
132
143
  def any_test_failed?(result)
133
- Actir::ParallelTests::Test::Result.any_test_failed?(result)
144
+ @result.any_test_failed?(result)
134
145
  end
135
146
 
136
147
  #获取错误用例名的正则
137
148
  def error_tests_name_reg
138
- Actir::ParallelTests::Test::Result.error_tests_name_reg
149
+ @result.error_tests_name_reg
139
150
  end
140
151
 
141
152
  #获取失败用例名的正则
142
153
  def failure_tests_name_reg
143
- Actir::ParallelTests::Test::Result.failure_tests_name_reg
154
+ @result.failure_tests_name_reg
144
155
  end
145
156
 
146
157
  #获取失败用例文件名的正则
@@ -154,6 +165,13 @@ module Actir
154
165
  /((\d+)\sfailure.*,\s(\d+)\serror)/
155
166
  end
156
167
 
168
+ # 加载result类
169
+ def load_result
170
+ require "actir/parallel_tests/test/result"
171
+ klass_name = "Actir::ParallelTests::Test::Result"
172
+ klass_name.split('::').inject(Object) { |x, y| x.const_get(y) }
173
+ end
174
+
157
175
  end
158
176
 
159
177
  end
@@ -15,10 +15,9 @@ module Actir
15
15
  if mode == :runner
16
16
  get_run_test_info(test_result)
17
17
  end
18
-
19
18
  #如果有用例失败,则记录详细信息,否则不需要
20
19
  if any_test_failed?(test_result)
21
- failure_detail_hash = get_testfailed_detail(test_result)
20
+ failure_detail_hash = get_testfailed_info(test_result)
22
21
  $testsuites.each do |testsuite|
23
22
  testcases = testsuite[:testcases]
24
23
  testcases.each do |testcase|
@@ -44,21 +43,25 @@ module Actir
44
43
 
45
44
  def get_run_test_info(test_result)
46
45
  output = test_result[:stdout]
47
- output.scan(/^(\[suite start\])([^\.]*)(\[suite end\])$/).each do |suite|
48
- suitename = suite[1].scan(/^(suitname:\s*)([\d\w]*)/)[0][1]
46
+ # output.scan(/^(\[suite start\])([^\.]*)(\[suite end\])$/).each do |suite|
47
+ output.scan(file_suite_case_reg).each do |suite|
48
+ filename = suite[0]
49
+ testsuite = suite[1].scan(/^(suitname:\s*)([\d\w]*)/)[0][1]
50
+ testsuite_name = get_unique_testname(filename, testsuite)
49
51
  cases = suite[1].scan(/^(testcase:\s*)([\d\w]*)/).inject([]) do |cases,testcase|
50
- cases << {:testcase_name => testcase[1], :success => true, :detail => nil}
52
+ testcase_name = get_unique_testname(filename, testcase[1])
53
+ cases << {:testcase_name => testcase_name, :success => true, :detail => nil}
51
54
  end
52
55
  # 如果testsuites中已存在此用例的信息,说明这个用例执行了rerun,就不再次添加了
53
56
  is_case_exist = $testsuites.inject(false) do |is_case_exist, testsuite|
54
- if testsuite.has_value?(suitename)
57
+ if testsuite.has_value?(testsuite_name)
55
58
  is_case_exist = true
56
59
  break
57
60
  end
58
61
  is_case_exist
59
62
  end
60
63
  if(is_case_exist == false)
61
- testsuite = {:testsuite_name => suitename, :testcases =>cases}
64
+ testsuite = {:testsuite_name => testsuite_name, :testcases =>cases}
62
65
  $testsuites << testsuite
63
66
  end
64
67
  end
@@ -69,11 +72,13 @@ module Actir
69
72
  #
70
73
  # 将测试套和测试用例的详细信息写入全局变量$testsuites中
71
74
  #
72
- def get_testfailed_detail(test_result)
75
+ def get_testfailed_info(test_result)
73
76
  result_array = test_result[:stdout].split("\n")
74
77
  failure_detail_hash = {}
78
+ testfile = ""
75
79
  testcase = ""
76
80
  detail = ""
81
+ testcase_name = ""
77
82
  record_detail_switch = 0
78
83
 
79
84
  result_array.each do |result|
@@ -81,25 +86,41 @@ module Actir
81
86
  #遇到错误信息,开启记录错误信息开关
82
87
  record_detail_switch = 1 if result =~failure_or_error_switch_on
83
88
 
89
+ # 记录报错信息
84
90
  if record_detail_switch == 1
85
91
  detail += result + "\n"
86
92
  end
87
93
 
94
+ # 记录报错用例名称
88
95
  if (result =~ failure_tests_name_reg) || (result =~ error_tests_name_reg)
89
96
  testcase = $1
90
97
  end
91
98
 
92
- if testcase != "" && detail != "" && record_detail_switch == 0
93
- failure_detail_hash[testcase] = detail
99
+ # 记录报错用例文件名称
100
+ if result =~ failure_tests_file_reg
101
+ #范例:"testcode/test_tt/test_hehe.rb:8:in `xxxx'"
102
+ testfile = $1
103
+ end
104
+
105
+ # 合并用例名称和文件名称
106
+ testcase_name = get_unique_testname(testfile, testcase)
107
+
108
+ if testcase_name != "" && detail != "" && record_detail_switch == 0
109
+ failure_detail_hash[testcase_name] = detail
94
110
  testcase = ""
111
+ testfile = ""
95
112
  detail = ""
113
+ testcase_name = ""
96
114
  end
97
115
  end
98
116
 
99
117
  failure_detail_hash
100
118
  end
101
119
 
102
-
120
+ # 从执行结果中获取文件/测试套/测试用例的名称
121
+ def file_suite_case_reg
122
+ /^Loaded\ssuite\s(.*)\nStarted\n\[suite start\]([^\.]*)\[suite end\]$/
123
+ end
103
124
 
104
125
  #判断是否有用例失败
105
126
  def any_test_failed?(result)
@@ -116,22 +137,57 @@ module Actir
116
137
  /^Failure:\s(test.+)\(.+\)/
117
138
  end
118
139
 
140
+ # 获取失败用例文件名的正则
141
+ def failure_tests_file_reg
142
+ /(.+\/test.+rb):\d+:in\s`.+'/
143
+ end
144
+
145
+ # 测试套信息开头正则
119
146
  def test_info_swtich_on
120
147
  /^\[suite start\]/
121
148
  end
122
149
 
150
+ # 测试套信息截止正则
123
151
  def test_info_swtich_off
124
152
  /^\[suite end\]/
125
153
  end
126
154
 
155
+ # 测试用例执行报错信息开头正则
127
156
  def failure_or_error_switch_on
128
157
  /^Failure:|^Error:/
129
158
  end
130
159
 
160
+ # 测试用例执行报错信息截止正则
131
161
  def failure_or_error_switch_off
132
162
  /^===============================================================================$/
133
163
  end
134
164
 
165
+ # 因为测试用例名称/测试套名称有可能重复,所以采用 测试文件名称:测试用例名称 的方式作为测试用例名称的唯一标识
166
+ # 也可用于测试套名称组合
167
+ def get_unique_testname(testfile, test)
168
+ if (test != "" || test != nil) && (testfile != "" || testfile != nil)
169
+ # 判断测试文件名称是否包含.rb后缀,如果没有则加上
170
+ unless testfile =~ /.*\.rb$/
171
+ testfile += ".rb"
172
+ end
173
+ return testfile + ":" + test
174
+ else
175
+ return ""
176
+ end
177
+ end
178
+
179
+ def get_testfile_from_unique(unique_testname)
180
+ testfile_name = ""
181
+ unique_testname =~ /(.*)\:(.*)/
182
+ testfile_name = $1
183
+ end
184
+
185
+ def get_testcase_from_unique(unique_testname)
186
+ p unique_testname
187
+ testcase_name = ""
188
+ unique_testname =~ /(.*)\:(.*)/
189
+ testcase_name = $2
190
+ end
135
191
 
136
192
  end
137
193
 
@@ -83,7 +83,7 @@ module Actir
83
83
  address = Actir::Remote.get_remote_address(1)
84
84
  end
85
85
  end
86
- @browser = Browser.new(:www, :url => address[0], :mode => $mode, :browser => :chrome)
86
+ @browser = Browser.new(:www, :url => address[0], :mode => $mode, :browser => :chrome, :window_size => nil)
87
87
  @browser.goto "baifubao.com"
88
88
  @browser
89
89
  end
@@ -1,3 +1,3 @@
1
1
  module Actir
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -34,6 +34,7 @@ class Browser
34
34
  @browser_type = args[:browser]
35
35
  @agent = args[:agent]
36
36
  @env = args[:mode]
37
+ @window_size = args[:window_size]
37
38
  if @env == :remote
38
39
  @url = if args[:url]
39
40
  "http://#{args[:url]}/wd/hub"
@@ -79,13 +80,14 @@ class Browser
79
80
 
80
81
  # 初始化入参
81
82
  def init_args(args = {})
83
+ config_exist = File.exist?(config_file)
82
84
  unless args.has_key?(:mode)
83
85
  #若通过actir执行测试用例,则会配置ENV的模式
84
86
  if ENV["mode"]
85
87
  args[:mode] = ENV["mode"].to_sym
86
88
  else
87
89
  #若ENV为空,则读取配置文件,判断有无配置文件
88
- if File.exist?(config_file)
90
+ if config_exist
89
91
  env = $config["config"]["test_mode"]["env"]
90
92
  args[:mode] = (env == nil) ? :local : env
91
93
  else
@@ -94,13 +96,25 @@ class Browser
94
96
  end
95
97
  end
96
98
  unless args.has_key?(:browser)
97
- if File.exist?(config_file)
99
+ if config_exist
98
100
  browser_type = $config["config"]["test_mode"]["browser"]
99
101
  args[:browser] = (browser_type == nil) ? :chrome : browser_type
100
102
  else
101
103
  args[:browser] = :chrome
102
104
  end
103
105
  end
106
+ unless args.has_key?(:window_size)
107
+ if config_exist
108
+ window_size = $config["config"]["window_size"]
109
+ if window_size != nil
110
+ width = window_size["width"]
111
+ height = window_size["height"]
112
+ end
113
+ args[:window_size] = (width == nil || height == nil) ? nil : window_size
114
+ else
115
+ args[:window_size] = nil
116
+ end
117
+ end
104
118
  args[:agent] = :iphone unless args.has_key?(:agent)
105
119
  args[:url] = $address unless args.has_key?(:url)
106
120
  args
@@ -128,6 +142,8 @@ class Browser
128
142
  browser.window.resize_to(PHANTOMJS_SIZE["width"], PHANTOMJS_SIZE["height"])
129
143
  elsif @env == :remote
130
144
  browser.window.resize_to(REMOTE_SIZE["width"], REMOTE_SIZE["height"])
145
+ elsif @window_size != nil
146
+ browser.window.resize_to(@window_size["width"], @window_size["height"])
131
147
  end
132
148
  browser
133
149
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actir
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit