actir 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b43d744c66c2dd1e24f9e64b7d2646636c15a793
4
- data.tar.gz: 23f165b5dd8b7ccf7e198d6d8f10c4b56395c2f1
3
+ metadata.gz: 5fd03ea345d89f235da0da7018897b291bac51e4
4
+ data.tar.gz: 36008a746454c6ac769fa39686b8040133e8c913
5
5
  SHA512:
6
- metadata.gz: 6b47142432f0de33ffb80f45f402c6b0ea78714b7edd4c108fb243e8d45b795c154be3b236b70ea7c7e3fd8770254a2bef290a82968e0dc3aec98d708b39f47b
7
- data.tar.gz: 4b7c59ff5a59442be44fa29abce1b2005fe59ca03bc3d0b8419b3645602e7cbc96e97b052b335f0afaced329e96802faa49aef9917285ca2b4af510b96004910
6
+ metadata.gz: cafec979c937f0ae7ce4fe1e89bf507ae930935888745f18c1a6901cbe9ec24dc9451b75ee5284958600dc0901b2a4c0831edec0ccf044002fd69083bf2ff399
7
+ data.tar.gz: 9af0c87b695b771a93568e3368d23b802af1f71c681676287fddc2432d88f3b8eda500d9b690b3705194f260ec77df61e05f6a6fe13d675be080688047884d4e
data/README.md CHANGED
@@ -2,49 +2,76 @@
2
2
 
3
3
  Application Concurrence Test in Ruby.
4
4
 
5
- ## Installation
5
+ ## 安装
6
6
 
7
- git clone code and then execute:
7
+ 通过Rake本地安装gem包:
8
8
 
9
9
  $ rake install
10
10
 
11
- Or install it yourself as:
12
-
13
- $ gem install actir
14
-
15
- ## Usage
16
-
17
- 使用须知:
18
- 1. 对应测试工程结构如下
19
-  config -- 配置文件
20
-   |-config.yaml -- 总体配置文件,test_mode相关的配置项必须要填
21
-  elements
22
-   |-components -- 公用页面元素方法
23
-   |-pages -- 页面元素封装的方法,可以继承自Actir::BasicPage,已经封装了部分公用方法
24
-  testcode -- 测试用例,执行之前需要初始化 Actir::Initializer.new(project_path)
25
-
26
- 2.project_path:测试工程根目录
27
-
28
- 3.Browser.new(type, *args):
29
-  Browser重新封装了watir以及selenium的初始化浏览器的方法
30
-  1).type指定初始化浏览器的类型,可以指定www/wap两类
31
-  2).*args:
32
-  :browser - 浏览器类型,可以支持 :chrome/:phantomjs/:firefox, 默认为chrome
33
-  :agent - user agent类型,可以支持 :iphone/:andriod_phone, 默认为iphone
34
-  :mode - 启动模式,支持 :local/:remote, 默认为local
35
-  :url - 配合mode为remote的模式,指定远程机器的url,需要 IP+端口号
36
-
37
- 4.初始化会自动require所有的elements内的文件并自动定义每个页面类对应的方法
38
-  如: 某页面类名为LoginPage,则会自动定义出login_page方法
39
-  3中初始化出的browser对象,可以直接调用login_page方法
40
-  也可以直接调用Watir::Browser对应的所有方法
41
-  如:browser = Browser.new(type, *args)
42
-    browser.login_page.xxx (xxxLoginPage中定义的方法)
43
-
44
- ## Contributing
45
-
46
- 1. Fork it ( https://github.com/hub128/actir.git )
47
- 2. Create your feature branch (`git checkout -b my-new-feature`)
48
- 3. Commit your changes (`git commit -am 'Add some feature'`)
49
- 4. Push to the branch (`git push origin my-new-feature`)
50
- 5. Create a new Pull Request
11
+ 或者通过rubygems远程安装
12
+
13
+ $ sudo gem install actir
14
+
15
+ 如果是Mac OS X 10.11版本以上的系统,要么关闭rootless机制,或者:
16
+
17
+ $ sudo gem install actir -n /usr/local/bin
18
+
19
+
20
+ ## 使用须知
21
+
22
+ ####测试工程结构
23
+ - **config**:配置文件
24
+   |--- config.yaml:总体配置文件,test_mode相关的配置项必须要填
25
+ - **elements**:页面元素
26
+   |--- components:公用页面元素方法, 包装成`Module`
27
+   |--- pages:页面元素封装的方法,可以继承自`Actir::BasicPage`,已经封装了部分公用方法
28
+   |--- items:根据业务抽象出的类
29
+   |--- user:根据系统业务抽象出的角色及其Action
30
+ - **testcode**: 测试用例, 文件和用例方法都要以`test`开头, 执行之前需要初始化 Actir::Initializer.new(project_path),`project_path`为测试工程根目录
31
+
32
+ ####浏览器对象
33
+ ``` ruby
34
+ Browser.new(type, *args)
35
+ ```
36
+ Browser重新封装了Watir以及Selenium的初始化浏览器的方法
37
+ - **type**:指定初始化浏览器的类型,可以指定www/wap两类
38
+ - ***args**:
39
+ - `:browser`:浏览器类型,可以支持 :chrome/:phantomjs/:firefox, 默认为chrome
40
+ - `:agent`:user agent类型,可以支持 :iphone/:andriod_phone, 默认为iphone
41
+ - `:mode`:启动模式,支持 :local/:remote, 默认为local
42
+ - `:url`: 配合moderemote的模式,指定远程机器的url,需要 IP+端口号
43
+
44
+ ####Initializer自动加载工程文件
45
+ ``` ruby
46
+ Actir::Initializer.new(project_path)
47
+ ```
48
+ - 自动require所有的elements内的文件并自动定义每个页面类对应的方法。如: 某页面类名为`LoginPage`,则会自动定义出`login_page`方法供`Browser`对象调用
49
+ - 可以直接调用Watir::Browser的所有方法
50
+ ``` ruby
51
+ browser = Browser.new(:wap)
52
+ browser.login_page.login("xxx")
53
+ # 调用Watir::Browser对象的方法
54
+ browser.refresh
55
+ ```
56
+
57
+ ####执行测试用例
58
+
59
+ $ actir [switches] [--] [files & folders]
60
+ $ actir testcode/test_refund/test_full_refund.rb
61
+ $ actir testcode
62
+
63
+ 指定执行某个用例文件中的某个方法:
64
+
65
+ $ actir testcode/test_pay/test_pay.rb -n test_ecard
66
+
67
+ 指定用例失败重试次数:
68
+
69
+ $ actir testcode/test_pay/test_pay.rb -r 2
70
+
71
+ 输出html格式的测试报告:
72
+
73
+ $ actir testcode/test_pay/test_pay.rb -r 2 --report
74
+
75
+
76
+ > 可使用`actir -h` 了解更多的运行参数
77
+ >
data/lib/actir/config.rb CHANGED
@@ -59,11 +59,17 @@ module Actir
59
59
  #先取出数组中的第一个元素当做配置文件名称,并从数组中移除此元素
60
60
  file_name = key_array.shift
61
61
  #再取出第二个元素,指定配置项,并移除
62
- cfg_name = key_array.shift
62
+ # cfg_name = key_array.shift
63
63
  hash = {}
64
64
  #加载yaml配置文件,加锁
65
65
  lock(file_name, config_path) do
66
- hash = cfg_name ? load_file(file(file_name, config_path))[cfg_name] : load_file(file(file_name, config_path))
66
+ # hash = cfg_name ? load_file(file(file_name, config_path))[cfg_name] : load_file(file(file_name, config_path))
67
+ hash = load_file(file(file_name, config_path))
68
+ end
69
+ #判断是否存在 online 和 qatest 关键词,存在的话就读取当前env配置
70
+ if (hash.has_key?("online") || hash.has_key?("qatest"))
71
+ #在key_array头上加入env配置
72
+ key_array.unshift(determine_env)
67
73
  end
68
74
  #遍历key数组
69
75
  until key_array.empty? do
@@ -78,9 +84,9 @@ module Actir
78
84
  #
79
85
  # 改文件加锁,解决多进程同时写文件的问题
80
86
  #
81
- # @example : set("config.test_mode.env", ":remote")
87
+ # @example : set("config.test_mode.mode", ":remote")
82
88
  #
83
- # @param key : [String] 指定配置项的字符串,形如config.test_mode.env,以点衔接
89
+ # @param key : [String] 指定配置项的字符串,形如config.test_mode.mode,以点衔接
84
90
  #
85
91
  # value : [String] 要修改的值的字符串
86
92
  #
@@ -89,6 +95,19 @@ module Actir
89
95
  key_array = key.split(".")
90
96
  #先取出数组中的第一个元素当做配置文件名称,并从数组中移除此元素
91
97
  file_name = key_array.shift
98
+
99
+ hash = {}
100
+ #加载yaml配置文件,加锁
101
+ lock(file_name, config_path) do
102
+ # hash = cfg_name ? load_file(file(file_name, config_path))[cfg_name] : load_file(file(file_name, config_path))
103
+ hash = load_file(file(file_name, config_path))
104
+ end
105
+ #判断是否存在 online 和 qatest 关键词,存在的话就读取当前env配置
106
+ if (hash.has_key?("online") || hash.has_key?("qatest"))
107
+ #在key_array头上加入env配置
108
+ key_array.unshift(determine_env)
109
+ end
110
+
92
111
  cfg_str = key_array.shift
93
112
  old_value = ""
94
113
  lock(file_name, config_path) do
@@ -115,9 +134,10 @@ module Actir
115
134
  end
116
135
  config_file.close
117
136
  end
118
- puts "Already set [" + key + "]'s value form " + old_value + " into " + value
137
+ puts "set [" + key + "]'s value form " + old_value + " into " + value
119
138
  end
120
139
 
140
+
121
141
  #
122
142
  # 判断配置文件的上一次修改时间和当前时间是否一样
123
143
  #
@@ -189,6 +209,15 @@ module Actir
189
209
  true
190
210
  end
191
211
 
212
+ # 判断执行环境,如果$env为nil则从环境变量里面读取
213
+ def determine_env
214
+ if $env
215
+ $env
216
+ else
217
+ ENV["env"]
218
+ end
219
+ end
220
+
192
221
  end
193
222
  end
194
223
  end
data/lib/actir/data.rb CHANGED
@@ -5,37 +5,29 @@ module Actir
5
5
  class << self
6
6
 
7
7
  def get(key)
8
- #按照点分割字符串
9
- key_array = key.split(".")
10
- #先取出数组中的第一个元素当做配置文件名称,并从数组中移除此元素
11
- file_name = key_array.shift
12
- #再取出第二个元素,指定配置项,并移除
13
- cfg_name = key_array.shift
14
- hash = cfg_name ? load_file(file(file_name))[cfg_name] : load_file(file(file_name))
15
- #遍历key数组
16
- until key_array.empty? do
17
- key = key_array.shift
18
- hash = hash[key]
19
- end
20
- hash
8
+ # #按照点分割字符串
9
+ # key_array = key.split(".")
10
+ # #先取出数组中的第一个元素当做配置文件名称,并从数组中移除此元素
11
+ # file_name = key_array.shift
12
+ # #再取出第二个元素,指定配置项,并移除
13
+ # cfg_name = key_array.shift
14
+ # hash = cfg_name ? load_file(file(file_name))[cfg_name] : load_file(file(file_name))
15
+ # #遍历key数组
16
+ # until key_array.empty? do
17
+ # key = key_array.shift
18
+ # hash = hash[key]
19
+ # end
20
+ # hash
21
+ Actir::Config.get(key, data_dir)
21
22
  end
22
23
 
23
24
  private
24
25
 
25
- def file(file_name)
26
- File.expand_path(File.join(data_dir, "/#{file_name}.yaml"), __FILE__)
27
- end
28
-
29
26
  #默认配置文件夹路径
30
27
  def data_dir
31
28
  @data_dir ||= File.join($project_path, "data")
32
29
  end
33
30
 
34
- #读取yaml配置文件
35
- def load_file(file)
36
- YAML.load_file file
37
- end
38
-
39
31
  end
40
32
 
41
33
  end
@@ -11,7 +11,7 @@ module Actir
11
11
  $env = "online"
12
12
  options = parse_options!(argv)
13
13
  num_processes = Actir::ParallelTests.determine_number_of_processes(options[:count])
14
- $mode = Actir::ParallelTests.determine_run_env(options[:mode])
14
+ $mode = Actir::ParallelTests.determine_run_mode(options[:mode])
15
15
  if options[:execute]
16
16
  execute_shell_command_in_parallel(options[:execute], num_processes, options)
17
17
  else
@@ -184,7 +184,7 @@ module Actir
184
184
  # default - filesize
185
185
  # TEXT
186
186
  # ) { |type| options[:group_by] = type.to_sym }
187
- opts.on("-e [online][qatest]", String, "set environment to run testcase, default: online") { |env| env = "online" if ((env != "qatest" && env != "online")|| (env == nil)); $env = env;}
187
+ opts.on("-e [online][qatest]", String, "set environment to run testcase, default: online") { |env| env = "online" if ((env != "qatest" && env != "online")||(env == nil)); $env = env}
188
188
  opts.on("-r [TIMES]", "--rerun [TIMES]", Integer, "rerun times for failure&error testcase, default: 0") { |n| options[:rerun] = n }
189
189
  opts.on("-u", "--update", "Update Baifubao's cookies") { options[:update] = true }
190
190
  opts.on("--verbose", "Print more output") { options[:verbose] = true }
@@ -27,25 +27,24 @@ module Actir
27
27
  [
28
28
  times,
29
29
  0
30
- #Actir::Config.get("config.test_mode.re_run")
31
30
  ].detect{|c| not c.to_s.strip.empty? }.to_i
32
31
  end
33
32
 
34
33
  #判断用例执行的环境是local还是remote
35
- def determine_run_env(mode)
34
+ def determine_run_mode(mode)
36
35
  env_mode = :local
37
36
  #判断是否存在config.yaml配置文件,如果不存在,则test_mode给默认值
38
37
  if File.exist?(File.join($project_path, "config", "config.yaml"))
39
38
  #刷新配置文件中的env配置项为remote模式,以防止本地调试代码改写上传后导致CI失败
40
39
  if mode
41
- unless mode == /#{Actir::Config.get("config.test_mode.env")}/
40
+ unless mode == /#{Actir::Config.get("config.test_mode.mode")}/
42
41
  #同步修改配置文件,需要先将Symbol转换成String
43
42
  mode_str = ":" + mode.to_s
44
- Actir::Config.set("config.test_mode.env", mode_str)
43
+ Actir::Config.set("config.test_mode.mode", mode_str)
45
44
  end
46
45
  env_mode = mode
47
46
  else
48
- env_mode = Actir::Config.get("config.test_mode.env")
47
+ env_mode = Actir::Config.get("config.test_mode.mode")
49
48
  end
50
49
  else
51
50
  if mode
@@ -41,26 +41,39 @@ module Actir
41
41
 
42
42
  def record_detail(test_result)
43
43
  failure_detail_hash = get_testfailed_info(test_result)
44
- $testsuites.each do |testsuite|
45
- testcases = testsuite[:testcases]
46
- testcases.each do |testcase|
47
- #标识用例是否执行失败
48
- fail_flag = 0
49
- failure_detail_hash.each do |testcase_failure, detail|
50
- if testcase_failure == testcase[:testcase_name]
51
- testcase[:success] = false
52
- testcase[:detail] = detail
53
- fail_flag = 1
54
- #从hash表中移除
55
- failure_detail_hash.delete(testcase_failure)
56
- end
57
- end
58
- if fail_flag == 0
59
- testcase[:success] = true
60
- testcase[:detail] = nil
44
+
45
+ $testsuites.each do |testsuite|
46
+ testcases = testsuite[:testcases]
47
+ testcases.each do |testcase|
48
+ #标识用例是否执行失败
49
+ fail_flag = 0
50
+ failure_detail_hash.each do |testcase_failure, detail|
51
+ if testcase_failure == testcase[:testcase_name]
52
+ testcase[:success] = false
53
+ testcase[:detail] = detail
54
+ fail_flag = 1
55
+ #从hash表中移除
56
+ failure_detail_hash.delete(testcase_failure)
61
57
  end
62
58
  end
59
+ if fail_flag == 0
60
+ testcase[:success] = true
61
+ testcase[:detail] = nil
62
+ end
63
+ end
64
+ end
65
+ # 反向再检查一遍是否有$testsuites种未记录的失败用例
66
+ miss_failed_case = []
67
+ if failure_detail_hash.size > 0
68
+ failure_detail_hash.each do |testcase_failure, detail|
69
+ testcase = {:testcase_name => testcase_failure, :success => false, :detail => detail}
70
+ #从hash表中移除
71
+ failure_detail_hash.delete(testcase_failure)
72
+ miss_failed_case << testcase
63
73
  end
74
+ testsuite = {:testsuite_name => "miss_failed_case", :testcases => miss_failed_case}
75
+ $testsuites << testsuite
76
+ end
64
77
  end
65
78
 
66
79
  def get_run_test_info(test_result)
@@ -83,6 +83,7 @@ module Actir
83
83
  def execute_command(cmd, process_number, num_processes, options)
84
84
  env = (options[:env] || {}).merge(
85
85
  #"TEST_ENV_NUMBER" => test_env_number(process_number),
86
+ "env" => $env,
86
87
  "TEST_ENV_NUMBER" => process_number,
87
88
  "PARALLEL_TEST_GROUPS" => num_processes
88
89
  )
data/lib/actir/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Actir
2
- VERSION = "1.4.2"
2
+ VERSION = "1.4.3"
3
3
  end
@@ -18,7 +18,7 @@ class Browser
18
18
  # 初始化函数
19
19
  #
20
20
  # 可以配置测试的mode:
21
- # 1.:env
21
+ # 1.:mode
22
22
  # :local 本地环境上测试
23
23
  # :remote 远程测试环境上测试
24
24
  # 2.:browser
@@ -27,20 +27,20 @@ class Browser
27
27
  # 3.:agent wap页面的useragent类型
28
28
  # :iphone
29
29
  # :android_phone
30
- # 4.:address 当env为:remote时,url指定远程执行脚本的地址
30
+ # 4.:address 当mode为:remote时,url指定远程执行脚本的地址
31
31
  #
32
32
  def initialize(type = :www, *args)
33
33
  args = init_args(*args)
34
34
  @browser_type = args[:browser]
35
35
  @agent = args[:agent]
36
- @env = args[:mode]
36
+ @mode = args[:mode]
37
37
  @window_size = args[:window_size]
38
- if @env == :remote
38
+ if @mode == :remote
39
39
  @url = if args[:url]
40
40
  "http://#{args[:url]}/wd/hub"
41
41
  else
42
42
  #TO-DO ,远程模式没有传入IP,改成local模式
43
- @env = :local
43
+ @mode = :local
44
44
  puts "selenium-node's IPAddress is null. switch to local mode"
45
45
  end
46
46
  end
@@ -90,8 +90,8 @@ class Browser
90
90
  else
91
91
  #若ENV为空,则读取配置文件,判断有无配置文件
92
92
  if config_exist
93
- env = $config["config"]["test_mode"]["env"]
94
- args[:mode] = (env == nil) ? :local : env
93
+ mode = $config["config"]["test_mode"]["mode"]
94
+ args[:mode] = (mode == nil) ? :local : mode
95
95
  else
96
96
  args[:mode] = :local
97
97
  end
@@ -127,7 +127,7 @@ class Browser
127
127
  # 打开普通www浏览器
128
128
  #
129
129
  def browser_www
130
- case @env
130
+ case @mode
131
131
  when :local
132
132
  #本地chrome浏览器
133
133
  browser = Watir::Browser.new @browser_type
@@ -142,7 +142,7 @@ class Browser
142
142
  #重新设置窗口大小,不然phantomjs的ghost driver各种问题
143
143
  if @browser_type == :phantomjs
144
144
  browser.window.resize_to(PHANTOMJS_SIZE["width"], PHANTOMJS_SIZE["height"])
145
- elsif @env == :remote
145
+ elsif @mode == :remote
146
146
  browser.window.resize_to(REMOTE_SIZE["width"], REMOTE_SIZE["height"])
147
147
  elsif @window_size != nil
148
148
  browser.window.resize_to(@window_size["width"], @window_size["height"])
@@ -160,7 +160,7 @@ class Browser
160
160
  # TO-DO: remote模式的phantomjs
161
161
  #
162
162
  def browser_wap
163
- case @env
163
+ case @mode
164
164
  when :local
165
165
  driver = Actir::Webdriver.driver(:browser => @browser_type, :agent => @agent)
166
166
  when :remote
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.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hub
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit