page_object_wrapper 1.0.0 → 1.1.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.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -7
- data/Rakefile +1 -0
- data/bad_pages/bad_page.rb +2 -0
- data/good_pages/some_test_page.rb +2 -0
- data/lib/page_object_wrapper/Alias.rb +12 -0
- data/lib/page_object_wrapper/PageObject.rb +37 -2
- data/lib/page_object_wrapper/version.rb +1 -1
- data/page_object_wrapper.gemspec +22 -0
- data/spec/define_page_object_spec.rb +22 -1
- data/spec/fire_event_spec.rb +15 -9
- data/spec/load_spec.rb +5 -0
- metadata +11 -6
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 ekhatko
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -34,7 +34,9 @@ Or install it yourself as:
|
|
34
34
|
- a label identifies the object
|
35
35
|
|
36
36
|
Here in the structure of PageObjectWrapper:
|
37
|
-

|
38
|
+
|
39
|
+
where required attributes are marked with (*)
|
38
40
|
|
39
41
|
### Examples
|
40
42
|
|
@@ -117,10 +119,25 @@ There is a directory, where we've defined a page\_object inside a \*\_page.rb fi
|
|
117
119
|
- it's possible to define several page objects in one file
|
118
120
|
- .open\_page method takes page label, directs browser to that page and returns corresponding page\_object
|
119
121
|
- PageObjectWrapper.current\_page points to the opened page\_object
|
122
|
+
- it's possible to set page\_object locator in 2 different ways: specifying full url (like in example) or specifying PageObjectWrapper.domain and page\_object local path (like in specs)
|
123
|
+
|
124
|
+
#### page\_object.xxx
|
125
|
+
Defined elements can be accessed with their labels.
|
126
|
+
- element from an element\_set is corresponds to real Watir::Element
|
127
|
+
- elemets\_set corresponds to an Array of Watir::Element
|
128
|
+
|
129
|
+
*preconditions*
|
130
|
+
**tp** is a :some\_test\_page object opened in the browser
|
131
|
+
|
132
|
+
tp.tf # => Watir::TextField
|
133
|
+
tp.rb # => Watir::Radio
|
134
|
+
tp.test_elements # => Array of Watir elements
|
135
|
+
|
136
|
+
|
120
137
|
|
121
138
|
#### feed\_xxx
|
122
139
|
*preconditions*
|
123
|
-
tp is a :some\_test\_page object opened in the browser
|
140
|
+
**tp** is a :some\_test\_page object opened in the browser
|
124
141
|
|
125
142
|
context "argument = :fresh_food" do
|
126
143
|
it "populates all xxx elements with :fresh_food" do
|
@@ -146,7 +163,7 @@ tp is a :some\_test\_page object opened in the browser
|
|
146
163
|
|
147
164
|
#### fire\_xxx
|
148
165
|
*preconditions*
|
149
|
-
tp is a :some\_test\_page object opened in the browser
|
166
|
+
**tp** is a :some\_test\_page object opened in the browser
|
150
167
|
|
151
168
|
it "executes fire_block in Watir::Browser context" do
|
152
169
|
tp = PageObjectWrapper.open_page(:some_test_page)
|
@@ -165,7 +182,7 @@ tp is a :some\_test\_page object opened in the browser
|
|
165
182
|
|
166
183
|
#### select\_from\_xxx
|
167
184
|
*preconditions*
|
168
|
-
tp is a :some\_test\_page object opened in the browser
|
185
|
+
**tp** is a :some\_test\_page object opened in the browser
|
169
186
|
its syntax is close to SQL *'select column1 from page\_object.some\_table where column2 = string\_or\_regexp'*
|
170
187
|
page\_object.select\_from\_xxx( :column1, :column2 => 'string\_or\_regexp' )
|
171
188
|
correct arguments are:
|
@@ -213,8 +230,7 @@ TODO
|
|
213
230
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
214
231
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
215
232
|
4. Push to the branch (`git push origin my-new-feature`)
|
216
|
-
5. Create new Pull Request
|
217
|
-
page\_object\_wrapper
|
218
|
-
===================
|
233
|
+
5. Create new Pull Request
|
219
234
|
|
235
|
+
##page\_object\_wrapper
|
220
236
|
Wraps watir-webdriver with convenient testing interface, based on PageObjects automation testing pattern. Simplifies resulting automated test understanding.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bad_pages/bad_page.rb
CHANGED
@@ -38,6 +38,8 @@ PageObjectWrapper.define_page(:some_test_page) do
|
|
38
38
|
textarea(:id => 'f2').set data
|
39
39
|
end
|
40
40
|
|
41
|
+
action_alias(:fill_textarea_alias, :some_test_page){ action :fill_textarea }
|
42
|
+
|
41
43
|
table(:table_without_header) do
|
42
44
|
locator :summary => 'Each row names a Nordic country and specifies its total area and land area, in square kilometers'
|
43
45
|
end
|
@@ -5,12 +5,13 @@ include PageObjectWrapper
|
|
5
5
|
require 'ElementsSet'
|
6
6
|
require 'Element'
|
7
7
|
require 'Action'
|
8
|
+
require 'Alias'
|
8
9
|
require 'Table'
|
9
10
|
require 'Pagination'
|
10
11
|
require 'known_elements'
|
11
12
|
|
12
13
|
class PageObject < DslElementWithLocator
|
13
|
-
attr_reader :esets, :elements, :actions, :tables, :paginations, :uniq_element_type, :uniq_element_hash
|
14
|
+
attr_reader :esets, :elements, :actions, :aliases, :tables, :paginations, :uniq_element_type, :uniq_element_hash
|
14
15
|
@@browser = nil
|
15
16
|
@@pages = []
|
16
17
|
@@current_page = nil
|
@@ -30,6 +31,7 @@ class PageObject < DslElementWithLocator
|
|
30
31
|
@esets = []
|
31
32
|
@elements = []
|
32
33
|
@actions = []
|
34
|
+
@aliases = []
|
33
35
|
@tables = []
|
34
36
|
@paginations = []
|
35
37
|
end
|
@@ -60,6 +62,10 @@ class PageObject < DslElementWithLocator
|
|
60
62
|
# page_object.fire_some_action
|
61
63
|
a = action_for($1)
|
62
64
|
fire_action(a, *args)
|
65
|
+
when (FIRE_ACTION.match(method_name) and has_alias?($1))
|
66
|
+
# page_object.fire_some_action
|
67
|
+
a = alias_for($1)
|
68
|
+
fire_action(a, *args)
|
63
69
|
when (SELECT_FROM.match(method_name) and has_table?($1))
|
64
70
|
# page_object.select_from_some_table(:header_column, {:column => 'value'})
|
65
71
|
table = table_for($1)
|
@@ -99,6 +105,9 @@ class PageObject < DslElementWithLocator
|
|
99
105
|
when (FIRE_ACTION.match(method_name) and has_action?($1))
|
100
106
|
# page_object.fire_some_action
|
101
107
|
true
|
108
|
+
when (FIRE_ACTION.match(method_name) and has_alias?($1))
|
109
|
+
# page_object.fire_some_action
|
110
|
+
true
|
102
111
|
when (SELECT_FROM.match(method_name) and has_table?($1))
|
103
112
|
# page_object.select_from_some_table(:header_column, {:column => 'value'})
|
104
113
|
true
|
@@ -162,6 +171,13 @@ class PageObject < DslElementWithLocator
|
|
162
171
|
a
|
163
172
|
end
|
164
173
|
|
174
|
+
def action_alias(label, next_page, &block)
|
175
|
+
a = Alias.new(label, next_page)
|
176
|
+
a.instance_eval(&block)
|
177
|
+
@aliases << a
|
178
|
+
a
|
179
|
+
end
|
180
|
+
|
165
181
|
def table(label, &block)
|
166
182
|
t = Table.new(label)
|
167
183
|
t.instance_eval(&block)
|
@@ -208,6 +224,16 @@ class PageObject < DslElementWithLocator
|
|
208
224
|
action_output.unshift "action(#{a.label_value.inspect}):\n" if not action_output.empty?
|
209
225
|
output += action_output
|
210
226
|
}
|
227
|
+
@aliases.each{|a|
|
228
|
+
alias_output = []
|
229
|
+
alias_output << "\talias #{a.label_value.inspect} already defined\n" if labeled(@aliases).count(a.label_value) > 1
|
230
|
+
alias_output << "\tlabel #{a.label_value.inspect} not a Symbol\n" if not a.label_value.is_a?(Symbol)
|
231
|
+
alias_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
|
232
|
+
alias_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
|
233
|
+
alias_output << "\taction #{a.action_value.inspect} not known Action\n" if not labeled(@actions).include? a.action_value
|
234
|
+
alias_output.unshift "alias(#{a.label_value.inspect}):\n" if not alias_output.empty?
|
235
|
+
output += alias_output
|
236
|
+
}
|
211
237
|
@tables.each{|t|
|
212
238
|
table_output = []
|
213
239
|
table_output << "\ttable #{t.label_value.inspect} already defined\n" if labeled(@tables).count(t.label_value) > 1
|
@@ -280,7 +306,8 @@ private
|
|
280
306
|
|
281
307
|
def fire_action(a, *args)
|
282
308
|
raise PageObjectWrapper::BrowserNotFound if @@browser.nil?
|
283
|
-
|
309
|
+
block = (a.is_a? Action)? a.fire_block_value : action_for(a.action_value).fire_block_value
|
310
|
+
@@browser.instance_exec args, &block
|
284
311
|
self.class.map_current_page a.next_page_value
|
285
312
|
@@current_page
|
286
313
|
end
|
@@ -349,6 +376,10 @@ private
|
|
349
376
|
labeled(@actions).include?(label.to_sym)
|
350
377
|
end
|
351
378
|
|
379
|
+
def has_alias?(label)
|
380
|
+
labeled(@aliases).include?(label.to_sym)
|
381
|
+
end
|
382
|
+
|
352
383
|
def eset_for(label)
|
353
384
|
@esets[labeled(@esets).index(label.to_sym)]
|
354
385
|
end
|
@@ -368,4 +399,8 @@ private
|
|
368
399
|
def action_for(label)
|
369
400
|
@actions[labeled(@actions).index(label.to_sym)]
|
370
401
|
end
|
402
|
+
|
403
|
+
def alias_for(label)
|
404
|
+
@aliases[labeled(@aliases).index(label.to_sym)]
|
405
|
+
end
|
371
406
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'page_object_wrapper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "page_object_wrapper"
|
8
|
+
gem.version = PageObjectWrapper::VERSION
|
9
|
+
gem.authors = ["Evgeniy Khatko"]
|
10
|
+
gem.email = ["evgeniy.khatko@gmail.com"]
|
11
|
+
gem.description = %q{Wraps watir-webdriver with convenient testing interface, based on PageObjects automation testing pattern. Simplifies resulting automated test understanding.}
|
12
|
+
gem.summary = %q{Wraps watir-webdriver with convenient testing interface.}
|
13
|
+
gem.homepage = "https://github.com/evgeniy-khatko/page_object_wrapper"
|
14
|
+
gem.add_dependency "watir-webdriver"
|
15
|
+
gem.add_development_dependency "rspec", ">= 2.0.0"
|
16
|
+
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib","lib/page_object_wrapper"]
|
22
|
+
end
|
@@ -39,6 +39,9 @@ describe "define_page_object" do
|
|
39
39
|
specify { subject.actions.collect(&:label_value).should include(:press_cool_button)}
|
40
40
|
it { should respond_to(:fire_press_cool_button) }
|
41
41
|
|
42
|
+
specify { subject.aliases.collect(&:label_value).should include(:fill_textarea_alias)}
|
43
|
+
it { should respond_to(:fire_fill_textarea_alias) }
|
44
|
+
|
42
45
|
specify { subject.tables.collect(&:label_value).should include(:table_without_header)}
|
43
46
|
it { should respond_to(:select_from_table_without_header) }
|
44
47
|
it { should respond_to(:select_from_table_with_header) }
|
@@ -101,7 +104,7 @@ describe "define_page_object" do
|
|
101
104
|
it_should_behave_like "a label"
|
102
105
|
end
|
103
106
|
|
104
|
-
describe "action
|
107
|
+
describe "action attributes" do
|
105
108
|
it { should respond_to(:next_page_value) }
|
106
109
|
it { should respond_to(:fire_block_value) }
|
107
110
|
|
@@ -110,6 +113,24 @@ describe "define_page_object" do
|
|
110
113
|
end
|
111
114
|
end
|
112
115
|
|
116
|
+
context "action alias" do
|
117
|
+
subject { page_object.aliases[page_object.aliases.collect(&:label_value).index(:fill_textarea_alias)] }
|
118
|
+
|
119
|
+
it { should be_a(Alias) }
|
120
|
+
|
121
|
+
describe "alias label" do
|
122
|
+
it_should_behave_like "a label"
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "alias attributes" do
|
126
|
+
it { should respond_to(:next_page_value) }
|
127
|
+
it { should respond_to(:action_value) }
|
128
|
+
|
129
|
+
its(:next_page_value){ should eq :some_test_page }
|
130
|
+
its(:action_value) { should eq :fill_textarea }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
113
134
|
context "table" do
|
114
135
|
subject { page_object.tables[page_object.tables.collect(&:label_value).index(:table_without_header)] }
|
115
136
|
|
data/spec/fire_event_spec.rb
CHANGED
@@ -17,25 +17,22 @@ describe "page_object.fire_xxx" do
|
|
17
17
|
before(:all){
|
18
18
|
@b = Watir::Browser.new
|
19
19
|
PageObjectWrapper.use_browser @b
|
20
|
-
begin
|
21
20
|
PageObjectWrapper.load('./good_pages')
|
22
|
-
rescue
|
23
|
-
end
|
24
21
|
}
|
25
22
|
after(:all){ PageObjectWrapper.browser.close }
|
26
23
|
|
24
|
+
it "executes fire_block in Watir::Browser context" do
|
25
|
+
tp = PageObjectWrapper.open_page(:some_test_page)
|
26
|
+
tp.fire_fill_textarea
|
27
|
+
@b.textarea(:id => 'f2').value.should eq('Default data')
|
28
|
+
end
|
29
|
+
|
27
30
|
context "xxx not found among current_page actions" do
|
28
31
|
it "raises NoMethodError" do
|
29
32
|
tp = PageObjectWrapper.current_page
|
30
33
|
expect{tp.fire_nonexistent_action}.to raise_error(NoMethodError)
|
31
34
|
end
|
32
35
|
end
|
33
|
-
|
34
|
-
it "executes fire_block in Watir::Browser context" do
|
35
|
-
tp = PageObjectWrapper.open_page(:some_test_page)
|
36
|
-
tp.fire_fill_textarea
|
37
|
-
@b.textarea(:id => 'f2').value.should eq('Default data')
|
38
|
-
end
|
39
36
|
|
40
37
|
it "can be invoked with parameters" do
|
41
38
|
tp = PageObjectWrapper.current_page
|
@@ -43,11 +40,20 @@ describe "page_object.fire_xxx" do
|
|
43
40
|
@b.textarea(:id => 'f2').value.should eq('User defined data')
|
44
41
|
end
|
45
42
|
|
43
|
+
context "xxx is alias" do
|
44
|
+
it "executes corresponding action" do
|
45
|
+
tp = PageObjectWrapper.open_page(:some_test_page)
|
46
|
+
tp.fire_fill_textarea_alias
|
47
|
+
@b.textarea(:id => 'f2').value.should eq('Default data')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
46
51
|
it "returns next_page" do
|
47
52
|
tp = PageObjectWrapper.current_page
|
48
53
|
np = tp.fire_press_cool_button
|
49
54
|
np.should be_a(PageObject)
|
50
55
|
np.label_value.should eq(:test_page_with_table)
|
51
56
|
end
|
57
|
+
|
52
58
|
end
|
53
59
|
end
|
data/spec/load_spec.rb
CHANGED
@@ -30,6 +30,11 @@ action(""):
|
|
30
30
|
label "" not a Symbol
|
31
31
|
next_page nil not a Symbol
|
32
32
|
next_page nil unknown page_object
|
33
|
+
alias(""):
|
34
|
+
label "" not a Symbol
|
35
|
+
next_page nil not a Symbol
|
36
|
+
next_page nil unknown page_object
|
37
|
+
action "unknown action" not known Action
|
33
38
|
table(""):
|
34
39
|
label "" not a Symbol
|
35
40
|
locator nil not a meaningful Hash
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page_object_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-19 00:00:00.
|
12
|
+
date: 2012-12-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watir-webdriver
|
16
|
-
requirement: &
|
16
|
+
requirement: &5265420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *5265420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &5243480 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 2.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *5243480
|
36
36
|
description: Wraps watir-webdriver with convenient testing interface, based on PageObjects
|
37
37
|
automation testing pattern. Simplifies resulting automated test understanding.
|
38
38
|
email:
|
@@ -42,7 +42,10 @@ extensions: []
|
|
42
42
|
extra_rdoc_files: []
|
43
43
|
files:
|
44
44
|
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- LICENSE.txt
|
45
47
|
- README.md
|
48
|
+
- Rakefile
|
46
49
|
- bad_pages/bad_page.rb
|
47
50
|
- good_pages/another_test_page.rb
|
48
51
|
- good_pages/some_test_page.rb
|
@@ -50,6 +53,7 @@ files:
|
|
50
53
|
- img/scheme.png
|
51
54
|
- lib/page_object_wrapper.rb
|
52
55
|
- lib/page_object_wrapper/Action.rb
|
56
|
+
- lib/page_object_wrapper/Alias.rb
|
53
57
|
- lib/page_object_wrapper/Dsl.rb
|
54
58
|
- lib/page_object_wrapper/Element.rb
|
55
59
|
- lib/page_object_wrapper/ElementsSet.rb
|
@@ -59,6 +63,7 @@ files:
|
|
59
63
|
- lib/page_object_wrapper/Table.rb
|
60
64
|
- lib/page_object_wrapper/known_elements.rb
|
61
65
|
- lib/page_object_wrapper/version.rb
|
66
|
+
- page_object_wrapper.gemspec
|
62
67
|
- spec/define_page_object_spec.rb
|
63
68
|
- spec/defined_elements_spec.rb
|
64
69
|
- spec/feed_elements_spec.rb
|