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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c35819f92d949b909c2178dacdff7caa9fe40c4
|
4
|
+
data.tar.gz: d8dceab268f4ab11dd69a518810ebd5c006b4659
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 049efbccf79d1f8eea86d5206a431f2c78381c81f8f58f1fadfe4c9bc5f3ddec58ce84b7ad0a36a0afc4df6d56614abb6b0a01a9c3a4a8f6b9dcab7252074587
|
7
|
+
data.tar.gz: b4ced0aeac0417e23d60966408b74e5e1e18964371e20b9f46b98e9c5acb8914df2669afa752f90434aa86e8bfe02e11cb1a520c1a10ebf0e2c61bd864bac31b
|
@@ -0,0 +1,140 @@
|
|
1
|
+
module Parfait
|
2
|
+
|
3
|
+
class Application
|
4
|
+
|
5
|
+
# Define an application
|
6
|
+
#
|
7
|
+
# *Options*
|
8
|
+
#
|
9
|
+
# Takes a hash as input where the current options are:
|
10
|
+
# +name+:: specifies the name of the application
|
11
|
+
# - +:browser+ optionally specifies the browser object used in the current thread. Storing this value will allow the browser object to be retrieved via +Parfait.browser+ invocation when defining +get+ and +set+ routines for controls.
|
12
|
+
#
|
13
|
+
# *Example*
|
14
|
+
#
|
15
|
+
# mybrowser = Watir::Browser.new()
|
16
|
+
# Parfait::Application.new(
|
17
|
+
# :name => "Blog",
|
18
|
+
# :browser => mybrowser
|
19
|
+
# )
|
20
|
+
#
|
21
|
+
def initialize(opts = {})
|
22
|
+
o = {
|
23
|
+
:name => nil,
|
24
|
+
:browser => nil
|
25
|
+
}.merge(opts)
|
26
|
+
|
27
|
+
@name = o[:name]
|
28
|
+
raise "Application name must be specified" unless @name
|
29
|
+
|
30
|
+
set_browser(o[:browser])
|
31
|
+
|
32
|
+
@pages = Hash.new
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# Set the browser object for the current thread.
|
37
|
+
#
|
38
|
+
# *Options*
|
39
|
+
#
|
40
|
+
# none
|
41
|
+
#
|
42
|
+
# *Example*
|
43
|
+
#
|
44
|
+
# b = Watir::browser.new
|
45
|
+
# myapplication.set_browser(b)
|
46
|
+
#
|
47
|
+
def set_browser(browser)
|
48
|
+
Thread.current[:parfait_browser] = browser
|
49
|
+
unless Thread.current[:parfait_browser] == nil or
|
50
|
+
Thread.current[:parfait_browser].is_a?(Watir::Browser)
|
51
|
+
raise "Parfait browser parameter must be a Watir Browser object"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# Get the browser object used by the current thread.
|
57
|
+
#
|
58
|
+
# This will be particularly useful when defining directives for a Parfait::Control.
|
59
|
+
#
|
60
|
+
# *Options*
|
61
|
+
#
|
62
|
+
# none
|
63
|
+
#
|
64
|
+
# *Example*
|
65
|
+
#
|
66
|
+
# mycontrol.add_get{ |opts|
|
67
|
+
# Parfait::browser.text_field(:id => "body").when_present.value
|
68
|
+
# }
|
69
|
+
def browser()
|
70
|
+
#If the browser is non-nil, then it passed validation in the configure method
|
71
|
+
unless Thread.current[:parfait_browser]
|
72
|
+
raise "Parfait: browser requested, but it is undefined"
|
73
|
+
end
|
74
|
+
Thread.current[:parfait_browser]
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
# Add a page to this Application
|
79
|
+
#
|
80
|
+
# *Options*
|
81
|
+
#
|
82
|
+
# +page+:: specifies a Parfait::Page object
|
83
|
+
#
|
84
|
+
# *Example*
|
85
|
+
#
|
86
|
+
# blog_posts = Parfait::Page.new(:name => "Blog Posts")
|
87
|
+
# blogapp.add_page(blog_posts)
|
88
|
+
#
|
89
|
+
def add_page(page)
|
90
|
+
|
91
|
+
if page
|
92
|
+
if page.is_a?(Parfait::Page)
|
93
|
+
@pages[page.name] = page
|
94
|
+
if page.aliases
|
95
|
+
page.aliases.each do |my_alias|
|
96
|
+
@pages[my_alias] = page
|
97
|
+
end
|
98
|
+
end
|
99
|
+
else
|
100
|
+
raise "Page must be a Parfait::Page when being adding to an application"
|
101
|
+
end
|
102
|
+
else
|
103
|
+
raise "Page must be specified when adding a page to an application"
|
104
|
+
end
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
# Retrieve a page object by name or alias.
|
110
|
+
#
|
111
|
+
# Under the covers, if there is an existence directive defined for this
|
112
|
+
# page, it will be run on the current browser to confirm that we are
|
113
|
+
# indeed on it.
|
114
|
+
#
|
115
|
+
# *Options*
|
116
|
+
#
|
117
|
+
# +name+:: specifies the name or alias of the page
|
118
|
+
#
|
119
|
+
# *Example*
|
120
|
+
#
|
121
|
+
# myapp.page("Login Page")
|
122
|
+
def page(requested_name)
|
123
|
+
page = @pages[requested_name]
|
124
|
+
if page
|
125
|
+
# Confirm that we are on the requested page
|
126
|
+
|
127
|
+
# Pass the browser through to any subsequently called methods
|
128
|
+
Thread.current[:parfait_region] = Thread.current[:parfait_browser]
|
129
|
+
|
130
|
+
return page
|
131
|
+
else
|
132
|
+
raise "Invalid page name requested: \"#{requested_name}\""
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
@@ -0,0 +1,413 @@
|
|
1
|
+
module Parfait
|
2
|
+
|
3
|
+
class Control
|
4
|
+
|
5
|
+
attr_reader :name,
|
6
|
+
:aliases
|
7
|
+
|
8
|
+
# Create a new control object
|
9
|
+
#
|
10
|
+
# *Options*
|
11
|
+
#
|
12
|
+
# +name+:: the name used to identify this control
|
13
|
+
# +logtext+:: the text to be used when referring to this control in logs
|
14
|
+
# +aliases+:: specifies an array of aliases for the control
|
15
|
+
#
|
16
|
+
# *Example*
|
17
|
+
#
|
18
|
+
# newcontrol = Parfait::Control.new(
|
19
|
+
# :name => "User ID",
|
20
|
+
# :logtext = "user ID"
|
21
|
+
# )
|
22
|
+
def initialize(opts = {})
|
23
|
+
o = {
|
24
|
+
:name => nil,
|
25
|
+
:logtext => nil,
|
26
|
+
:aliases => []
|
27
|
+
}.merge(opts)
|
28
|
+
@name = o[:name]
|
29
|
+
@aliases = o[:aliases]
|
30
|
+
@logtext = o[:logtext]
|
31
|
+
|
32
|
+
@set_method = nil
|
33
|
+
@get_method = nil
|
34
|
+
@update_method = nil
|
35
|
+
@retrieve_method = nil
|
36
|
+
@verify_method = nil
|
37
|
+
@confirm_method = nil
|
38
|
+
@goto_method = nil
|
39
|
+
@navigate_method = nil
|
40
|
+
|
41
|
+
if @name
|
42
|
+
unless @name.is_a?(String)
|
43
|
+
raise "Name must be a String when adding a control"
|
44
|
+
end
|
45
|
+
else
|
46
|
+
raise "Name must be specified when adding a control"
|
47
|
+
end
|
48
|
+
if @logtext
|
49
|
+
unless @logtext.is_a?(String)
|
50
|
+
raise "Logtext must be a String when adding a control"
|
51
|
+
end
|
52
|
+
else
|
53
|
+
raise "Logtext must be specified when adding a control"
|
54
|
+
end
|
55
|
+
if @aliases
|
56
|
+
unless @aliases.is_a?(Array)
|
57
|
+
raise "Parfait::Control requires aliases to be an array"
|
58
|
+
end
|
59
|
+
@aliases.each do |my_alias|
|
60
|
+
raise "Parfait::Control requires each alias in the array to be a string" unless my_alias.is_a?(String)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
# Method description
|
67
|
+
#
|
68
|
+
# *Options*
|
69
|
+
#
|
70
|
+
# +option+:: specifies something
|
71
|
+
#
|
72
|
+
# *Example*
|
73
|
+
#
|
74
|
+
# $$$ Need an example $$$
|
75
|
+
def get(opts = {})
|
76
|
+
return @get_method.call(opts)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# Set the value for this control
|
81
|
+
#
|
82
|
+
# *Options*
|
83
|
+
#
|
84
|
+
# +value+:: specifies the value that this control will be set to
|
85
|
+
#
|
86
|
+
# *Example*
|
87
|
+
#
|
88
|
+
# $$$ Need an example $$$
|
89
|
+
def set(value,opts = {})
|
90
|
+
@set_method.call(value,opts)
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
# Method description
|
95
|
+
#
|
96
|
+
# *Options*
|
97
|
+
#
|
98
|
+
# +option+:: specifies something
|
99
|
+
#
|
100
|
+
# *Example*
|
101
|
+
#
|
102
|
+
# $$$ Need an example $$$
|
103
|
+
def retrieve(opts = {})
|
104
|
+
return @retrieve_method.call(opts)
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
# Method description
|
109
|
+
#
|
110
|
+
# *Options*
|
111
|
+
#
|
112
|
+
# +option+:: specifies something
|
113
|
+
#
|
114
|
+
# *Example*
|
115
|
+
#
|
116
|
+
# $$$ Need an example $$$
|
117
|
+
def update(value,opts = {})
|
118
|
+
@update_method.call(value,opts)
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# Method description
|
123
|
+
#
|
124
|
+
# *Options*
|
125
|
+
#
|
126
|
+
# +option+:: specifies something
|
127
|
+
#
|
128
|
+
# *Example*
|
129
|
+
#
|
130
|
+
# $$$ Need an example $$$
|
131
|
+
def confirm(value,opts = {})
|
132
|
+
return @confirm_method.call(value,opts)
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
# Method description
|
137
|
+
#
|
138
|
+
# *Options*
|
139
|
+
#
|
140
|
+
# +option+:: specifies something
|
141
|
+
#
|
142
|
+
# *Example*
|
143
|
+
#
|
144
|
+
# $$$ Need an example $$$
|
145
|
+
def verify(value,opts = {})
|
146
|
+
@verify_method.call(value,opts)
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
# Method description
|
151
|
+
#
|
152
|
+
# *Options*
|
153
|
+
#
|
154
|
+
# +option+:: specifies something
|
155
|
+
#
|
156
|
+
# *Example*
|
157
|
+
#
|
158
|
+
# $$$ Need an example $$$
|
159
|
+
def goto(opts = {})
|
160
|
+
return @goto_method.call(opts)
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
# Method description
|
165
|
+
#
|
166
|
+
# *Options*
|
167
|
+
#
|
168
|
+
# +option+:: specifies something
|
169
|
+
#
|
170
|
+
# *Example*
|
171
|
+
#
|
172
|
+
# $$$ Need an example $$$
|
173
|
+
def navigate(opts = {})
|
174
|
+
return @navigate_method.call(opts)
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
# Method description
|
179
|
+
#
|
180
|
+
# *Options*
|
181
|
+
#
|
182
|
+
# +option+:: specifies something
|
183
|
+
#
|
184
|
+
# *Example*
|
185
|
+
#
|
186
|
+
# $$$ Need an example $$$
|
187
|
+
def add_get(&block)
|
188
|
+
@get_method = block
|
189
|
+
|
190
|
+
add_generic_retrieve() unless @retrieve_method
|
191
|
+
add_generic_confirm() unless @confirm_method
|
192
|
+
add_generic_verify() unless @verify_method
|
193
|
+
if @set_method != nil
|
194
|
+
add_generic_update unless @update_method
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
# Method description
|
200
|
+
#
|
201
|
+
# *Options*
|
202
|
+
#
|
203
|
+
# +option+:: specifies something
|
204
|
+
#
|
205
|
+
# *Example*
|
206
|
+
#
|
207
|
+
# $$$ Need an example $$$
|
208
|
+
def add_set(&block)
|
209
|
+
@set_method = block
|
210
|
+
|
211
|
+
if @get_method != nil
|
212
|
+
add_generic_update() unless @update_method
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
# Method description
|
218
|
+
#
|
219
|
+
# *Options*
|
220
|
+
#
|
221
|
+
# +option+:: specifies something
|
222
|
+
#
|
223
|
+
# *Example*
|
224
|
+
#
|
225
|
+
# $$$ Need an example $$$
|
226
|
+
def add_update(&block)
|
227
|
+
@update_method = block
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
# Method description
|
232
|
+
#
|
233
|
+
# *Options*
|
234
|
+
#
|
235
|
+
# +option+:: specifies something
|
236
|
+
#
|
237
|
+
# *Example*
|
238
|
+
#
|
239
|
+
# $$$ Need an example $$$
|
240
|
+
def add_retrieve(&block)
|
241
|
+
@retrieve_method = block
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
# Method description
|
246
|
+
#
|
247
|
+
# *Options*
|
248
|
+
#
|
249
|
+
# +option+:: specifies something
|
250
|
+
#
|
251
|
+
# *Example*
|
252
|
+
#
|
253
|
+
# $$$ Need an example $$$
|
254
|
+
def add_verify(&block)
|
255
|
+
@verify_method = block
|
256
|
+
end
|
257
|
+
|
258
|
+
|
259
|
+
# Method description
|
260
|
+
#
|
261
|
+
# *Options*
|
262
|
+
#
|
263
|
+
# +option+:: specifies something
|
264
|
+
#
|
265
|
+
# *Example*
|
266
|
+
#
|
267
|
+
# $$$ Need an example $$$
|
268
|
+
def add_confirm(&block)
|
269
|
+
@confirm_method = block
|
270
|
+
end
|
271
|
+
|
272
|
+
|
273
|
+
# Method description
|
274
|
+
#
|
275
|
+
# *Options*
|
276
|
+
#
|
277
|
+
# +option+:: specifies something
|
278
|
+
#
|
279
|
+
# *Example*
|
280
|
+
#
|
281
|
+
# $$$ Need an example $$$
|
282
|
+
def add_goto(&block)
|
283
|
+
@goto_method = block
|
284
|
+
add_generic_navigate() unless @navigate_method
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
# Method description
|
289
|
+
#
|
290
|
+
# *Options*
|
291
|
+
#
|
292
|
+
# +option+:: specifies something
|
293
|
+
#
|
294
|
+
# *Example*
|
295
|
+
#
|
296
|
+
# $$$ Need an example $$$
|
297
|
+
def add_navigate(&block)
|
298
|
+
@navigate_method = block
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
# Method description
|
303
|
+
#
|
304
|
+
# Depends on get, retrieve, set
|
305
|
+
#
|
306
|
+
# *Options*
|
307
|
+
#
|
308
|
+
# +option+:: specifies something
|
309
|
+
#
|
310
|
+
# *Example*
|
311
|
+
#
|
312
|
+
# $$$ Need an example $$$
|
313
|
+
def add_generic_update()
|
314
|
+
add_update { |value,opts|
|
315
|
+
new_value = value
|
316
|
+
found_value = retrieve()
|
317
|
+
if new_value == found_value
|
318
|
+
capital_text = @logtext
|
319
|
+
capital_text[0] = capital_text[0].capitalize
|
320
|
+
Parfait.log("#{capital_text} is already set to \"#{new_value}\"")
|
321
|
+
else
|
322
|
+
Parfait.log("Entering #{@logtext}: \"#{new_value}\" (was \"#{found_value}\")")
|
323
|
+
set(new_value,opts)
|
324
|
+
end
|
325
|
+
}
|
326
|
+
end
|
327
|
+
|
328
|
+
|
329
|
+
# Method description
|
330
|
+
#
|
331
|
+
# *Options*
|
332
|
+
#
|
333
|
+
# +option+:: specifies something
|
334
|
+
#
|
335
|
+
# *Example*
|
336
|
+
#
|
337
|
+
# $$$ Need an example $$$
|
338
|
+
def add_generic_retrieve()
|
339
|
+
add_retrieve {
|
340
|
+
get()
|
341
|
+
}
|
342
|
+
end
|
343
|
+
|
344
|
+
|
345
|
+
# Method description
|
346
|
+
#
|
347
|
+
# Depends on get, retrieve
|
348
|
+
#
|
349
|
+
# *Options*
|
350
|
+
#
|
351
|
+
# +option+:: specifies something
|
352
|
+
#
|
353
|
+
# *Example*
|
354
|
+
#
|
355
|
+
# $$$ Need an example $$$
|
356
|
+
def add_generic_verify()
|
357
|
+
add_verify { |value,opts|
|
358
|
+
found_value = retrieve()
|
359
|
+
if value == found_value
|
360
|
+
Parfait.log("Verified #{@logtext} to be \"#{value}\"")
|
361
|
+
else
|
362
|
+
raise "Expected #{@logtext} to be \"#{value}\", but found \"#{found_value}\" instead"
|
363
|
+
end
|
364
|
+
true
|
365
|
+
}
|
366
|
+
end
|
367
|
+
|
368
|
+
|
369
|
+
# Method description
|
370
|
+
#
|
371
|
+
# Depends on get, retrieve
|
372
|
+
#
|
373
|
+
# *Options*
|
374
|
+
#
|
375
|
+
# +option+:: specifies something
|
376
|
+
#
|
377
|
+
# *Example*
|
378
|
+
#
|
379
|
+
# $$$ Need an example $$$
|
380
|
+
def add_generic_confirm()
|
381
|
+
add_confirm { |value,opts|
|
382
|
+
retval = false
|
383
|
+
found_value = retrieve()
|
384
|
+
if value == found_value
|
385
|
+
retval = true
|
386
|
+
end
|
387
|
+
retval
|
388
|
+
}
|
389
|
+
end
|
390
|
+
|
391
|
+
|
392
|
+
# Method description
|
393
|
+
#
|
394
|
+
# Depends on goto
|
395
|
+
#
|
396
|
+
# *Options*
|
397
|
+
#
|
398
|
+
# +option+:: specifies something
|
399
|
+
#
|
400
|
+
# *Example*
|
401
|
+
#
|
402
|
+
# $$$ Need an example $$$
|
403
|
+
def add_generic_navigate()
|
404
|
+
add_navigate { |opts|
|
405
|
+
Parfait.log("Navigating to #{@logtext}")
|
406
|
+
goto(opts)
|
407
|
+
}
|
408
|
+
end
|
409
|
+
|
410
|
+
|
411
|
+
end
|
412
|
+
|
413
|
+
end
|