test-factory 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +75 -5
- data/lib/test-factory/gem_ext.rb +14 -14
- data/test-factory.gemspec +2 -2
- metadata +4 -5
- data/test-factory-0.1.6.gem +0 -0
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,8 +11,11 @@ Use it to abstract away from the underlying [Watir](http://www.watir.com) code a
|
|
11
11
|
With TestFactory you have the ability to...
|
12
12
|
|
13
13
|
1. Easily instantiate page classes (described below) in a consistent and readable manner
|
14
|
-
2. Concisely describe elements on a page, keeping it DRY by avoiding repetition of element
|
15
|
-
|
14
|
+
2. Concisely describe elements on a page, keeping it DRY by avoiding repetition of element
|
15
|
+
identifiers that may (will) change
|
16
|
+
3. Provide higher-level methods that use customizable (and default) data, along with the
|
17
|
+
page classes and elements, to perform user-oriented--i.e., behavioral--functions
|
18
|
+
with minimal lines of code
|
16
19
|
|
17
20
|
Tremendous thanks is due to [Alister Scott](http://watirmelon.com), whose [custom page object code](https://github.com/alisterscott/wmf-custom-page-object) for the Wikimedia Foundation provided the inspiration for this gem.
|
18
21
|
|
@@ -21,9 +24,16 @@ Summary
|
|
21
24
|
|
22
25
|
Using the TestFactory properly involves three distinct steps:
|
23
26
|
|
24
|
-
1. Creating page classes that contain references to the elements on your web page. For this
|
25
|
-
|
26
|
-
|
27
|
+
1. Creating page classes that contain references to the elements on your web page. For this
|
28
|
+
you use the PageFactory class. Working on page classes requires that you have a strong
|
29
|
+
command of Watir and basic skills with Ruby.
|
30
|
+
2. Creating "data objects" that utilize your page classes and elements to build methods that
|
31
|
+
perform user-oriented tasks. For this you use the DataFactory module. Working on data
|
32
|
+
objects requires you have good familiarity with Watir and strong Ruby skills.
|
33
|
+
3. Creating test scenarios using your favorite test framework (like Cucumber or Rspec) and
|
34
|
+
your data objects. The methods in the Foundry class are useful here. Working at this
|
35
|
+
level requires only basic skills with Ruby and Watir, but a strong command of your DSL
|
36
|
+
(the thing you're building with TestFactory).
|
27
37
|
|
28
38
|
How to Start
|
29
39
|
------------
|
@@ -156,6 +166,66 @@ on MyPage do |page|
|
|
156
166
|
end
|
157
167
|
```
|
158
168
|
|
169
|
+
Design Pattern
|
170
|
+
--------------
|
171
|
+
|
172
|
+
The TestFactory was written assuming the following guiding principles. Any code that does not follow them is probably not DRY.
|
173
|
+
|
174
|
+
1. Page Classes contain methods relating to interactions with page elements only--meaning
|
175
|
+
the getting or setting of values, or the clicking of links or buttons. Any more
|
176
|
+
complicated page interactions are handled in the Data Object classes, or in the test
|
177
|
+
step definitions.
|
178
|
+
2. Data Objects represent definable data structure entities in the system being tested.
|
179
|
+
As data, they fit into the [CRUD Model](http://en.wikipedia.org/wiki/Create,_read,_update_and_delete)
|
180
|
+
and thus have methods that correspond to those basic functions.
|
181
|
+
3. Data Objects have a single method for each of the CRUD functions, and additional
|
182
|
+
custom methods are avoided without compelling arguments for their inclusion in the class.
|
183
|
+
4. When a Data Object is executing its `edit` method, first the data in the
|
184
|
+
system under test is updated, then the data object's instance variables
|
185
|
+
are updated--using `set_options`.
|
186
|
+
5. Site navigation is handled using conditional methods (meaning they only navigate if
|
187
|
+
necessary) inside the Data Object, unless there are specific reasons to explicitly
|
188
|
+
navigate in a step definition. This keeps step definitions from being unnecessarily cluttered.
|
189
|
+
6. Specifying non-default test variables for data objects is done using key/value hash
|
190
|
+
pairs that are parameters of the data object's CRUD methods. It is _not_
|
191
|
+
done by explicitly assigning values to the instance variables. Examples:
|
192
|
+
```ruby
|
193
|
+
# During object creation, following the name of the class
|
194
|
+
@data_object = make DataObject, :attrib1 => "Custom Value 1", :attrib2 => "Custom Value 2" # etc...
|
195
|
+
|
196
|
+
# When an object is edited (Ruby v1.9.3 Hash syntax optional)
|
197
|
+
@data_object.edit attrib1: "Updated Value 1", attrib2: "Updated Value 2"
|
198
|
+
|
199
|
+
# This is frowned upon:
|
200
|
+
@data_object.attrib1="Another Value"
|
201
|
+
|
202
|
+
```
|
203
|
+
7. Updates to a data object's instance variables is handled *only* by the `set_options` method, *not* explicitly.
|
204
|
+
```ruby
|
205
|
+
# This is good
|
206
|
+
def edit opts={}
|
207
|
+
#...
|
208
|
+
page.element.fit opts[:value]
|
209
|
+
#...
|
210
|
+
update_options(opts)
|
211
|
+
end
|
212
|
+
|
213
|
+
# This is not good
|
214
|
+
def edit opts={}
|
215
|
+
#...
|
216
|
+
page.element.fit opts[:value]
|
217
|
+
#...
|
218
|
+
@value=opts[:value] unless @value==opts[:value]
|
219
|
+
end
|
220
|
+
```
|
221
|
+
8. The setting of random values for select lists in a data object is determined by passing
|
222
|
+
the symbol `:random` in the instance variable or as the value in the key/value pair
|
223
|
+
passed in an `#edit` method's `opts` parameter. The `#create` and `#edit` methods will
|
224
|
+
handle the necessary logic. The purpose is to prevent the need for custom randomizing
|
225
|
+
CRUD methods in the data object.
|
226
|
+
9. See the gem_ext.rb file's discussion of the Watir `#fit` method for additional
|
227
|
+
design pattern rules to follow.
|
228
|
+
|
159
229
|
Notice
|
160
230
|
------
|
161
231
|
|
data/lib/test-factory/gem_ext.rb
CHANGED
@@ -2,29 +2,29 @@
|
|
2
2
|
# which can be used with text fields, select lists, radio buttons,
|
3
3
|
# and checkboxes.
|
4
4
|
#
|
5
|
-
# The purpose of
|
6
|
-
# of a minimal number of
|
5
|
+
# The purpose of +#fit+ is to allow the creation, in your Data Object classes,
|
6
|
+
# of a minimal number of +#edit+ methods (ideally only one) written as
|
7
7
|
# concisely as possible.
|
8
8
|
#
|
9
|
-
# Without the
|
9
|
+
# Without the +#fit+ method, you would either have to write separate edit
|
10
10
|
# methods for every possible field you want to edit, or else your
|
11
11
|
# edit method would have to contain lots of repetitive conditional code
|
12
|
-
# to prevent making
|
12
|
+
# to prevent making inadvertent updates to those fields that don't need it.
|
13
13
|
#
|
14
|
-
# Proper use of the
|
14
|
+
# Proper use of the +#fit+ method requires following a particular coding
|
15
15
|
# pattern, however:
|
16
16
|
#
|
17
|
-
# 1. In your Page Classes, define your radio buttons and checkboxes directly. Do not define
|
18
|
-
# 2. Your data object's instance variables for radio buttons and checkboxes, when not +nil+, should have the values of +:set+ or +:clear+. If they *need* to be something else, then define a Hash transform method to easily convert the custom values back to +:set+ or +:clear+, then pass that transform to the
|
19
|
-
# 3. Always remember to end your
|
17
|
+
# 1. In your Page Classes, define your text fields, select lists, radio buttons, and checkboxes directly. Do not define +#select+, +#set+ and/or +#clear+ actions there.
|
18
|
+
# 2. Your data object's instance variables for radio buttons and checkboxes, when not +nil+, should have the values of +:set+ or +:clear+. If they *need* to be something else, then define a Hash transform method to easily convert the custom values back to +:set+ or +:clear+, then pass that transform to the +#fit+ method.
|
19
|
+
# 3. Always remember to end your +#edit+ methods with the +#set_options()+ method (a.k.a. +#update_options+), from the DataFactory module. It automatically takes care of updating your data object's instance variables with any new values.
|
20
20
|
#
|
21
21
|
# ==Example
|
22
22
|
#
|
23
|
-
# Let's take a look at how the proper use of
|
24
|
-
# clean things up, using a checkbox field for our example. Remember that
|
23
|
+
# Let's take a look at how the proper use of +#fit+ in your code can significantly
|
24
|
+
# clean things up, using a checkbox field for our example. Remember that +#fit+
|
25
25
|
# works with radio buttons, text fields, and select lists, too.
|
26
26
|
#
|
27
|
-
# First, here's some code written without using
|
27
|
+
# First, here's some code written without using +#fit+, and using
|
28
28
|
# actions for the checkbox page objects, and a Data Object
|
29
29
|
# instance variable, +@option+, that is either "YES" or "NO"...
|
30
30
|
#
|
@@ -54,9 +54,9 @@
|
|
54
54
|
# # ...
|
55
55
|
# end
|
56
56
|
#
|
57
|
-
# Now, let's take that same code, but this time use the
|
57
|
+
# Now, let's take that same code, but this time use the +#fit+ method, assume that
|
58
58
|
# the data object's +@option+ instance variable will be +:set+, +:clear+, or +nil+, and
|
59
|
-
# end the
|
59
|
+
# end the +#edit+ with the DataFactory's +#set_options+ helper method...
|
60
60
|
#
|
61
61
|
# class MyPage < BasePage
|
62
62
|
# # ...
|
@@ -87,7 +87,7 @@
|
|
87
87
|
# { "YES" => :set, "NO" => :clear }
|
88
88
|
# end
|
89
89
|
#
|
90
|
-
# Then use that transform with your
|
90
|
+
# Then use that transform with your +#fit+ method, like this:
|
91
91
|
#
|
92
92
|
# page.checkbox.fit checkbox_trans[opts[:option]]
|
93
93
|
#
|
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.1.
|
3
|
+
s.version = '0.1.8'
|
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("**/**/**")
|
@@ -8,6 +8,6 @@ spec = Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Abraham Heward"]
|
9
9
|
s.email = %w{"aheward@rsmart.com"}
|
10
10
|
s.homepage = 'https://github.com/rSmart'
|
11
|
-
s.add_dependency 'watir-webdriver', '>= 0.6.
|
11
|
+
s.add_dependency 'watir-webdriver', '>= 0.6.2'
|
12
12
|
s.required_ruby_version = '>= 1.9.2'
|
13
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watir-webdriver
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.6.
|
21
|
+
version: 0.6.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.6.
|
29
|
+
version: 0.6.2
|
30
30
|
description: This gem provides a set of modules and methods to help quickly and DRYly
|
31
31
|
create a test automation framework using Ruby and Watir (or watir-webdriver).
|
32
32
|
email:
|
@@ -47,7 +47,6 @@ files:
|
|
47
47
|
- lib/test-factory/string_factory.rb
|
48
48
|
- lib/test-factory.rb
|
49
49
|
- README.md
|
50
|
-
- test-factory-0.1.6.gem
|
51
50
|
- test-factory.gemspec
|
52
51
|
homepage: https://github.com/rSmart
|
53
52
|
licenses: []
|
data/test-factory-0.1.6.gem
DELETED
Binary file
|