magnesium 0.0.1

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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +11 -0
  3. data/Gemfile.lock +52 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/lib/magnesium.rb +62 -0
  8. data/lib/magnesium/config.xml +16 -0
  9. data/lib/magnesium/elements/alert.rb +134 -0
  10. data/lib/magnesium/elements/browser.rb +29 -0
  11. data/lib/magnesium/elements/button.rb +104 -0
  12. data/lib/magnesium/elements/checkbox.rb +103 -0
  13. data/lib/magnesium/elements/div.rb +120 -0
  14. data/lib/magnesium/elements/frame.rb +121 -0
  15. data/lib/magnesium/elements/link.rb +105 -0
  16. data/lib/magnesium/elements/radio.rb +103 -0
  17. data/lib/magnesium/elements/select_list.rb +103 -0
  18. data/lib/magnesium/elements/span.rb +116 -0
  19. data/lib/magnesium/elements/table.rb +121 -0
  20. data/lib/magnesium/elements/text.rb +109 -0
  21. data/lib/magnesium/elements/text_field.rb +109 -0
  22. data/lib/magnesium/extensions/assert.rb +2 -0
  23. data/lib/magnesium/extensions/feedback.rb +25 -0
  24. data/lib/magnesium/extensions/http.rb +48 -0
  25. data/lib/magnesium/extensions/mail.rb +26 -0
  26. data/lib/magnesium/extensions/scheduler.rb +32 -0
  27. data/lib/magnesium/extensions/ssh.rb +53 -0
  28. data/lib/magnesium/extensions/webservice.rb +0 -0
  29. data/lib/magnesium/factor/test_case.rb +124 -0
  30. data/lib/magnesium/factor/test_data.rb +32 -0
  31. data/lib/magnesium/factor/test_result.rb +84 -0
  32. data/lib/magnesium/factor/test_site.rb +23 -0
  33. data/lib/magnesium/factor/test_step.rb +31 -0
  34. data/lib/magnesium/factor/test_ui.rb +55 -0
  35. data/lib/magnesium/support/config.rb +361 -0
  36. data/lib/magnesium/support/container.rb +18 -0
  37. data/lib/magnesium/support/data.rb +11 -0
  38. data/lib/magnesium/support/error.rb +16 -0
  39. data/lib/magnesium/support/factory.rb +43 -0
  40. data/lib/magnesium/support/log.rb +3 -0
  41. data/lib/magnesium/support/testlink.rb +270 -0
  42. data/lib/magnesium/support/xml.rb +73 -0
  43. data/lib/magnesium/version.rb +3 -0
  44. data/magnesium.gemspec +24 -0
  45. data/spec/runspec.rb +0 -0
  46. data/template.yml +57 -0
  47. metadata +134 -0
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+
3
+ module Magnesium
4
+ module TestResult
5
+
6
+ def get_expected_result(prefix,caseno)
7
+ begin
8
+ tc_id = TestLink.find_tcase(prefix,caseno)
9
+ tv_id = TestLink.find_version(tc_id)
10
+
11
+ TestLink.find_step_result(tv_id).each do |row|
12
+ row.map do |k,v|
13
+ @expected_result = v
14
+ end
15
+ end
16
+
17
+ box = Array.new
18
+ expect = Hash.new
19
+ unless @expected_result.split(/\<p\>\r\n\t/)[1].nil?
20
+ r = @expected_result.split(/\<p\>\r\n\t/)[1].split(/\<\/p\>/)[0].split(/\=\&gt\;/)
21
+ if r.size > 1
22
+ i = 0
23
+ until i>r.size-2
24
+ box.push setbox(r[i])
25
+ i = i+1
26
+ end
27
+ end
28
+ expect["box"] = box
29
+ expect["element"] = setelement(r[r.size-1])#basic
30
+ return expect
31
+ else
32
+ #error
33
+ puts '...'
34
+ end
35
+ # rescue
36
+ # error
37
+ #ensure
38
+ end
39
+ end
40
+
41
+ def get_real_result(prefix,caseno,browser)
42
+ begin
43
+ hash = get_expected_result(prefix,caseno)
44
+ #puts hash
45
+ data = nil
46
+
47
+ fa = Factory.creator(hash["element"]["name"].to_s)
48
+
49
+ fa.box = hash["box"]
50
+ fa.browser = browser
51
+ fa.generate
52
+ fa.element(hash["element"]["locate"],hash["element"]["value"])
53
+ if fa.execute(hash["element"]["action"],data)
54
+ @status = "p"
55
+ @notes = "pass"
56
+ else
57
+ @status = "f"
58
+ @notes = "fail"
59
+ end
60
+ Feedback.new(prefix,caseno,"zhou_meichen",@status,@notes)
61
+ # rescue
62
+ # error
63
+ #ensure
64
+ end
65
+ end
66
+
67
+
68
+ def setbox(string)
69
+ box = Hash.new
70
+ box["name"] = string.split(/\(/)[0]
71
+ box["locate"] = string.split(/\(/)[1].split(/\:/)[0]
72
+ box["value"] = string.split(/\(/)[1].split(/\:/)[1].split(/\)/)[0]
73
+ return box
74
+ end
75
+
76
+ def setelement(string)
77
+ element = Hash.new
78
+ element = setbox(string)
79
+ element["action"] = "exists"
80
+ return element
81
+ end
82
+ end
83
+ #end
84
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ #require File.expand_path("../../support/error",__FILE__)
4
+ require 'yaml'
5
+
6
+ module Magnesium
7
+ module TestSite
8
+
9
+ def generate_site(prefix,caseno)
10
+ @hash = Hash.new
11
+
12
+ yaml = YAML.load(File.open("#{Config.config["temp"]}#{TestLink.find_path(prefix,caseno)}"))
13
+ yaml["web"].collect do |row|
14
+ row.each do |k,v|
15
+ if k == 'site'
16
+ @hash[v["mark"]] = v["value"]
17
+ end
18
+ end
19
+ end
20
+ return @hash
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ #require File.expand_path("../../support/error",__FILE__)
4
+
5
+
6
+ module Magnesium
7
+ module TestStep
8
+
9
+ def generate_step(prefix,caseno)
10
+ begin
11
+ @tc_id = TestLink.find_tcase(prefix,caseno)
12
+ @tv_id = TestLink.find_version(@tc_id)
13
+
14
+ @teststep = Hash.new
15
+
16
+ result = TestLink.find_step_action(@tv_id)
17
+ result.each do |row|
18
+ row.map do |k,v|
19
+
20
+ step = v.split(/\<p\>\r\n\t/)[1].split(/\<\/p\>/)[0].split(/:/)
21
+ @teststep[step[0]] = step[1]
22
+ end
23
+ end
24
+ return @teststep
25
+ rescue
26
+ error
27
+ #ensure
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path("../../support/container",__FILE__)
4
+ #require File.expand_path("../../support/error",__FILE__)
5
+ require 'yaml'
6
+
7
+ #
8
+ #todo!!! frame\alert
9
+ #
10
+ module Magnesium
11
+ module TestUI
12
+
13
+ def generate_UI(prefix,caseno)
14
+ @hash = Hash.new
15
+
16
+ yaml = YAML.load(File.open("#{Config.config["temp"]}#{TestLink.find_path(prefix,caseno)}"))
17
+ yaml["web"].collect do |row|
18
+ row.each do |k,v|
19
+ if k == 'ui'
20
+ v.collect do |row|
21
+ @hash_element = Hash.new
22
+ @hash_locate = Hash.new
23
+ @hash_value = Hash.new
24
+ @hash_action = Hash.new
25
+ @hash_box = Hash.new
26
+
27
+ @cont = Container.new
28
+ @cont.container_mark = row["page"]["mark"]
29
+ @cont.container_type = row["page"]["type"]
30
+ @cont.container_title = row["page"]["title"]
31
+ row["page"]["container"].collect do |c|
32
+ @hash_element[c["element"]] = c["name"]
33
+ @hash_locate[c["element"]] = c["locate"]
34
+ @hash_value[c["element"]] = c["value"]
35
+ @hash_action[c["element"]] = c["action"]
36
+ unless c["box"].nil?
37
+ @hash_box[c["element"]] = c["box"]
38
+ end
39
+ end
40
+
41
+ @cont.hash_element = @hash_element
42
+ @cont.hash_locate = @hash_locate
43
+ @cont.hash_value = @hash_value
44
+ @cont.hash_action = @hash_action
45
+ @cont.hash_box = @hash_box
46
+
47
+ @hash[row["page"]["mark"]] = @cont
48
+ end
49
+ end
50
+ end
51
+ end
52
+ return @hash
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,361 @@
1
+ # encoding: utf-8
2
+
3
+ #require File.expand_path("../../fun/xml",__FILE__)
4
+ #require File.expand_path("../../support/error",__FILE__)
5
+ require 'rexml/document'
6
+ include REXML
7
+
8
+ module Magnesium
9
+ class Config
10
+ def self.config()
11
+ begin
12
+ file_path = File.expand_path("../../config.xml",__FILE__)
13
+ @XML = XML.openXML(file_path)
14
+ doc = XML.new_document(@XML)
15
+
16
+ config = Hash.new
17
+ #browser
18
+ hash = Hash.new
19
+ doc.elements.each("config/basic/browser") do |e|
20
+ #puts e.attributes["value"]
21
+ #puts e.attributes["proxy"]
22
+ hash["value"] = e.attributes["value"]
23
+ hash["proxy"] = e.attributes["proxy"]
24
+ end
25
+ config["browser"] = hash
26
+ # puts config["browser"]
27
+ #testlink
28
+ hash = Hash.new
29
+ doc.elements.each("config/basic/testlink") do |e|
30
+ hash["host"] = e.attributes["host"]
31
+ hash["host_account"] = e.attributes["host_account"]
32
+ hash["host_pwd"] = e.attributes["host_pwd"]
33
+ hash["database"] = e.attributes["database"]
34
+ hash["db_account"] = e.attributes["db_account"]
35
+ hash["db_pwd"] = e.attributes["db_pwd"]
36
+ hash["install_path"] = e.attributes["install_path"]
37
+ end
38
+ config["testlink"] = hash
39
+
40
+ #temp
41
+ doc.elements.each("config/basic/temp") do |e|
42
+ config["temp"] = e.attributes["path"]
43
+ end
44
+
45
+ #log
46
+ hash = Hash.new
47
+ doc.elements.each("config/optioanl/log") do |e|
48
+ hash["isstart"] = e.attributes["isstart"]
49
+ hash["path"] = e.attributes["path"]
50
+ end
51
+ config["log"] = hash
52
+
53
+ #mail
54
+ hash = Hash.new
55
+ doc.elements.each("config/optional/mail") do |e|
56
+ hash["isstart"] = e.attributes["isstart"]
57
+ hash["fromacount"] = e.attributes["fromaccount"]
58
+ hash["toaccount"] = e.attributes["toaccount"]
59
+ end
60
+ config["mail"] = hash
61
+
62
+ #screenshot
63
+ hash = Hash.new
64
+ doc.elements.each("config/optional/screenshot") do |e|
65
+ hash["isstart"] = e.attributes["isstart"]
66
+ hash["path"] = e.attributes["path"]
67
+ end
68
+ config["screenshot"] = hash
69
+
70
+ #performance
71
+ hash = Hash.new
72
+ doc.elements.each("config/optional/performance") do |e|
73
+ hash["isstart"] = e.attributes["isstart"]
74
+ hash["path"] = e.attributes["path"]
75
+ end
76
+ config["performance"] = hash
77
+
78
+ #wait
79
+ hash = Hash.new
80
+ doc.elements.each("config/optional/wait") do |e|
81
+ hash["isstart"] = e.attributes["isstart"]
82
+ hash["value"] = e.attributes["value"]
83
+ end
84
+ config["wait"] = hash
85
+ return config
86
+ rescue
87
+ error
88
+ puts 'test'
89
+ #ensure
90
+ # closeXML(@XML)
91
+ end
92
+ end
93
+
94
+ #check config
95
+ def self.check_config
96
+ flag = true
97
+ if config["browser"]["value"].nil?
98
+ puts 'M: Please set browser use add_browser function.'
99
+ flag = false
100
+ elsif config["testlink"]["host"].nil?
101
+ puts ''
102
+ flag = false
103
+ elsif config["testlink"]["host_account"].nil?
104
+ puts ''
105
+ flag = false
106
+ elsif config["testlink"]["host_pwd"].nil?
107
+ puts ''
108
+ flag = false
109
+ elsif config["testlink"]["database"].nil?
110
+ puts ''
111
+ flag = false
112
+ elsif config["testlink"]["db_account"].nil?
113
+ puts ''
114
+ flag = false
115
+ elsif config["testlink"]["db_pwd"].nil?
116
+ puts ''
117
+ flag = false
118
+ elsif config["testlink"]["install_path"].nil?
119
+ puts ''
120
+ flag = false
121
+ elsif config["temp"].nil?
122
+ puts ''
123
+ flag = false
124
+ end
125
+ return flag
126
+ end
127
+
128
+ #browser modify
129
+ def self.set_browser(value,proxy)
130
+ file_path = File.expand_path("../../config.xml",__FILE__)
131
+ modify_attribute(file_path,"config/basic/browser","value",value)
132
+ modify_attribute(file_path,"config/basic/browser","proxy",proxy)
133
+ end
134
+ =begin
135
+ def add_browser(value,proxy)
136
+ begin
137
+ file_path = File.expand_path("../../config.xml",__FILE__)
138
+ hash = Hash.new
139
+ hash[value.to_s] = proxy
140
+ add_node(file_path,"config/basic/browser","type",hash)
141
+ rescue
142
+ error
143
+ #ensure
144
+ end
145
+ end
146
+
147
+ def delete_browser(value,proxy)
148
+ begin
149
+ file_path = File.expand_path("../../config.xml",__FILE__)
150
+ hash = Hash.new
151
+ hash[value.to_s] = proxy
152
+ delete_node(file_path,"config/basic/browser",hash)
153
+ rescue
154
+ error
155
+ #ensure
156
+ end
157
+ end
158
+ =end
159
+
160
+ #testlink modify
161
+ def self.set_testlink_host(host)
162
+ begin
163
+ file_path = File.expand_path("../../config.xml",__FILE__)
164
+ modify_attribute(file_path,"config/basic/testlink","host",host)
165
+ rescue
166
+ error
167
+ #ensure
168
+ end
169
+ end
170
+
171
+ def self.set_testlink_host_account(username)
172
+ begin
173
+ file_path = File.expand_path("../../config.xml",__FILE_)
174
+ modify_attribute(file_path,"config/basic/testlink","host_account",username)
175
+ rescue
176
+ error
177
+ #ensure
178
+ end
179
+ end
180
+
181
+ def self.set_testlink_db_account(username)
182
+ begin
183
+ file_path = File.expand_path("../../config.xml",__FILE_)
184
+ modify_attribute(file_path,"config/basic/testlink","db_account",username)
185
+ rescue
186
+ error
187
+ #ensure
188
+ end
189
+ end
190
+
191
+ def self.set_testlink_host_pwd(password)
192
+ begin
193
+ file_path = File.expand_path("../../config.xml",__FILE__)
194
+ modify_attribute(file_path,"config/basic/testlink","host_pwd",password)
195
+ rescue
196
+ error
197
+ #ensure
198
+ end
199
+ end
200
+
201
+ def self.set_testlink_db_pwd(password)
202
+ begin
203
+ file_path = File.expand_path("../../config.xml",__FILE__)
204
+ modify_attribute(file_path,"config/basic/testlink","db_pwd",password)
205
+ rescue
206
+ error
207
+ #ensure
208
+ end
209
+ end
210
+
211
+
212
+ def self.set_testlink_database(database)
213
+ begin
214
+ file_path = File.expand_path("../../config.xml",__FILE__)
215
+ modify_attribute(file_path,"config/basic/testlink","database",database)
216
+ rescue
217
+ error
218
+ #ensure
219
+ end
220
+ end
221
+
222
+ def self.set_testlink_install_path(path)
223
+ begin
224
+ file_path = File.expand_path("../../config.xml",__FILE__)
225
+ modify_attribute(file_path,"config/basic/testlink","install_path",path)
226
+ rescue
227
+ error
228
+ #ensure
229
+ end
230
+ end
231
+
232
+ #temp
233
+ def self.set_temp_path(path)
234
+ begin
235
+ file_path = File.expand_path("../../config.xml",__FILE__)
236
+ modify_attribute(file_path,"config/basic/temp","path",path)
237
+ rescue
238
+ error
239
+ #ensure
240
+ end
241
+ end
242
+
243
+ #log
244
+ def self.set_log_path(path)
245
+ begin
246
+ file_path = File.expand_path("../../config.xml",__FILE__)
247
+ modify_attribute(@file_path,"config/optional/log","path",path)
248
+ rescue
249
+ error
250
+ #ensure
251
+ end
252
+ end
253
+
254
+ #mail
255
+ def self.set_mail_start(start)
256
+ begin
257
+ file_path = File.expand_path("../../config.xml",__FILE__)
258
+ modify_attribute(file_path,"config/optional/mail","isstart",start)
259
+ rescue
260
+ error
261
+ #ensure
262
+ end
263
+ end
264
+
265
+ def self.set_mail_from_account(value)
266
+ begin
267
+ file_path = File.expand_path("../../config.xml",__FILE__)
268
+ modify_attribute(file_path,"config/optional/mail","fromaccount",value)
269
+ rescue
270
+ error
271
+ #ensure
272
+ end
273
+ end
274
+
275
+ def self.set_mail_to_account(value)
276
+ begin
277
+ file_path = File.expand_path("../../config.xml",__FILE__)
278
+ modify_attribute(file_path,"config/optional/mail","toaccount",value)
279
+ rescue
280
+ error
281
+ #ensure
282
+ end
283
+ end
284
+
285
+ #screenshot
286
+ def self.set_screenshot_start(start)
287
+ begin
288
+ file_path = File.expand_path("../../config.xml",__FILE__)
289
+ modify_attribute(file_path,"config/optional/screenshot","isstart",start)
290
+ rescue
291
+ error
292
+ #ensure
293
+ end
294
+ end
295
+
296
+ def self.set_screenshot_result_path(path)
297
+ begin
298
+ file_path = File.expand_path("../../config.xml",__FILE__)
299
+ modify_attribute(file_path,"config/optional/screenshot","path",path)
300
+ rescue
301
+ error
302
+ #ensure
303
+ end
304
+ end
305
+
306
+ #performance
307
+ def self.set_performance_start(start)
308
+ begin
309
+ file_path = File.expand_path("../../config.xml",__FILE__)
310
+ modify_attribute(file_path,"config/optional/performance","isstart",start)
311
+ rescue
312
+ error
313
+ #ensure
314
+ end
315
+ end
316
+
317
+ def self.set_performance_result_path(path)
318
+ begin
319
+ file_path = File.expand_path("../../config.xml",__FILE__)
320
+ modify_attribute(file_path,"config/optional/performance","path",path)
321
+ rescue
322
+ error
323
+ #ensure
324
+ end
325
+ end
326
+
327
+ def self.set_wait_start(start)
328
+ begin
329
+ file_path = File.expand_path("../../config.xml",__FILE__)
330
+ modify_attribute(file_path,"config/optional/wait","isstart",start)
331
+ rescue
332
+ error
333
+ #ensure
334
+ end
335
+ end
336
+
337
+ def self.set_wait_value(value)
338
+ begin
339
+ file_path = File.expand_path("../../config.xml",__FILE__)
340
+ modify_attribute(file_path,"config/optional/wait","value",value)
341
+ rescue
342
+ error
343
+ #ensure
344
+ end
345
+
346
+ end
347
+
348
+ def self.show
349
+ begin
350
+ file_path = File.expand_path("../../config.xml",__FILE__)
351
+ file = openXML(file_path)
352
+ puts 'M: Let\'s review the config file.'
353
+ puts '............................................................'
354
+ puts file
355
+ rescue
356
+ error
357
+ #ensure
358
+ end
359
+ end
360
+ end
361
+ end