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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07ed25d505b5407ecf0d6c1344907d52376b8844
4
+ data.tar.gz: 13cb468ff480d0fe00b02c91e7048fd777e769d6
5
+ SHA512:
6
+ metadata.gz: 9ae93d1eaf45444aa3813a7ef2c0add7f61bc6b2a7ff2ec2babc26eb7b3bac0b9c8a3eaf10838ff9e6a14aba864493261065b71a1a857d7b0a6a19cf720baaf3
7
+ data.tar.gz: 5112e76bb42fc1bc4d088a293fadb174296fc97629115393b531af0830707e8778976c875cff38db54d4e27ed539fe69af1fc66e330c77d4d8a7504d5b6706c2
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ #source 'https://rubygems.org'
2
+ source 'http://ruby.taobao.org/'
3
+
4
+ gem "fileutils", "~>0.7"
5
+ gem "watir-webdriver", "~>0.6.4"
6
+ gem "mysql2", "~>0.3.11"
7
+ gem "net-ssh", "~>2.6.7"
8
+ gem "net-scp", "~>1.1.1"
9
+
10
+ # Specify your gem's dependencies in magnesium.gemspec
11
+ gemspec
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ magnesium (0.0.1)
5
+
6
+ GEM
7
+ remote: http://ruby.taobao.org/
8
+ specs:
9
+ childprocess (0.3.9)
10
+ ffi (~> 1.0, >= 1.0.11)
11
+ diff-lcs (1.2.4)
12
+ ffi (1.9.0)
13
+ fileutils (0.7)
14
+ rmagick (>= 2.13.1)
15
+ multi_json (1.7.9)
16
+ mysql2 (0.3.13)
17
+ net-scp (1.1.2)
18
+ net-ssh (>= 2.6.5)
19
+ net-ssh (2.6.8)
20
+ rake (10.0.4)
21
+ rmagick (2.13.2)
22
+ rspec (2.13.0)
23
+ rspec-core (~> 2.13.0)
24
+ rspec-expectations (~> 2.13.0)
25
+ rspec-mocks (~> 2.13.0)
26
+ rspec-core (2.13.1)
27
+ rspec-expectations (2.13.0)
28
+ diff-lcs (>= 1.1.3, < 2.0)
29
+ rspec-mocks (2.13.1)
30
+ rubyzip (0.9.9)
31
+ selenium-webdriver (2.34.0)
32
+ childprocess (>= 0.2.5)
33
+ multi_json (~> 1.0)
34
+ rubyzip
35
+ websocket (~> 1.0.4)
36
+ watir-webdriver (0.6.4)
37
+ selenium-webdriver (>= 2.18.0)
38
+ websocket (1.0.7)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.3)
45
+ fileutils (~> 0.7)
46
+ magnesium!
47
+ mysql2 (~> 0.3.11)
48
+ net-scp (~> 1.1.1)
49
+ net-ssh (~> 2.6.7)
50
+ rake
51
+ rspec
52
+ watir-webdriver (~> 0.6.4)
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Meichen Zhou
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Magnesium
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'magnesium'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install magnesium
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ require 'watir-webdriver'
3
+
4
+ require File.expand_path("../magnesium/version",__FILE__)
5
+
6
+ #
7
+ # Usage 1: automatic test
8
+ #
9
+ #integrate testlink to run automatically
10
+ require File.expand_path("../magnesium/support/config",__FILE__)
11
+ require File.expand_path("../magnesium/class/testcase",__FILE__)#for simple requirement
12
+
13
+
14
+ #
15
+ # Usage 2: semiautomatic test(API)
16
+ #
17
+ #require 'watir-webdriver'
18
+ #(1)send email
19
+ # fun: a)sendMail("owa.hold.founder.com","test","This is a test e-mail message.","zhou_meichen@founder.com.cn","sun_shaohua@founder.com.cn")
20
+ require File.expand_path("../magnesium/extensions/mail",__FILE__)
21
+
22
+
23
+ #(2)ftp upload and download
24
+ # fun: a)get_login_info("172.29.135.145","user","pwd")
25
+ # b)exec_command("ls") --command
26
+ # c)upload_file("E:/test.xml","/var/www/testlink/")
27
+ # d)download_file("E:/","/var/www/testlink/test.xml")
28
+ # e)upload_folder("E:/test","/var/www/")
29
+ # f)download_folder("E:/","/var/www/test")
30
+ # g)download_file_to_memory("/var/www/test.xml")
31
+ require File.expand_path("../magnesium/extensions/ssh",__FILE__)
32
+
33
+
34
+ #(3)http get and post
35
+ # fun: a)file = http_get_xml("http://**/**")
36
+ # b)http_post_xml("url","test.xml")
37
+ require File.expand_path("../magnesium/extensions/http",__FILE__)
38
+
39
+
40
+ #(4)screenshot
41
+ # fun: a)screenshot(browser,"path/")
42
+ #require File.expand_path("../magnesium/extensions/screenshot",__FILE__)
43
+
44
+
45
+ #(5)result feedback to testlink
46
+ # fun: a)feedback("spi",1,"magnesium","p","notes") --"p" or "f"
47
+ require File.expand_path("../magnesium/extensions/feedback",__FILE__)
48
+
49
+
50
+ #(6)xml
51
+ # fun: a)file = openXML("path/test.xml")
52
+ # b)new_document(file)
53
+ # c)closeXML(file)
54
+ # d)modify_attributes("path/test.xml","config/browser","attribute","value")
55
+ require File.expand_path("../magnesium/fun/xml",__FILE__)
56
+
57
+ module Magnesium
58
+ puts 'M: Hello everyone, my name is magnesium, but you can call me little m. '
59
+ puts 'M: Now, I will help you to do Automation. '
60
+ puts 'M: Sincerely hope to have a fantastic journey all together.'
61
+ puts '............................................................'
62
+ end
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2
+ <config>
3
+ <basic>
4
+ <browser proxy="123.168.1.1" value="chrome"/>
5
+ <testlink host="127.0.0.1" host_account="zhoumc" host_pwd="zhoumc" database="testlink" db_account="zhoumc" db_pwd="zhoumc" install_path="/var/www/testlink/"/>
6
+ <temp path="/home/zhoumc/temp/"/>
7
+ </basic>
8
+
9
+ <optional>
10
+ <wait isstart="false" value="30"/>
11
+ <log isstart="false" path="/home/zhoumc/log"/>
12
+ <mail isstart="false" fromaccount="" toaccount=""/>
13
+ <screenshot isstart="false" path=""/>
14
+ <performance isstart="false" path=""/>
15
+ </optional>
16
+ </config>
@@ -0,0 +1,134 @@
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 Magnesium
11
+ class Alert
12
+ attr_accessor :box
13
+ attr_accessor :browser
14
+
15
+ def element(locate,value)
16
+ @e = @browser.alert
17
+ =begin
18
+ begin
19
+ if locate == 'id'
20
+ @e = @browser.button(:id => value.to_s)
21
+ elsif locate == 'name'
22
+ @e = @browser.button(:name => value.to_s)
23
+ elsif locate == 'index'
24
+ @e = @browser.button(:index => value.to_i)
25
+ elsif locate == 'text'
26
+ @e = @browser.button(:text => value.to_s)
27
+ else
28
+ nonfun
29
+ #puts 'M: I need time to grow up.'
30
+ end
31
+ rescue
32
+ error
33
+ #ensure
34
+ end
35
+ =end
36
+ end
37
+
38
+ def execute(action,data)
39
+ begin
40
+ if action == 'text'
41
+ if Config.config["wait"]["isstart"] == "true"
42
+ return @e.when_present(Config.config["wait"]["value"].to_i).text
43
+ elsif Config.config["wait"]["isstart"] == "false"
44
+ return @e.text
45
+ else
46
+ # error
47
+ puts '...'
48
+ end
49
+ elsif action == 'exists'
50
+ if Config.config["wait"]["isstart"] == "true"
51
+ return @e.when_present(Config.config["wait"]["value"].to_i).exists?
52
+ elsif Config.config["wait"]["isstart"] == "false"
53
+ return @e.exists?
54
+ else
55
+ # error
56
+ puts '...'
57
+ end
58
+ elsif action == 'ok'
59
+ if Config.config["wait"]["isstart"] == "true"
60
+ return @e.when_present(Config.config["wait"]["value"].to_i).ok
61
+ elsif Config.config["wait"]["isstart"] == "false"
62
+ return @e.ok
63
+ else
64
+ # error
65
+ puts '...'
66
+ end
67
+ elsif action == 'close'
68
+ if Config.config["wait"]["isstart"] == "true"
69
+ return @e.when_present(Config.config["wait"]["value"].to_i).close
70
+ elsif Config.config["wait"]["isstart"] == "false"
71
+ return @e.close
72
+ else
73
+ # error
74
+ puts '...'
75
+ end
76
+ elsif action == 'set'
77
+ if Config.config["wait"]["isstart"] == "true"
78
+ return @e.when_present(Config.config["wait"]["value"].to_i).set data.to_s
79
+ elsif Config.config["wait"]["isstart"] == "false"
80
+ return @e.set data.to_s
81
+ else
82
+ # error
83
+ puts '...'
84
+ end
85
+ elsif action == 'wait_until_present'
86
+ return @e.wait_until_present
87
+ elsif action == 'wait_while_present'
88
+ return @e.wait_while_present
89
+ else
90
+ # nonfun
91
+ puts '...'
92
+ end
93
+ #rescue
94
+ # error
95
+ #ensure
96
+ end
97
+ end
98
+ =begin
99
+ def setbox(box)
100
+ @box = box
101
+ end
102
+
103
+ def getbox()
104
+ return @box
105
+ end
106
+
107
+ def setbrowser(browser)
108
+ @browser = browser
109
+ end
110
+
111
+ def getbrowser()
112
+ return @browser
113
+ end
114
+ =end
115
+ def generate()
116
+ unless @box.empty?
117
+ @box.collect do |f|
118
+ if f["name"] == 'frame'
119
+ @browser = dealframe(@browser,f["locate"],f["value"])
120
+ elsif f["name"] == 'div'
121
+ @browser = dealdiv(@browser,f["locate"],f["value"])
122
+ elsif f["name"] == 'span'
123
+ @browser = dealspan(@browser,f["locate"],f["value"])
124
+ elsif f["name"] == 'table'
125
+ @browser = dealtable(@browser,f["locate"],f["value"])
126
+ else
127
+ # nonfun
128
+ puts '...'
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,29 @@
1
+ require 'watir-wedriver'
2
+ require File.expand_path("../../support/config",__FILE__)
3
+
4
+ module Magnesium
5
+ class Browser
6
+ # attr_accessor :box
7
+ attr_accessor :browser
8
+
9
+ def initialize(type)
10
+ if type == "chrome"
11
+ @browser = Watir::Browser.new :chrome
12
+ elsif type == "ie"
13
+ @browser = Watir::Browser.new :ie
14
+ elsif type == "firefox"
15
+ @browser = Watir::Browser.new
16
+ else
17
+ nonfun
18
+ end
19
+ end
20
+
21
+ def goto(url)
22
+ @browser.goto url.to_s
23
+ end
24
+
25
+ def close()
26
+ @browser.close
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,104 @@
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 Magnesium
11
+ class Button
12
+ attr_accessor :box
13
+ attr_accessor :browser
14
+
15
+ def element(locate,value)
16
+ begin
17
+ if locate == 'id'
18
+ @e = @browser.button(:id => value.to_s)
19
+ elsif locate == 'name'
20
+ @e = @browser.button(:name => value.to_s)
21
+ elsif locate == 'index'
22
+ @e = @browser.button(:index => value.to_i)
23
+ elsif locate == 'text'
24
+ @e = @browser.button(:text => value.to_s)
25
+ else
26
+ puts '...'
27
+ #nonfun
28
+ end
29
+ #rescue
30
+ # error
31
+ #ensure
32
+ end
33
+ end
34
+
35
+ def execute(action,data)
36
+ begin
37
+ if action == 'click'
38
+ if Config.config["wait"]["isstart"] == "true"
39
+ return @e.when_present(Config.config["wait"]["value"].to_i).click
40
+ elsif Config.config["wait"]["isstart"] == "false"
41
+ return @e.click
42
+ else
43
+ #error
44
+ puts '...'
45
+ end
46
+ elsif action == 'exists'
47
+ if Config.config["wait"]["isstart"] == "true"
48
+ return @e.when_present(Config.config["wait"]["value"].to_i).exists?
49
+ elsif Config.config["wait"]["isstart"] == "false"
50
+ return @e.exists?
51
+ else
52
+ puts '...'
53
+ #error
54
+ end
55
+ elsif action == 'wait_until_present'
56
+ return @e.wait_until_present
57
+ elsif action == 'wait_while_present'
58
+ return @e.wait_while_present
59
+ else
60
+ puts '...'
61
+ # nonfun
62
+ end
63
+ # rescue
64
+ # error
65
+ #ensure
66
+ end
67
+ end
68
+ =begin
69
+ def setbox(box)
70
+ @box = box
71
+ end
72
+
73
+ def getbox()
74
+ return @box
75
+ end
76
+
77
+ def setbrowser(browser)
78
+ @browser = browser
79
+ end
80
+
81
+ def getbrowser()
82
+ return @browser
83
+ end
84
+ =end
85
+ def generate()
86
+ unless @box.empty?
87
+ @box.collect do |f|
88
+ if f["name"] == 'frame'
89
+ @browser = dealframe(@browser,f["locate"],f["value"])
90
+ elsif f["name"] == 'div'
91
+ @browser = dealdiv(@browser,f["locate"],f["value"])
92
+ elsif f["name"] == 'span'
93
+ @browser = dealspan(@browser,f["locate"],f["value"])
94
+ elsif f["name"] == 'table'
95
+ @browser = dealtable(@browser,f["locate"],f["value"])
96
+ else
97
+ # nonfun
98
+ puts '...'
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end