puppet7 0.2.0.beta1

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.
@@ -0,0 +1,302 @@
1
+ # coding: utf-8
2
+
3
+ module Puppet7
4
+ module SeleniumLocatorActions
5
+ def get_attribute attrname
6
+ selenium {|s| s.get_attribute("#{@xpath}@#{attrname}")}
7
+ end
8
+ alias_method :attr, :get_attribute
9
+
10
+ def add_selection
11
+ selenium {|s| s.add_selection @xpath}
12
+ end
13
+
14
+ def assign_id id
15
+ selenium {|s| s.assign_id @xpath, id}
16
+ end
17
+
18
+
19
+ def attach_file fileLocator
20
+ selenium {|s| s.attach_file @xpath, fileLocator}
21
+ end
22
+
23
+ def check
24
+ selenium {|s| s.check @xpath}
25
+ end
26
+
27
+ def click
28
+ selenium {|s| s.click @xpath}
29
+ end
30
+
31
+ def click_n_wait what=:page, *args
32
+ selenium do |s|
33
+ s.click @xpath
34
+ case what
35
+ when :page then s.wait_for_page_to_load
36
+ when :element then s.wait_for_element *args
37
+ end
38
+ end
39
+ end
40
+
41
+ def click_at coordString
42
+ selenium {|s| s.click_at @xpath, coordString}
43
+ end
44
+
45
+ def context_menu
46
+ selenium {|s| s.context_menu @xpath}
47
+ end
48
+
49
+ def context_menu_at coordString
50
+ selenium {|s| s.context_menu @xpath, coordString}
51
+ end
52
+
53
+ def double_click
54
+ selenium {|s| s.double_click @xpath}
55
+ end
56
+
57
+ def double_click_at coordString
58
+ selenium {|s| s.double_click @xpath, coordString}
59
+ end
60
+
61
+ def drag_and_drop movementsString
62
+ selenium {|s| s.drag_and_drop @xpath, movementsString}
63
+ end
64
+
65
+ def drag_and_drop_to_object destLocator
66
+ selenium {|s| s.drag_and_drop_to_object @xpath, get_locator(destLocator)}
67
+ end
68
+
69
+ def fire_event eventName
70
+ selenium {|s| s.fire_event(@xpath, eventName)}
71
+ end
72
+
73
+ def focus
74
+ selenium {|s| s.focus @xpath}
75
+ end
76
+
77
+ def get_element_height
78
+ selenium {|s| s.get_element_height(@xpath).to_i}
79
+ end
80
+ alias_method :height, :get_element_height
81
+
82
+ def get_element_index
83
+ selenium {|s| s.get_element_index(@xpath).to_i}
84
+ end
85
+ alias_method :index, :get_element_index
86
+
87
+ def get_element_position_left
88
+ selenium {|s| s.get_element_position_left(@xpath).to_i}
89
+ end
90
+ alias_method :left, :get_element_position_left
91
+
92
+ def get_element_position_top
93
+ selenium {|s| s.get_element_position_top(@xpath).to_i}
94
+ end
95
+ alias_method :top, :get_element_position_top
96
+
97
+ def get_element_width
98
+ selenium {|s| s.get_element_width(@xpath).to_i}
99
+ end
100
+ alias_method :width, :get_element_width
101
+
102
+ def get_select_options
103
+ selenium {|s| s.get_select_options @xpath}
104
+ end
105
+ alias_method :select_options, :get_select_options
106
+
107
+ def get_selected_id
108
+ selenium {|s| s.get_selected_id @xpath}
109
+ end
110
+ alias_method :selected_id, :get_selected_id
111
+
112
+ def get_selected_ids
113
+ selenium {|s| s.get_selected_ids @xpath}
114
+ end
115
+ alias_method :selected_ids, :get_selected_ids
116
+
117
+ def get_selected_index
118
+ selenium {|s| s.get_selected_index @xpath}
119
+ end
120
+ alias_method :selected_index, :get_selected_index
121
+
122
+ def get_selected_indexes
123
+ selenium {|s| s.get_selected_indexes @xpath}
124
+ end
125
+ alias_method :selected_indexes, :get_selected_indexes
126
+
127
+ def get_selected_label
128
+ selenium {|s| s.get_selected_label @xpath}
129
+ end
130
+ alias_method :selected_label, :get_selected_label
131
+
132
+ def get_selected_labels
133
+ selenium {|s| s.get_selected_labels @xpath}
134
+ end
135
+ alias_method :selected_labels, :get_selected_labels
136
+
137
+ def get_selected_value
138
+ selenium {|s| s.get_selected_value @xpath}
139
+ end
140
+ alias_method :selected_value, :get_selected_value
141
+
142
+ def get_selected_values
143
+ selenium {|s| s.get_selected_values @xpath}
144
+ end
145
+ alias_method :selected_values, :get_selected_values
146
+
147
+ def get_text
148
+ selenium {|s| s.get_text(@xpath).force_encoding(@parent.page.encoding)}
149
+ end
150
+
151
+ alias_method :text, :get_text
152
+
153
+ def get_value
154
+ selenium {|s| s.get_value @xpath}
155
+ end
156
+ alias_method :value, :get_value
157
+
158
+ def get_xpath_count
159
+ selenium {|s| s.get_xpath_count(@xpath).to_i}
160
+ end
161
+ alias_method :count, :get_xpath_count
162
+ alias_method :length, :get_xpath_count
163
+
164
+ def highlight
165
+ selenium {|s| s.highlight @xpath}
166
+ end
167
+
168
+ def is_checked
169
+ selenium {|s| s.is_checked(@xpath)}
170
+ end
171
+
172
+ alias_method :checked?, :is_checked
173
+
174
+ def is_editable
175
+ selenium {|s| s.is_editable(@xpath)}
176
+ end
177
+ alias_method :editable?, :is_editable
178
+
179
+ def is_element_present
180
+ selenium {|s| s.is_element_present @xpath}
181
+ end
182
+
183
+ alias_method :element?, :is_element_present
184
+
185
+ def is_ordered otherLocator
186
+ selenium {|s| s.is_ordered @xpath, get_locator(otherLocator)}
187
+ end
188
+
189
+ alias_method :ordered?, :is_ordered
190
+
191
+ def is_something_selected
192
+ selenium {|s| s.is_something_selected(@xpath)}
193
+ end
194
+
195
+ def is_visible
196
+ selenium {|s| s.is_visible @xpath}
197
+ end
198
+
199
+ alias_method :visible?, :is_visible
200
+
201
+ def key_down keySequence
202
+ selenium {|s| s.key_down(@xpath, keySequence)}
203
+ end
204
+
205
+ def key_press keySequence
206
+ selenium {|s| s.key_press(@xpath, keySequence)}
207
+ end
208
+
209
+ def key_up keySequence
210
+ selenium {|s| s.key_up(@xpath, keySequence)}
211
+ end
212
+
213
+ def mouse_down
214
+ selenium {|s| s.mouse_down @xpath}
215
+ end
216
+
217
+ def mouse_down_at coordString
218
+ selenium {|s| s.mouse_down_at(@xpath, coordString)}
219
+ end
220
+
221
+ def mouse_down_right
222
+ selenium {|s| s.mouse_down_right @xpath}
223
+ end
224
+
225
+ def mouse_down_right_at coordString
226
+ selenium {|s| s.mouse_down_right_at @xpath, coordString}
227
+ end
228
+
229
+ def mouse_move
230
+ selenium {|s| s.mouse_move @xpath}
231
+ end
232
+
233
+ def mouse_move_at coordString
234
+ selenium {|s| s.mouse_move_at @xpath, coordString}
235
+ end
236
+
237
+ def mouse_out
238
+ selenium {|s| s.mouse_out @xpath}
239
+ end
240
+
241
+ def mouse_over
242
+ selenium {|s| s.mouse_over @xpath}
243
+ end
244
+
245
+ def mouse_up
246
+ selenium {|s| s.mouse_up @xpath}
247
+ end
248
+
249
+ def mouse_up_at coordString
250
+ selenium {|s| s.mouse_up_at @xpath, coordString}
251
+ end
252
+
253
+ def mouse_up_right
254
+ selenium {|s| s.mouse_up_right @xpath}
255
+ end
256
+
257
+ def mouse_up_right_at coordString
258
+ selenium {|s| s.mouse_up_right_at @xpath, coordString}
259
+ end
260
+
261
+ def remove_all_selections
262
+ selenium {|s| s.remove_all_selections @xpath}
263
+ end
264
+
265
+ def remove_selection optionLocator
266
+ selenium {|s| s.remove_selection @xpath, get_locator(optionLocator)}
267
+ end
268
+
269
+ def select optionLocator
270
+ selenium {|s| s.select @xpath, get_locator(optionLocator)}
271
+ end
272
+
273
+ def select_frame
274
+ selenium {|s| s.select_frame @xpath}
275
+ end
276
+
277
+ def submit
278
+ selenium {|s| s.submit @xpath}
279
+ end
280
+
281
+ def type value
282
+ selenium {|s| s.type @xpath, value}
283
+ end
284
+
285
+ def type_keys value
286
+ selenium {|s| s.type_keys @xpath, value}
287
+ end
288
+
289
+ def uncheck
290
+ selenium {|s| s.uncheck @xpath}
291
+ end
292
+
293
+ private
294
+ def get_locator locator
295
+ if locator === Puppet7::Element
296
+ locator.xpath
297
+ else
298
+ locator.to_s
299
+ end
300
+ end
301
+ end
302
+ end
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+
3
+ require "selenium/client"
4
+
5
+ module Puppet7
6
+
7
+ # Selenium Client Configure
8
+ #
9
+ # default is ...
10
+ # {
11
+ # :host => 'localhost',
12
+ # :port => 4444,
13
+ # :browser => '*firefox',
14
+ # :timeout_in_seconds => 15,
15
+ # :highlight_located_element => true
16
+ # }
17
+ #
18
+ class SeleniumSupport
19
+ def self.init_selenium user_configs={}
20
+ begin
21
+ selenium_config = Puppet7.configuration.selenium_configs.merge(user_configs)
22
+ selenium = Selenium::Client::Driver.new selenium_config
23
+ selenium.javascript_extension = extension_script
24
+ selenium.start
25
+ selenium.window_maximize
26
+ #selenium.set_speed 100
27
+ selenium
28
+ rescue => err
29
+ raise SeleniumInitError.new("Fail to initialize selenium : #{err}")
30
+ end
31
+ end
32
+
33
+ def self.javascript_dir
34
+ File.join File.dirname(__FILE__), "javascript"
35
+ end
36
+
37
+ def self.extension_script
38
+ line_buff = []
39
+ File.open(File.join(javascript_dir, "json.js")).each_line do |line|
40
+ line_buff << line
41
+ end
42
+ File.open(File.join(javascript_dir, "on_page_loading.js")).each_line do |line|
43
+ line_buff << line
44
+ end
45
+ Puppet7.configuration.js_ext_files.each do |file|
46
+ if File.exist?(file)
47
+ File.open(file).each_line {|line| line_buff << line}
48
+ end
49
+ end
50
+ File.open(File.join(javascript_dir, "selenium_extension.js")).each_line do |line|
51
+ line_buff << line
52
+ end
53
+ line_buff.join()
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,98 @@
1
+ # coding: utf-8
2
+
3
+
4
+ require "puppet7/extend"
5
+ require "puppet7/sql_exec"
6
+
7
+ module Puppet7
8
+ class SQLAgent
9
+ attr_reader :files, :sqllist, :types, :dao
10
+ SqlInfo = Struct.new(:id, :type, :sql)
11
+
12
+ def initialize sqlexec, dir
13
+ if RUBY_VERSION < "1.9"
14
+ raise "#{self.class} support ruby1.9 or greater. but you have #{RUBY_VERSION} version of ruby"
15
+ end
16
+ @files = []
17
+ @sqllist = {}
18
+ @types = [:list, :row, :value, :execute]
19
+ @sqlexec = sqlexec
20
+ load_files dir
21
+ end
22
+
23
+ private
24
+
25
+ def load_files dir
26
+ Dir.new(dir).each do |file|
27
+ next if file =~ /^\./
28
+ next unless file =~ /\.sqldef$/
29
+ path = File.join(dir,file)
30
+ if File.directory?(path)
31
+ load_files path
32
+ else
33
+ load_sql path
34
+ end
35
+ end
36
+ end
37
+
38
+ def load_sql file
39
+ sqlcnt = 0
40
+ sql_id = nil
41
+ type = nil
42
+ File.open(file).each_line do |line|
43
+ if sql_id
44
+ if line.strip =~ /^\// # end of sql
45
+ @sqllist[sql_id].sql = @sqllist[sql_id].sql.join("\n")
46
+ create_method @sqllist[sql_id]
47
+ sql_id= nil
48
+ type=nil
49
+ sqlcnt += 1
50
+ else
51
+ @sqllist[sql_id].sql << line.strip
52
+ end
53
+ else
54
+ next if line.strip =~/^\#/ # comment line
55
+ next if line.strip.eql?("")
56
+ if line =~ /@(.+):([^\s]+)/ # sql definition
57
+ sql_id = $1.to_sym
58
+ type = $2.to_sym
59
+ throw "Unknown Type : #{type.to_s} in line(#{$.})" unless @types.include?(type)
60
+ @sqllist[sql_id] = SqlInfo.new(sql_id,type,[])
61
+ else
62
+ throw "Wrong SQL Definition : line(#{$.})"
63
+ end
64
+ end
65
+ end
66
+ if sql_id
67
+ throw "Unexpected end of sql : line(#{$.})"
68
+ end
69
+ @files << file
70
+ end
71
+
72
+ def create_method sqlInfo
73
+ method_def = []
74
+ method_def << "def #{sqlInfo.id} params={}"
75
+ method_def << "sqlInfo = @sqllist['#{sqlInfo.id}'.to_sym]"
76
+ case sqlInfo.type
77
+ when :list
78
+ method_def << "if block_given?"
79
+ method_def << " @sqlexec.select_all(sqlInfo.sql, params) {|row| yield row}"
80
+ method_def << "else"
81
+ method_def << " @sqlexec.select_all(sqlInfo.sql, params)"
82
+ method_def << "end"
83
+ when :row
84
+ method_def << "@sqlexec.select_row(sqlInfo.sql, params)"
85
+ when :value
86
+ method_def << "@sqlexec.select_value(sqlInfo.sql, params)"
87
+ when :execute
88
+ method_def << "@sqlexec.execute(sqlInfo.sql, params)"
89
+ end
90
+ method_def << "end"
91
+ self.class.class_eval(method_def.join("\n"))
92
+ end
93
+
94
+ def method_missing sym, *args, &b
95
+ try_pending "Undefined Databaseaccess : #{sym}"
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,148 @@
1
+ # coding: utf-8
2
+
3
+ require "dbi"
4
+
5
+ module Puppet7
6
+ class SQLExec
7
+ attr_reader :db_url, :user, :password, :encoding
8
+
9
+ def initialize db_url, user, passwd, encoding = "utf8"
10
+ if RUBY_VERSION < "1.9"
11
+ raise "#{self.class} support ruby1.9 or greater. but you have #{RUBY_VERSION} version of ruby"
12
+ end
13
+ @db_url, @user, @password = db_url, user, passwd
14
+ @encoding = encoding
15
+ end
16
+
17
+ def select_all sql, params={}
18
+ result = []
19
+ connect do |dbh|
20
+ prep_sql, binds = parameterize(sql, params)
21
+ sth = dbh.prepare(prep_sql)
22
+ sth.execute(*binds)
23
+ record = self.class.record(sth.column_names)
24
+ sth.fetch do |row|
25
+ r = record.new(*row.to_a.collect{|c|
26
+ if String === c
27
+ c.force_encoding(encode_str)
28
+ else
29
+ c
30
+ end
31
+ })
32
+ if block_given?
33
+ yield r
34
+ else
35
+ result << r
36
+ end
37
+ end
38
+ end
39
+ return result
40
+ end
41
+
42
+ def select_row sql, params={}
43
+ connect do |dbh|
44
+ prep_sql, binds = parameterize(sql, params)
45
+ sth = dbh.prepare(prep_sql)
46
+ sth.execute(*binds)
47
+ record = self.class.record(sth.column_names)
48
+ return record.new(*sth.fetch.to_a)
49
+ end
50
+ end
51
+
52
+ def select_value sql, params={}
53
+ connect do |dbh|
54
+ prep_sql, binds = parameterize(sql, params)
55
+ sth = dbh.prepare(prep_sql)
56
+ sth.execute(*binds)
57
+ return sth.fetch[sth.column_names[0]]
58
+ end
59
+ end
60
+
61
+ def execute sql, params={}
62
+ connect do |dbh|
63
+ prep_sql, binds = parameterize(sql, params)
64
+ sth = dbh.prepare(prep_sql)
65
+ sth.execute(*binds)
66
+ return sth.rows
67
+ end
68
+ end
69
+
70
+ def tables
71
+ tables =nil
72
+ connect do |dbh|
73
+ tables = dbh.tables
74
+ end
75
+ return tables
76
+ end
77
+
78
+ def table_encoding table_name
79
+ sql = "select coll.character_set_name
80
+ from information_schema.tables tabs
81
+ join information_schema.collations coll
82
+ on tabs.table_collation = coll.collation_name
83
+ where table_name = &table
84
+ and table_schema = &db"
85
+ select_value(sql, {:table=>table_name, :db=>@database})
86
+ end
87
+
88
+ def connect
89
+ unless @dbh && @dbh.connected?
90
+ @dbh = DBI.connect @db_url, @user, @password
91
+ @dbh.execute("set names #{@encoding.to_s}") # for mysql
92
+ end
93
+ if block_given?
94
+ yield @dbh
95
+ #dbh.disconnect
96
+ else
97
+ @dbh
98
+ end
99
+ end
100
+
101
+ private
102
+ def parameterize sql, params={}
103
+ mod_sql = "#{sql}"
104
+ params.each_pair do |pname, pvalue|
105
+ mod_sql.gsub!(/\$#{pname}[^a-zA-Z0-9._-]?/, pvalue.to_s)
106
+ end
107
+ bindvars = []
108
+ sqlsplit = []
109
+ sqlsplit << mod_sql.gsub(/(.*?)(\&[a-zA-Z][a-zA-Z0-9._-]*)/m) do |param|
110
+ sqlsplit << $1
111
+ sqlsplit << $2
112
+ ""
113
+ end
114
+ sqlsplit.collect! do |token|
115
+ if token =~ /^\&(.+)/
116
+ raise "No Value for '#{$1}" unless params.member?($1.to_sym)
117
+ value = params[$1.to_sym]
118
+ value = _encode(value) if value.kind_of? String
119
+ bindvars << value
120
+ "?"
121
+ else
122
+ _encode token
123
+ end
124
+ end
125
+
126
+ [sqlsplit.join, bindvars]
127
+ end
128
+
129
+ def self.record columns
130
+ @__records ||= {}
131
+ colsyms = columns.collect{|a| a.downcase.force_encoding(__ENCODING__).to_sym}
132
+ @__records[colsyms] ||= Struct.new(*colsyms)
133
+ @__records[colsyms]
134
+ end
135
+
136
+ def _encode str
137
+ str.encode(encode_str)
138
+ end
139
+
140
+ def encode_str
141
+ case @encoding.to_sym
142
+ when :utf8 then "UTF-8"
143
+ when :euckr then "EUC-KR"
144
+ else @encoding.to_s
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,72 @@
1
+ # coding: utf-8
2
+
3
+ require "nokogiri/css"
4
+
5
+ module Puppet7
6
+ module Utils
7
+ URLInfo = Struct.new :url, :protocol, :baseurl, :domain, :port, :path, :query, :query_str
8
+ def parse_url url
9
+ urlinfo = URLInfo.new
10
+ urlinfo.url = url
11
+ if url =~ /^(http|https):\/\/([\w\d\.\_\-]+)(:\d+)?(\/[^?]*)(\?.*)?$/
12
+ urlinfo.protocol = $1
13
+ urlinfo.domain = $2
14
+ urlinfo.baseurl = "#{$1}://#{$2}#{$3}"
15
+ urlinfo.port = $3 || ""
16
+ urlinfo.path = $4 || ""
17
+ urlinfo.query_str = $5 || ""
18
+ elsif url =~ /^(\/[^\?]*)(\?.*)?$/
19
+ urlinfo.protocol = nil
20
+ urlinfo.domain = nil
21
+ urlinfo.baseurl = nil
22
+ urlinfo.port = nil
23
+ urlinfo.path = $1 || ""
24
+ urlinfo.query_str = $2 || ""
25
+ elsif url =~ /^(http|https):\/\/([\w\d\.\_\-]+)(:\d+)?$/
26
+ urlinfo.protocol = $1
27
+ urlinfo.domain = $2
28
+ urlinfo.baseurl = "#{$1}://#{$2}#{$3}"
29
+ urlinfo.port = $3 || ""
30
+ urlinfo.path = nil
31
+ urlinfo.query_str = ""
32
+ else
33
+ raise "Unexpected URL : #{url}"
34
+ end
35
+
36
+ # process query string
37
+ urlinfo.query = {}
38
+ urlinfo.query_str.gsub(/^\?/, "").split(/&/).each do |qr|
39
+ name, value = qr.split("=")
40
+ next unless name
41
+ value = value || ""
42
+ if urlinfo.query[name.to_sym]
43
+ urlinfo.query[name.to_sym] = [] << urlinfo.query[name.to_sym]
44
+ urlinfo.query[name.to_sym] << value
45
+ else
46
+ urlinfo.query[name.to_sym] = value
47
+ end
48
+ end
49
+ urlinfo
50
+ end
51
+
52
+ def by_xpath str
53
+ str
54
+ end
55
+
56
+ def by_id id
57
+ "//*[@id='#{id}']"
58
+ end
59
+
60
+ def by_link link_text
61
+ "//a[text()='#{link_text}']"
62
+ end
63
+
64
+ def by_input input_name
65
+ "//input[@name='#{input_name}']"
66
+ end
67
+
68
+ def by_css css_selector
69
+ Nokogiri::CSS.xpath_for(css_selector).first
70
+ end
71
+ end
72
+ end
data/lib/puppet7.rb ADDED
@@ -0,0 +1,28 @@
1
+ # coding:utf-8
2
+
3
+ require "puppet7/configuration"
4
+ require 'puppet7/utils'
5
+ require "puppet7/puppet"
6
+
7
+ require 'puppet7/extend'
8
+ require 'puppet7/selenium_actions'
9
+ require 'puppet7/selenium_locator_actions'
10
+ require 'puppet7/element'
11
+ require 'puppet7/page_part'
12
+ require 'puppet7/page'
13
+ require 'puppet7/domain'
14
+ require "puppet7/selenium_support"
15
+ require "puppet7/puppet_formatter"
16
+ require "puppet7/puppet_report"
17
+ require "puppet7/exceptions"
18
+ require "puppet7/configuration"
19
+
20
+ begin
21
+ # optional loading...
22
+ gem "dbi"
23
+ require "puppet7/sql_exec"
24
+ require "puppet7/sql_agent"
25
+ rescue GEM::LoadError
26
+ end
27
+
28
+