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.
- checksums.yaml +7 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/magnesium.rb +62 -0
- data/lib/magnesium/config.xml +16 -0
- data/lib/magnesium/elements/alert.rb +134 -0
- data/lib/magnesium/elements/browser.rb +29 -0
- data/lib/magnesium/elements/button.rb +104 -0
- data/lib/magnesium/elements/checkbox.rb +103 -0
- data/lib/magnesium/elements/div.rb +120 -0
- data/lib/magnesium/elements/frame.rb +121 -0
- data/lib/magnesium/elements/link.rb +105 -0
- data/lib/magnesium/elements/radio.rb +103 -0
- data/lib/magnesium/elements/select_list.rb +103 -0
- data/lib/magnesium/elements/span.rb +116 -0
- data/lib/magnesium/elements/table.rb +121 -0
- data/lib/magnesium/elements/text.rb +109 -0
- data/lib/magnesium/elements/text_field.rb +109 -0
- data/lib/magnesium/extensions/assert.rb +2 -0
- data/lib/magnesium/extensions/feedback.rb +25 -0
- data/lib/magnesium/extensions/http.rb +48 -0
- data/lib/magnesium/extensions/mail.rb +26 -0
- data/lib/magnesium/extensions/scheduler.rb +32 -0
- data/lib/magnesium/extensions/ssh.rb +53 -0
- data/lib/magnesium/extensions/webservice.rb +0 -0
- data/lib/magnesium/factor/test_case.rb +124 -0
- data/lib/magnesium/factor/test_data.rb +32 -0
- data/lib/magnesium/factor/test_result.rb +84 -0
- data/lib/magnesium/factor/test_site.rb +23 -0
- data/lib/magnesium/factor/test_step.rb +31 -0
- data/lib/magnesium/factor/test_ui.rb +55 -0
- data/lib/magnesium/support/config.rb +361 -0
- data/lib/magnesium/support/container.rb +18 -0
- data/lib/magnesium/support/data.rb +11 -0
- data/lib/magnesium/support/error.rb +16 -0
- data/lib/magnesium/support/factory.rb +43 -0
- data/lib/magnesium/support/log.rb +3 -0
- data/lib/magnesium/support/testlink.rb +270 -0
- data/lib/magnesium/support/xml.rb +73 -0
- data/lib/magnesium/version.rb +3 -0
- data/magnesium.gemspec +24 -0
- data/spec/runspec.rb +0 -0
- data/template.yml +57 -0
- metadata +134 -0
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'watir-webdriver'
|
3
|
+
require File.expand_path("../frame", __FILE__)
|
4
|
+
require File.expand_path("../div", __FILE__)
|
5
|
+
require File.expand_path("../span", __FILE__)
|
6
|
+
require File.expand_path("../table", __FILE__)
|
7
|
+
#require File.expand_path("../../support/error", __FILE__)
|
8
|
+
#require File.expand_path("../../support/config", __FILE__)
|
9
|
+
|
10
|
+
#module TextField
|
11
|
+
module Magnesium
|
12
|
+
class TextField
|
13
|
+
attr_accessor :box
|
14
|
+
attr_accessor :browser
|
15
|
+
|
16
|
+
def element(locate,value)
|
17
|
+
begin
|
18
|
+
if locate == 'id'
|
19
|
+
@e = @browser.text_field(:id => value.to_s)
|
20
|
+
elsif locate == 'name'
|
21
|
+
@e = @browser.text_field(:name => value.to_s)
|
22
|
+
elsif locate == 'index'
|
23
|
+
@e = @browser.text_field(:index => value.to_i)
|
24
|
+
else
|
25
|
+
# nonfun
|
26
|
+
puts 'M: I need time to grow up.'
|
27
|
+
end
|
28
|
+
# rescue
|
29
|
+
# error
|
30
|
+
#ensure
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute(action,data)
|
35
|
+
begin
|
36
|
+
if action == 'set'
|
37
|
+
if Config.config["wait"]["isstart"] == "true"
|
38
|
+
return @e.when_present(Config.config["wait"]["value"].to_i).set data.to_s
|
39
|
+
elsif Config.config["wait"]["isstart"] == "false"
|
40
|
+
return @e.set data.to_s
|
41
|
+
else
|
42
|
+
puts 'error'
|
43
|
+
end
|
44
|
+
elsif action == 'send_keys'
|
45
|
+
if Config.config["wait"]["isstart"] == "true"
|
46
|
+
return @e.when_present(Config.config["wait"]["value"].to_i).send_keys data.to_s
|
47
|
+
elsif Config.config["wait"]["isstart"] == "false"
|
48
|
+
return @e.send_keys data.to_s
|
49
|
+
else
|
50
|
+
puts 'error'
|
51
|
+
end
|
52
|
+
elsif action == 'exists'
|
53
|
+
if Config.config["wait"]["isstart"] == "true"
|
54
|
+
return @e.when_present(Config.config["wait"]["value"].to_i).exists?
|
55
|
+
elsif Config.config["wait"]["isstart"] == "false"
|
56
|
+
return @e.exists?
|
57
|
+
else
|
58
|
+
puts 'error'
|
59
|
+
end
|
60
|
+
elsif action == 'wait_until_present'
|
61
|
+
return @e.wait_until_present
|
62
|
+
elsif action == 'wait_while_present'
|
63
|
+
return @e.wait_while_present
|
64
|
+
else
|
65
|
+
#nonfun
|
66
|
+
puts 'M: I need time to grow up.'
|
67
|
+
end
|
68
|
+
#rescue
|
69
|
+
# error
|
70
|
+
#ensure
|
71
|
+
end
|
72
|
+
end
|
73
|
+
=begin
|
74
|
+
def setbox(box)
|
75
|
+
@box = box
|
76
|
+
end
|
77
|
+
|
78
|
+
def getbox()
|
79
|
+
return @box
|
80
|
+
end
|
81
|
+
|
82
|
+
def setbrowser(browser)
|
83
|
+
@browser = browser
|
84
|
+
end
|
85
|
+
|
86
|
+
def getbrowser(browser)
|
87
|
+
return @browser
|
88
|
+
end
|
89
|
+
=end
|
90
|
+
def generate()
|
91
|
+
unless @box.empty?
|
92
|
+
@box.collect do |f|
|
93
|
+
if f["name"] == 'frame'
|
94
|
+
@browser = dealframe(@browser,f["locate"],f["value"])
|
95
|
+
elsif f["name"] == 'div'
|
96
|
+
@browser = dealdiv(@browser,f["locate"],f["value"])
|
97
|
+
elsif f["name"] == 'span'
|
98
|
+
@browser = dealspan(@browser,f["locate"],f["value"])
|
99
|
+
elsif f["name"] == 'table'
|
100
|
+
@browser = dealtable(@browser,f["locate"],f["value"])
|
101
|
+
else
|
102
|
+
#nonfun
|
103
|
+
puts '...'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path("../../support/testlink",__FILE__)
|
2
|
+
|
3
|
+
module Magnesium
|
4
|
+
class Feedback
|
5
|
+
|
6
|
+
def initialize(prefix,caseno,login,status,notes)
|
7
|
+
begin
|
8
|
+
@id = TestLink.find_max_id("executions").to_i+1
|
9
|
+
@build_id = TestLink.find_build(prefix)
|
10
|
+
@tester_id = TestLink.find_tester(login)
|
11
|
+
@testplan_id = TestLink.find_testplan(prefix)
|
12
|
+
@tcversion_id = TestLink.find_tcversion_id(caseno)
|
13
|
+
@tcversion_number = TestLink.find_tcversion_number(caseno)
|
14
|
+
@platform_id = TestLink.find_platform_id
|
15
|
+
@execution_type = TestLink.find_execution_type
|
16
|
+
|
17
|
+
execute = TestLink.query("insert into executions values(#{@id},#{@build_id},#{@tester_id},now(),'#{status}',#{@testplan_id},#{@tcversion_id},#{@tcversion_number},#{@platform_id},#{@execution_type},'#{notes}')")
|
18
|
+
# rescue
|
19
|
+
# error
|
20
|
+
#puts 'feedback'
|
21
|
+
#ensure
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require File.expand_path("../../support/config",__FILE__)
|
5
|
+
require 'rexml/document'
|
6
|
+
include REXML
|
7
|
+
|
8
|
+
module Magnesium
|
9
|
+
class Http
|
10
|
+
attr_accessor :url
|
11
|
+
attr_accessor :filepath
|
12
|
+
|
13
|
+
def self.get_xml
|
14
|
+
begin
|
15
|
+
uri = URI.parse(@url)
|
16
|
+
req = Net::HTTP::Get.new(uri.path)
|
17
|
+
|
18
|
+
req.content_type = 'text/xml'
|
19
|
+
|
20
|
+
http = Net::HTTP.new(uri.host,uri.port)
|
21
|
+
|
22
|
+
request = http.start {|h| h.request(req)}
|
23
|
+
#return xml file
|
24
|
+
return request.read_body
|
25
|
+
rescue
|
26
|
+
error
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.post_xml
|
31
|
+
begin
|
32
|
+
file = File.read(@filepath)
|
33
|
+
|
34
|
+
uri = URI.parse(@url)
|
35
|
+
req = Net::HTTP::Post.new(uri.path)
|
36
|
+
|
37
|
+
req.body = file
|
38
|
+
req.content_type = 'text/xml'
|
39
|
+
|
40
|
+
http = Net::HTTP.new(uri.host,uri.port)
|
41
|
+
|
42
|
+
http.start{|h| h.request(req)}
|
43
|
+
rescue
|
44
|
+
error
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#require File.expand_path("../../support/config",__FILE__)
|
2
|
+
require 'net/smtp'
|
3
|
+
|
4
|
+
module Magnesium
|
5
|
+
class Mail
|
6
|
+
attr_accessor :server
|
7
|
+
attr_accessor :subject
|
8
|
+
attr_accessor :msg
|
9
|
+
attr_accessor :from
|
10
|
+
attr_accessor :to
|
11
|
+
|
12
|
+
def self.send #(server,subject,msg,from,to)
|
13
|
+
message = <<MESSAGE_END
|
14
|
+
From: <#{@from}>
|
15
|
+
To: <#{@to}>
|
16
|
+
Subject: #{@subject}
|
17
|
+
|
18
|
+
#{@msg}
|
19
|
+
MESSAGE_END
|
20
|
+
|
21
|
+
Net::SMTP.start('#{@server}') do |smtp|
|
22
|
+
smtp.send_message message, '#{@from}', '#{@to}'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rufus/scheduler'
|
2
|
+
|
3
|
+
module Magnesium
|
4
|
+
class scheduler
|
5
|
+
attr_accessor :period
|
6
|
+
attr_accessor :execute
|
7
|
+
|
8
|
+
def self.every #(period,execute)
|
9
|
+
scheduler.every '#{@period}' do
|
10
|
+
@execute
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.in #(period,execute)
|
15
|
+
scheduler.in '#{@period}' do
|
16
|
+
@execute
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.at #(period,execute)
|
21
|
+
scheduler.at '#{@period}' do
|
22
|
+
@execute
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.cron #(period,execute)
|
27
|
+
scheduler.cron '#{@period}' do
|
28
|
+
@execute
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'net/scp'
|
3
|
+
|
4
|
+
module Magnesium
|
5
|
+
class SSH
|
6
|
+
attr_accessor :host
|
7
|
+
attr_accessor :username
|
8
|
+
attr_accessor :pwd
|
9
|
+
attr_accessor :local
|
10
|
+
attr_accessor :server
|
11
|
+
|
12
|
+
def exec_command(command)
|
13
|
+
Net::SSH.start(@host, @username, :password => @pwd) do |ssh|
|
14
|
+
result = ssh.exec!(command.to_s)
|
15
|
+
return result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def upload_file
|
20
|
+
Net::SCP.start(@host, @username, :password => @pwd) do |scp|
|
21
|
+
scp.upload!(@local,@server) do |ch, name, sent, total|
|
22
|
+
puts "\r#{name}:#{(sent.to_f * 100 / total.to_f).to_i}%"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def download_file #(local,server)
|
28
|
+
Net::SCP.start(@host, @username, :password => @pwd) do |scp|
|
29
|
+
scp.download!(@server,@local) do |ch, name, sent, total|
|
30
|
+
puts "\r#{name}:#{(sent.to_f * 100 / total.to_f).to_i}%"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def upload_folder #(local,server)
|
36
|
+
Net::SSH.start(@host, @username, :password => @pwd) do |ssh|
|
37
|
+
ssh.scp.upload!(@local,@server,:recursive => true)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def download_folder #(local,server)
|
42
|
+
Net::SSH.start(@host, @username, :password => @pwd) do |ssh|
|
43
|
+
ssh.scp.download!(@local,@server,:recursive => true)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def download_file_to_memory #(server)
|
48
|
+
Net::SCP.start(@host, @username, :password => @pwd) do |scp|
|
49
|
+
return scp.download!(@server),to_yaml
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
File without changes
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#require 'fileutils'
|
4
|
+
require File.expand_path("../../factor/test_data",__FILE__)
|
5
|
+
require File.expand_path("../../factor/test_ui",__FILE__)
|
6
|
+
require File.expand_path("../../factor/test_site",__FILE__)
|
7
|
+
require File.expand_path("../../factor/test_step",__FILE__)
|
8
|
+
require File.expand_path("../../factor/test_result",__FILE__)
|
9
|
+
require File.expand_path("../../support/factory",__FILE__)
|
10
|
+
#require File.expand_path("../../extensions/browser",__FILE__)
|
11
|
+
#require File.expand_path("../../support/error",__FILE__)
|
12
|
+
#require File.expand_path("../../extensions/js",__FILE__)
|
13
|
+
|
14
|
+
module Magnesium
|
15
|
+
class Testcase
|
16
|
+
include TestData
|
17
|
+
include TestSite
|
18
|
+
include TestStep
|
19
|
+
include TestResult
|
20
|
+
include TestUI
|
21
|
+
def initialize(p,c)
|
22
|
+
@prefix = p
|
23
|
+
@caseno = c
|
24
|
+
new_folder("#{Config.config["temp"]}nodes_hierarchy")
|
25
|
+
#new folder id
|
26
|
+
new_folder("#{Config.config["temp"]}#{TestLink.find_path(@prefix,@caseno).split(/\//)[0]}/#{TestLink.find_path(@prefix,@caseno).split(/\//)[1]}")
|
27
|
+
|
28
|
+
|
29
|
+
#download attachment
|
30
|
+
ssh = SSH.new
|
31
|
+
ssh.host = Config.config["testlink"]["host"]
|
32
|
+
ssh.username = Config.config["testlink"]["host_account"]
|
33
|
+
ssh.pwd = Config.config["testlink"]["host_pwd"]
|
34
|
+
ssh.local ="#{Config.config["temp"]}#{TestLink.find_path(@prefix,@caseno).split(/\//)[0]}/#{TestLink.find_path(@prefix,@caseno).split(/\//)[1]}/"
|
35
|
+
ssh.server = "#{Config.config["testlink"]["install_path"]}upload_area/#{TestLink.find_path(@prefix,@caseno)}"
|
36
|
+
ssh.download_file
|
37
|
+
|
38
|
+
#factor
|
39
|
+
@data = generate_data(@prefix,@caseno)
|
40
|
+
# @data.prefix = @prefix
|
41
|
+
# @data.caseno = @caseno
|
42
|
+
# @data.generate
|
43
|
+
@ui = generate_UI(@prefix,@caseno)
|
44
|
+
@site = generate_site(@prefix,@caseno)
|
45
|
+
@step = generate_step(@prefix,@caseno)
|
46
|
+
@expected_result = get_expected_result(@prefix,@caseno)
|
47
|
+
end
|
48
|
+
|
49
|
+
def new_folder(path)
|
50
|
+
if (File.exist? path)
|
51
|
+
puts "folder exist!"
|
52
|
+
else
|
53
|
+
Dir.mkdir(path)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def run() #1
|
58
|
+
begin #2
|
59
|
+
@data.each do |data_key,data_value| #3
|
60
|
+
browser_type = Config.config["browser"]["value"]
|
61
|
+
@browser = Watir::Browser.new :chrome if browser_type == "chrome"
|
62
|
+
@step.each do |step_key,step_value| #4
|
63
|
+
@tempdata = data_value.hash[step_key] unless data_value.hash[step_key].nil?
|
64
|
+
|
65
|
+
unless step_value.to_s.eql? 'goto' #5
|
66
|
+
@ui.each do |ui_key,ui_value|
|
67
|
+
@temptype = ui_value.container_type
|
68
|
+
@temptitle = ui_value.container_title #if popup
|
69
|
+
#
|
70
|
+
unless ui_value.hash_element[step_key].nil?
|
71
|
+
@tempelement = ui_value.hash_element[step_key]
|
72
|
+
@templocate = ui_value.hash_locate[step_key]
|
73
|
+
@tempvalue = ui_value.hash_value[step_key]
|
74
|
+
@tempaction = ui_value.hash_action[step_key]
|
75
|
+
unless ui_value.hash_box[step_key].nil?
|
76
|
+
@tempbox = ui_value.hash_box[step_key]
|
77
|
+
else
|
78
|
+
@tempbox = Array.new
|
79
|
+
end
|
80
|
+
break
|
81
|
+
end
|
82
|
+
#
|
83
|
+
end #ui
|
84
|
+
|
85
|
+
#real run
|
86
|
+
unless @tempelement.eql? 'js'
|
87
|
+
fa = Factory.creator(@tempelement)
|
88
|
+
fa.box = @tempbox
|
89
|
+
fa.browser = @browser
|
90
|
+
fa.generate
|
91
|
+
fa.element(@templocate,@tempvalue)
|
92
|
+
if @temptype == 'common'
|
93
|
+
fa.execute(@tempaction,@tempdata)
|
94
|
+
else
|
95
|
+
dealpopup(@browser,@temptitle,fa,@tempaction,@tempdata)
|
96
|
+
end
|
97
|
+
else
|
98
|
+
#if js has nothing to do with frame
|
99
|
+
#if popip has no js
|
100
|
+
#TODO
|
101
|
+
execute_js(@browser,@tempvalue)
|
102
|
+
end #unless js
|
103
|
+
|
104
|
+
#end of real run
|
105
|
+
else #5
|
106
|
+
@browser.goto @site[step_key].to_s
|
107
|
+
#gotoBrowser(@browser,@site[step_key].to_s)
|
108
|
+
end #5
|
109
|
+
end #4
|
110
|
+
#generate result
|
111
|
+
get_real_result(@prefix,@caseno,@browser)
|
112
|
+
#end of per data test
|
113
|
+
@browser.close
|
114
|
+
# closeBrowser(@browser)
|
115
|
+
end #3
|
116
|
+
#delete temp fodler
|
117
|
+
FileUtils.rm_rf "#{Config.config["temp"]}nodes_hierarchy/"
|
118
|
+
#end #3
|
119
|
+
# rescue
|
120
|
+
# error
|
121
|
+
end #2
|
122
|
+
end #1
|
123
|
+
end #class
|
124
|
+
end #magnesium
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path("../../support/data",__FILE__)
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Magnesium
|
7
|
+
module TestData
|
8
|
+
def generate_data(prefix,caseno)
|
9
|
+
@hash = Hash.new
|
10
|
+
|
11
|
+
yaml = YAML.load(File.open("#{Config.config["temp"]}#{TestLink.find_path(prefix,caseno)}"))
|
12
|
+
yaml["data"].collect do |row|
|
13
|
+
@data = TD.new
|
14
|
+
@hash_temp = Hash.new
|
15
|
+
@mark = nil
|
16
|
+
row["testdata"].each do |k,v|
|
17
|
+
if k == 'value'
|
18
|
+
v.collect do |d|
|
19
|
+
@hash_temp[d["element"]] = d["value"]
|
20
|
+
end
|
21
|
+
elsif k == 'mark'
|
22
|
+
@mark = v
|
23
|
+
end
|
24
|
+
end
|
25
|
+
@data.mark = @mark
|
26
|
+
@data.hash = @hash_temp
|
27
|
+
@hash[@mark] = @data
|
28
|
+
end
|
29
|
+
return @hash
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|