iu-test-factory 0.5.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f3ea4ae667f09f498f06cc42c864ce19f6b58889d06773003f6c7fff485df5c7
4
+ data.tar.gz: 9b17a101a1912e39c194bb2b1f1308b1829ebf23353d4f717654bb1eeb4b496b
5
+ SHA512:
6
+ metadata.gz: b246c41552684f183328d2727480118eb01959ee62105e1ba2d6bdd1b2af0167edc0f5a880b10e7126458dc7930cee83cee0364a66a015f0bcddc1014abd2015
7
+ data.tar.gz: '009c47f65b12af13855013d6db260c90bd5705947399028ca6aec55f3ac4cd3ac07f9b972a258dbd902663913ec41e18151936989682637e7fe89548de8b03a0'
data/COPYING ADDED
@@ -0,0 +1 @@
1
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'watir', '>=6.0.0'
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ test-factory (0.5.4)
5
+ watir (>= 6.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ childprocess (0.8.0)
11
+ ffi (~> 1.0, >= 1.0.11)
12
+ ffi (1.9.18)
13
+ rubyzip (1.2.1)
14
+ selenium-webdriver (3.7.0)
15
+ childprocess (~> 0.5)
16
+ rubyzip (~> 1.0)
17
+ watir (6.9.0)
18
+ selenium-webdriver (~> 3.4, >= 3.4.1)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ test-factory!
25
+ watir (>= 6.0.0)
26
+
27
+ BUNDLED WITH
28
+ 1.15.4
data/LICENSE ADDED
@@ -0,0 +1,68 @@
1
+ Apache License, Version 2.0
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
13
+
14
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15
+
16
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
17
+
18
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
19
+
20
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
21
+
22
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
23
+
24
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
25
+
26
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
27
+
28
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
29
+
30
+ 2. Grant of Copyright License.
31
+
32
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
33
+
34
+ 3. Grant of Patent License.
35
+
36
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
37
+
38
+ 4. Redistribution.
39
+
40
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
41
+
42
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
43
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
44
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
45
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
46
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
47
+
48
+ 5. Submission of Contributions.
49
+
50
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
51
+
52
+ 6. Trademarks.
53
+
54
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
55
+
56
+ 7. Disclaimer of Warranty.
57
+
58
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
59
+
60
+ 8. Limitation of Liability.
61
+
62
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
63
+
64
+ 9. Accepting Warranty or Additional Liability.
65
+
66
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
67
+
68
+ END OF TERMS AND CONDITIONS
data/README.md ADDED
@@ -0,0 +1,241 @@
1
+ IU's TestFactory Gem
2
+ =========================
3
+
4
+ Overview
5
+ --------
6
+
7
+ This gem contains the basic framework for [dryly](http://en.wikipedia.org/wiki/Don%27t_repeat_yourself) creating test scripts for the web site that needs testing.
8
+
9
+ Use it to abstract away from the underlying [Watir](http://www.watir.com) code and create your own [DSL](http://en.wikipedia.org/wiki/Domain_specific_language).
10
+
11
+ With TestFactory you have the ability to...
12
+
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
+ 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
19
+
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.
21
+
22
+ Summary
23
+ -------
24
+
25
+ Using the TestFactory properly involves three distinct steps:
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).
37
+
38
+ These three steps can all be accomplished by a single person. However, ideally, they should be done by three or four people, as the design philosophy of TestFactory allows for specialization:
39
+
40
+ - A Watir specialist works on defining page elements and actions inside of page classes
41
+ - A Ruby specialist uses the output of the Watir specialist to build the data objects and their helper methods, creating the DSL for the project
42
+ - A non-programmer--say, a business analyst or a manual tester with domain expertise--writes test scenarios, in English
43
+ - A more junior automation engineer translates the English into Ruby code, via the DSL created by the Ruby specialist (if you're using Cucumber, these would be your step definitions)
44
+
45
+ How to Start
46
+ ------------
47
+
48
+ First install the gem, of course.
49
+
50
+ gem install test-factory
51
+
52
+ Now you'll want to start building your own page classes, using the methods in TestFactory as your tool chest.
53
+
54
+ Please note that the following example is *very* simplified and contrived, to keep every step as compartmentalized as possible. Once you've read through this, it is strongly recommended that you visit an actual repository that is using the test factory.
55
+
56
+ [Here](https://github.com/aheward/sambal-cle) is one such.
57
+
58
+ Begin by creating a BasePage class. This class should have PageFactory as its superclass and define sets of class elements that are generally common across the pages of your site.
59
+
60
+ ```ruby
61
+ require 'test-factory'
62
+
63
+ class BasePage < PageFactory
64
+
65
+ class << self
66
+
67
+ def header_elements
68
+ element(:main_menu_link) { |b| b.link(title: "Main Menu") }
69
+ element(:logout) { |b| b.button(value: "Logout") }
70
+ element(:administration_link) { |b| b.link(title: "Administration") }
71
+
72
+ action(:main_menu) { |p| p.main_menu_link.click }
73
+ action(:provide_feedback) { |b| b.link(title: "Provide Feedback").click }
74
+ action(:administration) { |p| p.administration_link.click }
75
+ end
76
+ end
77
+ end
78
+
79
+ ```
80
+
81
+ Next, you create classes for the individual pages in your web site. These classes should have BasePage as their superclass, and should declare any of the relevant methods defined in the BasePage class.
82
+
83
+ ```ruby
84
+ class Home < BasePage
85
+
86
+ # This allows the header elements to be defined once
87
+ # in the BasePage class and then reused throughout your web pages...
88
+ header_elements
89
+
90
+ expected_element :title # When the Home class is instantiated (using the Foundry),
91
+ # the script will ensure that the :title element is present
92
+ # on the page before the script continues
93
+
94
+ # Now you define elements that are specific to your Home page...
95
+ element(:title) { |b| b.h3(id: "title") }
96
+ # and on and on...
97
+
98
+ end
99
+ ```
100
+
101
+ Once you've got a bunch of classes set up for your site's various pages, you're going to want to create "data objects" to represent what goes into those pages. For this, you'll use the superclass DataFactory. Your data classes should follow this basic structure:
102
+
103
+ ```ruby
104
+ class YourDataObject < DataFactory
105
+
106
+ # Define all the things you need to test about your data object.
107
+ # These are some example attributes...
108
+ attr_accessor :title, :id, :link, :status, :description
109
+
110
+ # Your data object has to know about Watir's browser object, so it's passed to it here, along
111
+ # with a hash containing all the attributes you want the data object to have
112
+ def initialize(browser, opts={})
113
+ @browser = browser
114
+
115
+ # Put any attributes here that you don't want to always have to define explicitly...
116
+ defaults = {
117
+ :title=>"My Data Title",
118
+ :description=>"My Data's Description"
119
+ # ...
120
+ }
121
+
122
+ # The set_options line combines the defaults
123
+ # with any options you passed explicitly in opts,
124
+ # then turns all the contents of the options
125
+ # Hash into YourDataObject's class instance variables
126
+ set_options(defaults.merge(opts))
127
+
128
+ requires :id # This line allows you to specify any class instance variables that must
129
+ # be explicitly defined for the data object
130
+ end
131
+
132
+ # Now define a bunch of methods that are relevant to your data object.
133
+ # In general these methods will follow the CRUD design pattern
134
+
135
+ def create
136
+ # Your code here...
137
+ end
138
+
139
+ def view
140
+ # Your code here...
141
+ end
142
+
143
+ def edit opts={}
144
+ # Your code here...
145
+ update_options(opts) # This updates all your class instance variables
146
+ # with any new values specified by the opts Hash.
147
+ end
148
+
149
+ def remove
150
+ # Your code here...
151
+ end
152
+
153
+ end
154
+ ```
155
+
156
+ Now you have your basic infrastructure in place, and you can start writing your test cases using these classes.
157
+
158
+ ```ruby
159
+ include Foundry # Gives you access to the methods that instantiate your Page and Data classes
160
+
161
+ # First, make the data object you're going to use for testing...
162
+ @my_thing = make YourDataObject :id=>"identifier", :description=>"It's lovely."
163
+
164
+ # Now, create the data in your site...
165
+ @my_thing.create
166
+
167
+ on MyPage do |page|
168
+ page.title.set "Bla bla"
169
+ # Very contrived example. TestFactory was made to be test-framework-agnostic. You should be using your favorite verification framework here:
170
+ page.description==@my_thing.description ? puts "Passed" : puts "Failed"
171
+ end
172
+ ```
173
+
174
+ Design Pattern
175
+ --------------
176
+
177
+ The TestFactory was written assuming the following guiding principles. Any code that does not
178
+ follow them probably [smells](http://en.wikipedia.org/wiki/Code_smell), and should be refactored.
179
+
180
+ * Page Classes contain methods relating to interactions with page elements only--meaning
181
+ the getting or setting of values, or the clicking of links or buttons. Any more
182
+ complicated page interactions are handled in the Data Object classes, or in the test
183
+ step definitions.
184
+ * Data Objects represent definable data structure entities in the system being tested.
185
+ As data, they fit into the [CRUD Model](http://en.wikipedia.org/wiki/Create,_read,_update_and_delete)
186
+ and thus have methods that correspond to those basic functions.
187
+ * Data Objects have a single method for each of the CRUD functions, and additional
188
+ custom methods are avoided, unless there are _compelling_ arguments for their inclusion in the class.
189
+ * When a Data Object is executing its `edit` method, first the data in the
190
+ system under test is updated, then the data object's instance variables
191
+ are updated--using DataFactory's `set_options`.
192
+ * Site navigation is handled using conditional methods (meaning they only navigate if
193
+ necessary) inside the Data Object--and preferably inside the data object's CRUD methods
194
+ themselves--unless there are specific reasons to explicitly navigate in a step
195
+ definition. This keeps step definitions from being unnecessarily cluttered.
196
+ * Specifying non-default test variables for data objects is done using key/value hash
197
+ pairs that are parameters of the data object's CRUD methods. It is _not_
198
+ done by explicitly assigning values to the instance variables. Examples:
199
+
200
+ ```ruby
201
+ # During object creation, following the name of the class
202
+ @data_object = make DataObject, :attrib1 => "Custom Value 1", :attrib2 => "Custom Value 2" # etc...
203
+
204
+ # When an object is edited (using Ruby v1.9.3's Hash syntax is optional)
205
+ @data_object.edit attrib1: "Updated Value 1", attrib2: "Updated Value 2"
206
+
207
+ # This is frowned upon because it can easily lead to
208
+ # the data object and the data in the test site being
209
+ # out of sync, leading to a false negative test result:
210
+ @data_object.attrib1="Another Value"
211
+
212
+ ```
213
+
214
+ * Except in very rare cases, updates to a data object's instance variables should be handled *only* by the `set_options` method, *not* explicitly.
215
+
216
+ ```ruby
217
+ # This is good
218
+ def edit opts={}
219
+ #...
220
+ page.element.fit opts[:value]
221
+ #...
222
+ update_options(opts)
223
+ end
224
+
225
+ # This is not good
226
+ def edit opts={}
227
+ #...
228
+ page.element.fit opts[:value]
229
+ #...
230
+ @value=opts[:value] unless @value==opts[:value]
231
+ end
232
+ ```
233
+
234
+ * The setting of random values for select lists in a data object is determined by passing
235
+ the string '::random::' in the instance variable, or as the value in the key/value pair
236
+ passed in an `#edit` method's `opts` parameter. The `#create` and `#edit` methods will
237
+ handle the necessary logic. The purpose is to prevent the need for custom randomizing
238
+ CRUD methods in the data object.
239
+ * See the gem_ext.rb file's discussion of the Watir `#fit` method for additional
240
+ design pattern rules to follow (If you're reading this on rubydoc.info then click the Watir module link)
241
+ * Please make an effort to follow the [Ruby Style Guidelines](http://www.caliban.org/ruby/rubyguide.shtml#style).
@@ -0,0 +1,13 @@
1
+ spec = Gem::Specification.new do |s|
2
+ s.name = 'iu-test-factory'
3
+ s.version = '0.5.4.2'
4
+ s.summary = %q{framework for creating automated testing scripts}
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.}
6
+ s.files = Dir.glob("**/**/**")
7
+ s.test_files = Dir.glob("test/*test_rb")
8
+ s.authors = ['Abraham Heward']
9
+ s.email = %w{aheward@rsmart.com}
10
+ s.homepage = 'https://github.iu.edu/iu-uits-es'
11
+ s.add_dependency 'watir', '>= 6.0.0'
12
+ s.required_ruby_version = '>= 2.0.0'
13
+ end
@@ -0,0 +1,18 @@
1
+ # Copyright 2012-2014 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
+ require 'watir'
16
+ require 'forwardable'
17
+ %w{foundry.rb data_factory.rb}.each { |f| require "#{File.dirname(__FILE__)}/test-factory/#{f}" }
18
+ Dir["#{File.dirname(__FILE__)}/test-factory/*.rb"].each {|f| require f }
@@ -0,0 +1,67 @@
1
+ # Copyright 2012-2014 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
+ # =================
16
+ # CollectionsFactory
17
+ # =================
18
+ #
19
+ # Use this as the superclass for your data object collection classes.
20
+ class CollectionsFactory < Array
21
+
22
+ def initialize(browser)
23
+ @browser=browser
24
+ end
25
+
26
+ # Defines the class of objects contained in the collection
27
+ #
28
+ def self.contains klass
29
+
30
+ # Creates a method called "add" that will create the specified data
31
+ # object and then add it as an item in the collection.
32
+ #
33
+ # Note that it's assumed that the target data object will have a
34
+ # create method defined. If not, this will not work properly.
35
+ define_method 'add' do |opts={}|
36
+ element = klass.new @browser, opts
37
+ element.create
38
+ self << element
39
+ end
40
+
41
+ end
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
+
54
+ # Used in conjunction with the Parent object containing
55
+ # the collection.
56
+ #
57
+ # The parent sends updated information to the collection(s)
58
+ # using #notify_collections
59
+ #
60
+ def notify_members *updates
61
+ self.each { |member| member.update_from_parent *updates }
62
+ end
63
+
64
+ end
65
+
66
+ # Just an alias class name.
67
+ class CollectionFactory < CollectionsFactory; end