test-factory 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +1 -1
- data/lib/test-factory.rb +1 -0
- data/lib/test-factory/collections_factory.rb +12 -0
- data/lib/test-factory/data_factory.rb +24 -30
- data/lib/test-factory/data_object.rb +50 -0
- data/lib/test-factory/foundry.rb +3 -3
- data/test-factory.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGUwYjI5N2E3MjM1YmVlZmQ2NzMzYTRkY2JiODA2ZjIxY2U3NjEwYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTFiZWRjOThjNzc0MzQ3ZTMyNzQyYmM2YWJiZGQ2Zjk3NmUzODgyMg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzkzYjA2NjYwNDk5NTZmNDg5ZTc2YTgxMWY1NWExYjUyYTcyOWRjYzUxNWJh
|
10
|
+
YzkxYjkzODk3NDZhMDEzMGZlM2I1MzEzMDZjOTBmMzE3MjczOTRiN2IyNTRk
|
11
|
+
ZmZhZTRkODMzYjhlMzQwYWY2ZDFlZmNkNmZlNmU5YmUzYzE1NzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTRhM2Y5ZjkyY2ZkMmQ5ZWE1ODI1NmM2MTFjZTc0ODUzZjY1MjNjZTg4NjBl
|
14
|
+
ZDI2YzYwMzFjODZkYzZkNTg0MTEzNWM2ZWE4ZjUxMTUwOGUxNmMwNTAxYmZh
|
15
|
+
NGRmMTJkYzFiOThhMzIzZGE0MTY2ZTEyMDkwZDQ1ZTgyNmRhOTQ=
|
data/README.md
CHANGED
@@ -213,7 +213,7 @@ follow them probably [smells](http://en.wikipedia.org/wiki/Code_smell), and shou
|
|
213
213
|
|
214
214
|
```
|
215
215
|
|
216
|
-
*
|
216
|
+
* Except in very rare cases, updates to a data object's instance variables should be handled *only* by the `set_options` method, *not* explicitly.
|
217
217
|
|
218
218
|
```ruby
|
219
219
|
# This is good
|
data/lib/test-factory.rb
CHANGED
@@ -24,6 +24,7 @@ class CollectionsFactory < Array
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# Defines the class of objects contained in the collection
|
27
|
+
#
|
27
28
|
def self.contains klass
|
28
29
|
|
29
30
|
# Creates a method called "add" that will create the specified data
|
@@ -39,6 +40,17 @@ class CollectionsFactory < Array
|
|
39
40
|
|
40
41
|
end
|
41
42
|
|
43
|
+
# Makes a "deep copy" of the Collection. See the #data_object_copy
|
44
|
+
# method description in the DataObject class for more information.
|
45
|
+
#
|
46
|
+
def copy
|
47
|
+
new_collection = self.class.new(@browser)
|
48
|
+
self.each do |item|
|
49
|
+
new_collection << item.data_object_copy
|
50
|
+
end
|
51
|
+
new_collection
|
52
|
+
end
|
53
|
+
|
42
54
|
end
|
43
55
|
|
44
56
|
class CollectionFactory < CollectionsFactory
|
@@ -34,7 +34,8 @@ module DataFactory
|
|
34
34
|
# E.g., your collection class is called "DataObjectCollection", so, inside your
|
35
35
|
# parent object's defaults, you'd set the instance variable like this:
|
36
36
|
#
|
37
|
-
#
|
37
|
+
# @example
|
38
|
+
# data_objects: collection('DataObject')
|
38
39
|
#
|
39
40
|
def collection(name)
|
40
41
|
Kernel.const_get("#{name}Collection").new(@browser)
|
@@ -52,7 +53,6 @@ module DataFactory
|
|
52
53
|
# @param elements [Array] the list of items that are required.
|
53
54
|
#
|
54
55
|
# @example
|
55
|
-
#
|
56
56
|
# requires :site, :assignment, :document_id
|
57
57
|
#
|
58
58
|
def requires(*elements)
|
@@ -72,7 +72,7 @@ module DataFactory
|
|
72
72
|
|
73
73
|
# Transform for use with data object instance variables
|
74
74
|
# that refer to checkboxes or radio buttons. Instead of returning a boolean value, it returns
|
75
|
-
# the symbols
|
75
|
+
# the symbols +:set+ or +:clear+ -- This can be useful because those symbols can then in turn
|
76
76
|
# be passed directly as methods for updating or validating the checkbox later.
|
77
77
|
#
|
78
78
|
# @param checkbox [Watir::CheckBox] The checkbox on the page that you want to inspect
|
@@ -88,51 +88,47 @@ module DataFactory
|
|
88
88
|
# (as Symbols).
|
89
89
|
#
|
90
90
|
# This method has a number of requirements:
|
91
|
+
#
|
91
92
|
# 1) The field name and the instance variable name in your data object
|
92
|
-
#
|
93
|
-
#
|
93
|
+
# must be identical. For this reason, this method can only
|
94
|
+
# be used in your data objects' create methods.
|
95
|
+
#
|
94
96
|
# 2) Your checkbox and radio button data object instance variables are
|
95
|
-
#
|
96
|
-
#
|
97
|
+
# either +nil+, +:set+, or +:clear+. Any other values will not be handled
|
98
|
+
# correctly.
|
99
|
+
#
|
97
100
|
# 3) Since the listed fields get filled out in random order, be sure that
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
+
# this is okay in the context of your page--in other words, if field A
|
102
|
+
# needs to be specified before field B then having them both in your
|
103
|
+
# fill_out step would be inappropriate.
|
104
|
+
#
|
101
105
|
# 4) This method supports text fields, select lists, check boxes, and
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
106
|
+
# radio buttons, but only if their element definitions don't take a
|
107
|
+
# parameter. Please use the +#fill_out_item+ with elements that do need
|
108
|
+
# a parameter defined.
|
105
109
|
#
|
106
110
|
# @example
|
107
|
-
#
|
108
111
|
# on PageClass do |page|
|
109
112
|
# fill_out page, :text_field_name, :radio_name, :select_list_name, :checkbox_name
|
110
113
|
# end
|
111
114
|
#
|
112
115
|
def fill_out(page, *fields)
|
113
|
-
|
114
|
-
lambda{|p, f| p.send(f).pick!(instance_variable_get "@#{f}") } ]
|
115
|
-
fields.shuffle.each do |field|
|
116
|
-
x = page.send(field).class.to_s=='Watir::Select' ? 1 : 0
|
117
|
-
watir_methods[x].call(page, field)
|
118
|
-
end
|
116
|
+
fill_out_item(nil, page, *fields)
|
119
117
|
end
|
120
118
|
|
121
119
|
# Same as #fill_out, but used with methods that take a
|
122
120
|
# parameter to identify the target element...
|
123
121
|
#
|
124
122
|
# @example
|
125
|
-
#
|
126
123
|
# on PageClass do |page|
|
127
124
|
# fill_out_item 'Joe Schmoe', page, :text_field_name, :radio_name, :select_list_name, :checkbox_name
|
128
125
|
# end
|
129
126
|
#
|
130
127
|
def fill_out_item(name, page, *fields)
|
131
|
-
watir_methods=[ lambda{|n, p, f| p.send(f, n).fit(instance_variable_get "@#{f}") },
|
132
|
-
lambda{|n, p, f| p.send(f, n).pick!(instance_variable_get "@#{f}") } ]
|
133
128
|
fields.shuffle.each do |field|
|
134
|
-
|
135
|
-
|
129
|
+
lmnt = page.send(*[field, name].compact)
|
130
|
+
var = instance_variable_get "@#{field}"
|
131
|
+
lmnt.class.to_s == 'Watir::Select' ? lmnt.pick!(var) : lmnt.fit(var)
|
136
132
|
end
|
137
133
|
end
|
138
134
|
|
@@ -148,16 +144,16 @@ module DataFactory
|
|
148
144
|
# 1) Retrieve and store the select list's value
|
149
145
|
# 2) Specify a custom value to select
|
150
146
|
#
|
151
|
-
# Enter:
|
147
|
+
# Enter: +#get_or_select!+
|
152
148
|
#
|
153
149
|
# Assuming you just want to store the default value, then your
|
154
150
|
# Data Object's instance variable for the field will--initially--be
|
155
|
-
# nil. In that case,
|
151
|
+
# nil. In that case, +#get_or_select!+ will grab the select list's
|
156
152
|
# current value and store it in your instance variable.
|
157
153
|
#
|
158
154
|
# On the other hand, if you want to update that field with your
|
159
155
|
# custom value, then your instance variable will not be nil, so
|
160
|
-
#
|
156
|
+
# +#get_or_select!+ will take that value and use it to update the
|
161
157
|
# select list.
|
162
158
|
#
|
163
159
|
# Note that this method *only* works with select lists that take
|
@@ -172,7 +168,6 @@ module DataFactory
|
|
172
168
|
# @param select_list [Watir::Select] The relevant select list element on the page
|
173
169
|
#
|
174
170
|
# @example
|
175
|
-
#
|
176
171
|
# get_or_select! :@num_resubmissions, page.num_resubmissions
|
177
172
|
#
|
178
173
|
def get_or_select!(inst_var_sym, select_list)
|
@@ -197,7 +192,6 @@ module DataFactory
|
|
197
192
|
# of the instance variable.
|
198
193
|
#
|
199
194
|
# @example
|
200
|
-
#
|
201
195
|
# @open[:day] = get_or_select(@open[:day], page.open_day)
|
202
196
|
#
|
203
197
|
def get_or_select(hash_inst_var, select_list)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright 2012-2013 The rSmart Group, Inc.
|
2
|
+
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# The Superclass for all of your data objects.
|
16
|
+
class DataObject
|
17
|
+
|
18
|
+
include Foundry
|
19
|
+
include DataFactory
|
20
|
+
|
21
|
+
# Since Data Objects are not "Marshallable", and they generally
|
22
|
+
# contain lots of types of data in their instance variables,
|
23
|
+
# we have this method. This will create and return a 'deep copy' of
|
24
|
+
# the data object as well as any and all nested data objects
|
25
|
+
# and collections it contains.
|
26
|
+
#
|
27
|
+
# Please note that this method will fail if you are putting
|
28
|
+
# Data Objects into Arrays or Hashes instead
|
29
|
+
# of into Collection classes
|
30
|
+
#
|
31
|
+
def data_object_copy
|
32
|
+
opts = {}
|
33
|
+
self.instance_variables.each do |var|
|
34
|
+
key = var.to_s.gsub('@','').to_sym
|
35
|
+
orig_val = instance_variable_get var
|
36
|
+
opts[key] = case
|
37
|
+
when orig_val.kind_of?(CollectionsFactory)
|
38
|
+
orig_val.copy
|
39
|
+
when orig_val.instance_of?(Array) || orig_val.instance_of?(Hash)
|
40
|
+
Marshal::load(Marshal.dump(orig_val))
|
41
|
+
when orig_val.kind_of?(DataObject)
|
42
|
+
orig_val.data_object_copy
|
43
|
+
else
|
44
|
+
orig_val
|
45
|
+
end
|
46
|
+
end
|
47
|
+
self.class.new(@browser, opts)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/test-factory/foundry.rb
CHANGED
@@ -32,9 +32,9 @@ module Foundry
|
|
32
32
|
# @param &block [C] this is the block of code that you want to run while on the given page
|
33
33
|
#
|
34
34
|
def on page_class, visit=false, &block
|
35
|
-
|
36
|
-
block.call
|
37
|
-
|
35
|
+
current_page = page_class.new @browser, visit
|
36
|
+
block.call current_page if block
|
37
|
+
current_page
|
38
38
|
end
|
39
39
|
alias_method :on_page, :on
|
40
40
|
|
data/test-factory.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
s.name = 'test-factory'
|
3
|
-
s.version = '0.3.
|
3
|
+
s.version = '0.3.9'
|
4
4
|
s.summary = %q{rSmart's framework for creating automated testing scripts}
|
5
5
|
s.description = %q{This gem provides a set of modules and methods to help quickly and DRYly create a test automation framework using Ruby and Watir (or watir-webdriver).}
|
6
6
|
s.files = Dir.glob("**/**/**")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abraham Heward
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: watir-webdriver
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/test-factory/collections_factory.rb
|
39
39
|
- lib/test-factory/core_ext.rb
|
40
40
|
- lib/test-factory/data_factory.rb
|
41
|
+
- lib/test-factory/data_object.rb
|
41
42
|
- lib/test-factory/date_factory.rb
|
42
43
|
- lib/test-factory/foundry.rb
|
43
44
|
- lib/test-factory/gem_ext.rb
|