parfait 0.8.0
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/lib/parfait/application.rb +140 -0
- data/lib/parfait/control.rb +413 -0
- data/lib/parfait/page.rb +226 -0
- data/lib/parfait/region.rb +267 -0
- data/lib/parfait.rb +376 -0
- metadata +63 -0
data/lib/parfait.rb
ADDED
@@ -0,0 +1,376 @@
|
|
1
|
+
require 'watir-webdriver'
|
2
|
+
require 'parfait/application'
|
3
|
+
require 'parfait/page'
|
4
|
+
require 'parfait/region'
|
5
|
+
require 'parfait/control'
|
6
|
+
|
7
|
+
# [cat] something
|
8
|
+
# something else
|
9
|
+
#
|
10
|
+
#
|
11
|
+
# * Top level comment about Parfait
|
12
|
+
module Parfait
|
13
|
+
|
14
|
+
# Global hash containing each Parfait::Page object indexed by page name (and alias)
|
15
|
+
PAGES = Hash.new
|
16
|
+
|
17
|
+
|
18
|
+
# Configure the logging routine to be used by Parfait
|
19
|
+
#
|
20
|
+
# The routine you store here can be invoked by Parfait.log
|
21
|
+
#
|
22
|
+
# *Options*
|
23
|
+
#
|
24
|
+
# +&block+:: specifies the code block to be called whenever Parfait needs to invoke a logger. This block should take a string followed by an optional hash as its parameters.
|
25
|
+
#
|
26
|
+
# *Example*
|
27
|
+
#
|
28
|
+
# Parfait.set_logroutine { |string,opts|
|
29
|
+
# MyLogger::write(string,opts)
|
30
|
+
# }
|
31
|
+
def Parfait.set_logroutine(&block)
|
32
|
+
Thread.current[:parfait_logroutine] = block
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# Write to the Parfait log
|
37
|
+
#
|
38
|
+
# The log can be predefined by Parfait.set_logroutine
|
39
|
+
#
|
40
|
+
# *Options*
|
41
|
+
#
|
42
|
+
# +string+:: specifies the string to write to the Parfait log
|
43
|
+
# +opts+:: specifies a hash containing parameters to the Parfait logging function
|
44
|
+
#
|
45
|
+
# *Example*
|
46
|
+
#
|
47
|
+
# Parfait.log("Everything is fine - no bugs here.",:style => fatal_error)
|
48
|
+
def Parfait.log(string,opts = {})
|
49
|
+
return Thread.current[:parfait_logroutine].call(string,opts)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# Define a new page to Parfait
|
54
|
+
#
|
55
|
+
# *Options*
|
56
|
+
#
|
57
|
+
# +name+:: specifies the name of the page
|
58
|
+
# +aliases+:: is an array of aliases for the page
|
59
|
+
#
|
60
|
+
# Note that the type of these values does not matter as long as they are used consistently throughout. All examples provided with Parfait use strings.
|
61
|
+
#
|
62
|
+
# *Example*
|
63
|
+
#
|
64
|
+
# edit_user = Parfait.add_page(
|
65
|
+
# :name => "Edit User",
|
66
|
+
# :alias => "New User", "User New", "User Edit"
|
67
|
+
# )
|
68
|
+
def Parfait.add_page(opts = {})
|
69
|
+
o = {
|
70
|
+
:name => :notspecified,
|
71
|
+
:aliases => :notspecified
|
72
|
+
}.merge(opts)
|
73
|
+
name = o[:name]
|
74
|
+
aliases = o[:aliases]
|
75
|
+
|
76
|
+
new_page = Parfait::Page.new(name)
|
77
|
+
|
78
|
+
Parfait::PAGES[name] = new_page
|
79
|
+
unless aliases == :notspecified
|
80
|
+
aliases.each { |an_alias|
|
81
|
+
Parfait::PAGES[an_alias] = new_page
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
return new_page
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
# Retrieve a page object by name or alias
|
90
|
+
#
|
91
|
+
# Intended for internal use only
|
92
|
+
#
|
93
|
+
# *Options*
|
94
|
+
#
|
95
|
+
# +name+:: specifies the name or alias of the page
|
96
|
+
#
|
97
|
+
# *Example*
|
98
|
+
#
|
99
|
+
# Parfait.get_page("User New")
|
100
|
+
def Parfait.get_page(name)
|
101
|
+
page_name = Parfait::PAGES[name]
|
102
|
+
if page_name
|
103
|
+
return page_name
|
104
|
+
else
|
105
|
+
raise "Parfait::get_page called for invalid page name \"#{page_name}\""
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
# Set the value for a specified control on a specified page
|
111
|
+
#
|
112
|
+
# Parfait.set is only intended to be invoked from page directive routines, like retrieve, update, confirm, and verify. It does not invoke the logger.
|
113
|
+
#
|
114
|
+
# *Options*
|
115
|
+
#
|
116
|
+
# Parfait.set takes a hash as a parameter with the +:onpage+ key specifying the page to be manipulated. Users can utilize additional keys as they wish. A simple invocation of Parfait.set might contain an additional key matching the label of a control on that page and providing a value to set in that control.
|
117
|
+
#
|
118
|
+
# *Example*
|
119
|
+
#
|
120
|
+
# Parfait.set(:onpage => "Login", :username => "enrico_palazzo")
|
121
|
+
def Parfait.set(opts = {})
|
122
|
+
o = {
|
123
|
+
:onpage => :nopage
|
124
|
+
}.merge(opts)
|
125
|
+
|
126
|
+
if o[:onpage] == :nopage
|
127
|
+
raise "Parfait::set must be called with \":onpage\" specified."
|
128
|
+
end
|
129
|
+
|
130
|
+
# Find the specified control and invoke its set method
|
131
|
+
action_taken = false
|
132
|
+
page = Parfait::get_page(o[:onpage])
|
133
|
+
opts.each { |label,value|
|
134
|
+
control = page.get_control(label)
|
135
|
+
unless control == nil
|
136
|
+
control.set(opts)
|
137
|
+
action_taken = true
|
138
|
+
end
|
139
|
+
}
|
140
|
+
unless action_taken
|
141
|
+
raise "No valid control was passed to Parfait::set"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
# Retreive the value from a specified control on a specified page and return it
|
147
|
+
#
|
148
|
+
# *Options*
|
149
|
+
#
|
150
|
+
# The Parfait.retrieve directive takes a hash as a parameter with an +:onpage+ key specifying the current page. The system-generated Parfait.retrieve directive will also take a +:data+ key specfying the control on that page from which data should be retrieved. Users can override the system-generated directive and use any keys they wish.
|
151
|
+
#
|
152
|
+
# The system-generated retrieve directive does not invoke the logger.
|
153
|
+
#
|
154
|
+
# *Example*
|
155
|
+
#
|
156
|
+
# my_ssn = Parfait.retrieve(:onpage => "User Data", :data => :ssn)
|
157
|
+
def Parfait.retrieve(opts = {})
|
158
|
+
o = {
|
159
|
+
:onpage => :nopage
|
160
|
+
}.merge(opts)
|
161
|
+
|
162
|
+
if o[:onpage] == :nopage
|
163
|
+
raise "Parfait::retrieve must be called with \":onpage\" specified."
|
164
|
+
end
|
165
|
+
|
166
|
+
# Find the specified control and invoke its retrieve method
|
167
|
+
action_taken = false
|
168
|
+
page = Parfait::get_page(o[:onpage])
|
169
|
+
opts.each { |label,value|
|
170
|
+
if label == :data
|
171
|
+
control = page.get_control(value)
|
172
|
+
unless control == nil
|
173
|
+
return control.retrieve(opts)
|
174
|
+
action_taken = true
|
175
|
+
end
|
176
|
+
end
|
177
|
+
}
|
178
|
+
unless action_taken
|
179
|
+
raise "No valid control was passed to Parfait::retrieve"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
# Update the value of a specified control on a specified page.
|
185
|
+
#
|
186
|
+
# *Options*
|
187
|
+
#
|
188
|
+
# The Parfait.update directive takes a hash as a parameter with an +:onpage+ key specifying the current page. The system-generated Parfait.update directive will also take a key matching the label of a control on that page and providing a value to set in that control. Users can override the system-generated directive and use any keys they wish.
|
189
|
+
#
|
190
|
+
# The system-generated update directive will log both the original value and the newly updated value. It is assumed that users overriding the system-generated functionality will do the same.
|
191
|
+
#
|
192
|
+
# *Example*
|
193
|
+
#
|
194
|
+
# Parfait.update(:onpage => "Configure Settings", :time_zone => "Eastern Time (US & Canada)")
|
195
|
+
def Parfait.update(opts = {})
|
196
|
+
o = {
|
197
|
+
:onpage => :nopage
|
198
|
+
}.merge(opts)
|
199
|
+
|
200
|
+
if o[:onpage] == :nopage
|
201
|
+
raise "Parfait::update must be called with \":onpage\" specified."
|
202
|
+
end
|
203
|
+
|
204
|
+
# Find the specified control and invoke its update method
|
205
|
+
retval = nil
|
206
|
+
action_taken = false
|
207
|
+
page = Parfait::get_page(o[:onpage])
|
208
|
+
opts.each { |label,value|
|
209
|
+
control = page.get_control(label)
|
210
|
+
unless control == nil
|
211
|
+
retval = control.update(opts)
|
212
|
+
action_taken = true
|
213
|
+
end
|
214
|
+
}
|
215
|
+
unless action_taken
|
216
|
+
raise "No valid control was passed to Parfait::update"
|
217
|
+
end
|
218
|
+
retval
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
# Verify the value of a specified control on a specified page, returning +true+ if it matches the provided value and raising an exception if it does not.
|
223
|
+
#
|
224
|
+
# *Options*
|
225
|
+
#
|
226
|
+
# The Parfait.verify directive takes a hash as a parameter with an +:onpage+ key specifying the current page. The system-generated Parfait.verify directive will also take a key matching the label of a control on that page and providing a value against which to verify the current value of that control. Users can override the system-generated directive and use any keys they wish.
|
227
|
+
#
|
228
|
+
# The system-generated verify directive will log the successfully verified value. It is assumed that users overriding the system-generated functionality will do the same.
|
229
|
+
#
|
230
|
+
# *Example*
|
231
|
+
#
|
232
|
+
# Parfait.verify(:onpage => "Edit User", :social_security_number => "123-45-6789")
|
233
|
+
def Parfait.verify(opts = {})
|
234
|
+
o = {
|
235
|
+
:onpage => :nopage
|
236
|
+
}.merge(opts)
|
237
|
+
|
238
|
+
if o[:onpage] == :nopage
|
239
|
+
raise "Parfait::verify must be called with \":onpage\" specified."
|
240
|
+
end
|
241
|
+
|
242
|
+
page = Parfait::get_page(o[:onpage])
|
243
|
+
|
244
|
+
if opts.size == 1 #If no other parameters were passed, run the page test
|
245
|
+
if page.page_test()
|
246
|
+
Parfait.log("Verified that browser is on page \"#{page.name}\"",:style => :h2)
|
247
|
+
else
|
248
|
+
raise "Parfait expected browser to be on page #{page.name}, but it wasn\'t"
|
249
|
+
end
|
250
|
+
else
|
251
|
+
# Find the specified control and invoke its verify method
|
252
|
+
action_taken = false
|
253
|
+
opts.each { |label,value|
|
254
|
+
control = page.get_control(label)
|
255
|
+
unless control == nil
|
256
|
+
control.verify(opts)
|
257
|
+
action_taken = true
|
258
|
+
end
|
259
|
+
}
|
260
|
+
unless action_taken
|
261
|
+
raise "No valid control was passed to Parfait::verify"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
true
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
# Confirm the value of a specified control on a specified page, returning +true+ if it matches the provided value and returning +false+ otherwise.
|
269
|
+
#
|
270
|
+
# *Options*
|
271
|
+
#
|
272
|
+
# The Parfait.confirm directive takes a hash as a parameter with an +:onpage+ key specifying the current page. The system-generated Parfait.confirm directive will also take a key matching the label of a control on that page and providing a value against which to test the current value of that control. Users can override the system-generated directive and use any keys they wish.
|
273
|
+
#
|
274
|
+
# The system-generated confirm directive does not invoke the logger.
|
275
|
+
#
|
276
|
+
# *Example*
|
277
|
+
#
|
278
|
+
# Parfait.confirm(:onpage => "Edit User", :gender => "female")
|
279
|
+
def Parfait.confirm(opts = {})
|
280
|
+
o = {
|
281
|
+
:onpage => :nopage
|
282
|
+
}.merge(opts)
|
283
|
+
|
284
|
+
if o[:onpage] == :nopage
|
285
|
+
raise "Parfait::confirm must be called with \":onpage\" specified."
|
286
|
+
end
|
287
|
+
|
288
|
+
page = Parfait::get_page(o[:onpage])
|
289
|
+
|
290
|
+
retval = false
|
291
|
+
if opts.size == 1 #If no other parameters were passed, run the page test
|
292
|
+
return page.page_test()
|
293
|
+
else
|
294
|
+
# Find the specified control and invoke its confirm method
|
295
|
+
action_taken = false
|
296
|
+
opts.each { |label,value|
|
297
|
+
control = page.get_control(label)
|
298
|
+
unless control == nil
|
299
|
+
retval = control.confirm(opts)
|
300
|
+
action_taken = true
|
301
|
+
end
|
302
|
+
}
|
303
|
+
if action_taken
|
304
|
+
return retval
|
305
|
+
else
|
306
|
+
raise "No valid control was passed to Parfait::confirm"
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
|
312
|
+
# Method description
|
313
|
+
#
|
314
|
+
# *Options*
|
315
|
+
#
|
316
|
+
# +option+:: specifies something
|
317
|
+
#
|
318
|
+
# *Example*
|
319
|
+
#
|
320
|
+
# $$$ Need an example $$$
|
321
|
+
def Parfait.navigate(opts = {})
|
322
|
+
o = {
|
323
|
+
:onpage => :nopage,
|
324
|
+
:to => :nodestination
|
325
|
+
}.merge(opts)
|
326
|
+
|
327
|
+
if o[:to] == :nodestination
|
328
|
+
raise "Parfait::navigate must be called with a destination (\":to\") specified."
|
329
|
+
end
|
330
|
+
|
331
|
+
if o[:onpage] == :nopage
|
332
|
+
#Only a target was specified
|
333
|
+
page = Parfait::get_page("All Pages")
|
334
|
+
else
|
335
|
+
page = Parfait::get_page(o[:onpage])
|
336
|
+
end
|
337
|
+
page.navigate(opts)
|
338
|
+
end
|
339
|
+
|
340
|
+
|
341
|
+
# Set the browser object (for the current thread) for Parfait to use
|
342
|
+
#
|
343
|
+
# *Options*
|
344
|
+
#
|
345
|
+
# +browser+:: specifies the browser to store
|
346
|
+
#
|
347
|
+
# *Example*
|
348
|
+
#
|
349
|
+
# Parfait::set_browser(browser)
|
350
|
+
#
|
351
|
+
def Parfait.set_browser(browser)
|
352
|
+
Thread.current[:parfait_browser] = browser
|
353
|
+
Thread.current[:parfait_region] = browser
|
354
|
+
end
|
355
|
+
|
356
|
+
|
357
|
+
# Get the current browser object (for the current thread) from Parfait
|
358
|
+
#
|
359
|
+
# Note that inside regions, this may be a Selenium object and not the
|
360
|
+
# selenium browser pointer (i.e. a subset of the page instead of the
|
361
|
+
# whole page)
|
362
|
+
#
|
363
|
+
# *Options*
|
364
|
+
#
|
365
|
+
# none
|
366
|
+
#
|
367
|
+
# *Example*
|
368
|
+
#
|
369
|
+
# Parfait::browser
|
370
|
+
#
|
371
|
+
def Parfait.browser()
|
372
|
+
Thread.current[:parfait_region]
|
373
|
+
end
|
374
|
+
|
375
|
+
|
376
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parfait
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Rotter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A base set of test operations for verification of web pages and the controls
|
28
|
+
therein
|
29
|
+
email: jeremy.rotter@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/parfait.rb
|
35
|
+
- lib/parfait/application.rb
|
36
|
+
- lib/parfait/control.rb
|
37
|
+
- lib/parfait/page.rb
|
38
|
+
- lib/parfait/region.rb
|
39
|
+
homepage: ''
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.4.6
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Parfait
|
63
|
+
test_files: []
|