page_object_wrapper 1.1.2 → 1.2.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/README.md +35 -7
- data/good_pages/dynamic_url_page.rb +4 -0
- data/good_pages/{google_wron_uniq_page.rb → google_wrong_uniq_page.rb} +0 -0
- data/img/scheme.png +0 -0
- data/lib/page_object_wrapper.rb +2 -2
- data/lib/page_object_wrapper/Exceptions.rb +1 -0
- data/lib/page_object_wrapper/PageObject.rb +35 -3
- data/lib/page_object_wrapper/version.rb +1 -1
- data/page_object_wrapper.gemspec +0 -1
- data/spec/get_food_spec.rb +28 -0
- data/spec/open_spec.rb +41 -7
- data/spec/select_from_spec.rb +57 -18
- metadata +10 -7
data/README.md
CHANGED
@@ -99,8 +99,10 @@ where required attributes are marked with (*)
|
|
99
99
|
end
|
100
100
|
|
101
101
|
here we have defined a page object with locator (url) = 'http://www.cs.tut.fi/~jkorpela/www/testel.html'
|
102
|
-
uniq\_xxx is used to define a uniq element on that page, which uniquely identifies the page from other pages
|
103
|
-
uniq\_xxx is being checked when openning the page with PageObjectWrapper.open\_page and when running an page\_object.action
|
102
|
+
- uniq\_xxx is used to define a uniq element on that page, which uniquely identifies the page from other pages
|
103
|
+
- uniq\_xxx is being checked when openning the page with PageObjectWrapper.open\_page and when running an page\_object.action
|
104
|
+
- all defined elements have labels
|
105
|
+
- action and action_alias defined with labels and next_pages
|
104
106
|
|
105
107
|
#### openning the page
|
106
108
|
*preconditions*
|
@@ -122,8 +124,18 @@ There is a directory, where we've defined a page\_object inside a \*\_page.rb fi
|
|
122
124
|
- .open\_page method takes page label, directs browser to that page and returns corresponding page\_object
|
123
125
|
- PageObjectWrapper.current\_page points to the opened page\_object
|
124
126
|
- 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)
|
125
|
-
|
126
|
-
|
127
|
+
- it's possible to set dynamic urls for pages, e.g.
|
128
|
+
PageObjectWrapper.define_page(:google) do
|
129
|
+
locator 'www.google.com/:some_param'
|
130
|
+
end
|
131
|
+
PageObjectWrapper.open_page(:google, :some_param => 'advanced_search') # => 'http://google.com/advanced_search'
|
132
|
+
|
133
|
+
#### page\_object.xxx
|
134
|
+
*parameters*
|
135
|
+
no
|
136
|
+
*returns*
|
137
|
+
Watir::XXX element
|
138
|
+
|
127
139
|
Defined elements can be accessed with their labels.
|
128
140
|
- element from an element\_set is corresponds to real Watir::Element
|
129
141
|
- elemets\_set corresponds to an Array of Watir::Element
|
@@ -137,7 +149,12 @@ Defined elements can be accessed with their labels.
|
|
137
149
|
|
138
150
|
|
139
151
|
|
140
|
-
#### feed\_xxx
|
152
|
+
#### feed\_xxx
|
153
|
+
*parameters*
|
154
|
+
:fresh\_food, :missing\_food
|
155
|
+
*returns*
|
156
|
+
current\_page
|
157
|
+
|
141
158
|
*preconditions*
|
142
159
|
**tp** is a :some\_test\_page object opened in the browser
|
143
160
|
|
@@ -163,7 +180,12 @@ Defined elements can be accessed with their labels.
|
|
163
180
|
@b.textarea(:id => 'f2').value.should eq('Default data')
|
164
181
|
|
165
182
|
|
166
|
-
#### fire\_xxx
|
183
|
+
#### fire\_xxx
|
184
|
+
*parameters*
|
185
|
+
optional arguments defined inside action
|
186
|
+
*returns*
|
187
|
+
next\_page from xxx action
|
188
|
+
|
167
189
|
*preconditions*
|
168
190
|
**tp** is a :some\_test\_page object opened in the browser
|
169
191
|
|
@@ -185,7 +207,13 @@ Defined elements can be accessed with their labels.
|
|
185
207
|
tp.fire_fill_textarea_alias
|
186
208
|
@b.textarea(:id => 'f2').value.should eq('Default data')
|
187
209
|
|
188
|
-
#### select\_from\_xxx
|
210
|
+
#### select\_from\_xxx
|
211
|
+
*parameters*
|
212
|
+
:column\_1, :column\_2 => search\_value, :optional\_next\_page
|
213
|
+
*returns*
|
214
|
+
Watir::TableCell if next\_page not specified
|
215
|
+
next\_page if it is specified
|
216
|
+
|
189
217
|
*preconditions*
|
190
218
|
**tp** is a :some\_test\_page object opened in the browser
|
191
219
|
its syntax is close to SQL *'select column1 from page\_object.some\_table where column2 = string\_or\_regexp'*
|
File without changes
|
data/img/scheme.png
CHANGED
Binary file
|
data/lib/page_object_wrapper.rb
CHANGED
@@ -123,13 +123,21 @@ class PageObject < DslElementWithLocator
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
def self.open_page label
|
126
|
+
def self.open_page label, optional_hash=nil
|
127
127
|
raise PageObjectWrapper::BrowserNotFound if @@browser.nil?
|
128
128
|
raise PageObjectWrapper::UnknownPageObject, label if not @@pages.collect(&:label_value).include?(label)
|
129
129
|
page_object = PageObject.find_page_object(label)
|
130
130
|
url = ''
|
131
131
|
url += @@domain if page_object.locator_value[0]=='/'
|
132
132
|
url += page_object.locator_value
|
133
|
+
if not (optional_hash.nil? or optional_hash.empty?)
|
134
|
+
optional_hash.each{|k,v|
|
135
|
+
raise ArgumentError, "#{k.inspect} not Symbol" if not k.is_a? Symbol
|
136
|
+
raise ArgumentError, "#{v.inspect} not meaningful String" if not v.is_a? String or v.empty?
|
137
|
+
raise PageObjectWrapper::DynamicUrl, "#{k.inspect} not known parameter" if not url.match(':'+k.to_s)
|
138
|
+
url.gsub!(/:#{k.to_s}/, v)
|
139
|
+
}
|
140
|
+
end
|
133
141
|
@@browser.goto url
|
134
142
|
end
|
135
143
|
|
@@ -168,6 +176,14 @@ class PageObject < DslElementWithLocator
|
|
168
176
|
eset = ElementsSet.new(label)
|
169
177
|
eset.instance_eval(&block)
|
170
178
|
@esets << eset
|
179
|
+
eset.elements.each{|e|
|
180
|
+
PageObject.send :define_method, (e.label_value.to_s+'_fresh_food').to_sym do
|
181
|
+
e.fresh_food_value
|
182
|
+
end
|
183
|
+
PageObject.send :define_method, (e.label_value.to_s+'_missing_food').to_sym do
|
184
|
+
e.missing_food_value
|
185
|
+
end
|
186
|
+
}
|
171
187
|
@elements += eset.elements
|
172
188
|
eset
|
173
189
|
end
|
@@ -318,7 +334,9 @@ private
|
|
318
334
|
@@current_page
|
319
335
|
end
|
320
336
|
|
321
|
-
def select_from_table(table, header,
|
337
|
+
def select_from_table(table, header, *args)
|
338
|
+
where = args[0]
|
339
|
+
next_page = args[1]
|
322
340
|
raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
|
323
341
|
t = @@browser.table(table.locator_value)
|
324
342
|
raise ArgumentError, "#{header.inspect} not a Symbol" if not header.is_a? Symbol
|
@@ -326,6 +344,11 @@ private
|
|
326
344
|
search_for_index = table.header_value.index(header)
|
327
345
|
found = nil
|
328
346
|
|
347
|
+
if not next_page.nil?
|
348
|
+
raise ArgumentError, "#{next_page.inspect} not a Symbol" if not next_page.is_a? Symbol
|
349
|
+
raise ArgumentError, "#{next_page.inspect} not known Page" if not labeled(@@pages).include?(next_page)
|
350
|
+
end
|
351
|
+
|
329
352
|
if not where.nil?
|
330
353
|
raise ArgumentError, "#{where.inspect} not a meaningful Hash" if not where.is_a? Hash or where.empty?
|
331
354
|
raise ArgumentError, "#{where.inspect} has more than 1 keys" if not where.keys.length == 1
|
@@ -346,7 +369,16 @@ private
|
|
346
369
|
else # where == nil
|
347
370
|
found = t.rows.last.cells[search_for_index]
|
348
371
|
end
|
349
|
-
|
372
|
+
|
373
|
+
if not next_page.nil?
|
374
|
+
if not found.nil?
|
375
|
+
return PageObject.find_page_object(next_page)
|
376
|
+
else
|
377
|
+
return nil
|
378
|
+
end
|
379
|
+
else # next_page == nil
|
380
|
+
return found
|
381
|
+
end
|
350
382
|
end
|
351
383
|
|
352
384
|
def each_pagination
|
data/page_object_wrapper.gemspec
CHANGED
@@ -13,7 +13,6 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.homepage = "https://github.com/evgeniy-khatko/page_object_wrapper"
|
14
14
|
gem.add_dependency "watir-webdriver"
|
15
15
|
gem.add_development_dependency "rspec", ">= 2.0.0"
|
16
|
-
|
17
16
|
|
18
17
|
gem.files = `git ls-files`.split($/)
|
19
18
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe "getting food specified for element" do
|
3
|
+
subject{ PageObjectWrapper.receive_page(:some_test_page) }
|
4
|
+
|
5
|
+
describe "page_object.xxx_fresh_food" do
|
6
|
+
it "raises NoMethodError if xxx is not known element" do
|
7
|
+
expect{ subject.unknown_fresh_food }.to raise_error(NoMethodError)
|
8
|
+
end
|
9
|
+
|
10
|
+
it{ should respond_to(:tf_fresh_food) }
|
11
|
+
its(:tf_fresh_food){ should eq 'some fresh food' }
|
12
|
+
|
13
|
+
it{ should respond_to(:ta_fresh_food) }
|
14
|
+
its(:ta_fresh_food){ should eq 'default fresh food' }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "page_object.xxx_missing_food" do
|
18
|
+
it "raises NoMethodError if xxx is not known element" do
|
19
|
+
expect{ subject.unknown_fresh_food }.to raise_error(NoMethodError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it{ should respond_to(:tf_fresh_food) }
|
23
|
+
its(:tf_missing_food){ should eq 'some missing food' }
|
24
|
+
|
25
|
+
it{ should respond_to(:ta_fresh_food) }
|
26
|
+
its(:ta_missing_food){ should eq 'default missing food' }
|
27
|
+
end
|
28
|
+
end
|
data/spec/open_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "PageObjectWrapper.open_page" do
|
4
4
|
context "browser is closed" do
|
5
|
-
it "raises
|
6
|
-
expect{ PageObjectWrapper.open_page(:google_page) }.to raise_error(
|
5
|
+
it "raises PageObjectWrapper::BrowserNotFound" do
|
6
|
+
expect{ PageObjectWrapper.open_page(:google_page) }.to raise_error(PageObjectWrapper::BrowserNotFound)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -17,15 +17,49 @@ describe "PageObjectWrapper.open_page" do
|
|
17
17
|
after(:all){ PageObjectWrapper.browser.quit }
|
18
18
|
|
19
19
|
it "raises errors" do
|
20
|
-
expect{ PageObjectWrapper.open_page(:first_arg, :second_arg) }.to raise_error(ArgumentError)
|
21
20
|
expect{ PageObjectWrapper.open_page(:unknown_page) }.to raise_error(PageObjectWrapper::UnknownPageObject)
|
22
21
|
expect{ PageObjectWrapper.open_page(:wrong_google_page) }.to raise_error(PageObjectWrapper::UnmappedPageObject)
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
context "no optional arguments" do
|
25
|
+
it "returns opened PageObject instance" do
|
26
|
+
p = PageObjectWrapper.open_page(:google_page)
|
27
|
+
p.should be_an_instance_of(PageObject)
|
28
|
+
p.label_value.should eq(:google_page)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with optional arguments" do
|
33
|
+
context "optional hash key not Symbol" do
|
34
|
+
it "raises ArgumentError" do
|
35
|
+
expect{ PageObjectWrapper.open_page(:dynamic_url_page, 'a string' => 'a string') }.to raise_error ArgumentError, '"a string" not Symbol'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context "optional hash value not meaningful String" do
|
39
|
+
it "raises ArgumentError" do
|
40
|
+
expect{ PageObjectWrapper.open_page(:dynamic_url_page, :param => '') }.to raise_error ArgumentError, '"" not meaningful String'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
context "one optional parameter not known" do
|
44
|
+
it "raises PageObjectWrapper::DynamicUrl" do
|
45
|
+
expect{ PageObjectWrapper.open_page(:dynamic_url_page, :domain => 'google.com', :unknown_url_parameter => '123') }.to raise_error PageObjectWrapper::DynamicUrl, ":unknown_url_parameter not known parameter"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context "at least one dynamic parameter specified" do
|
49
|
+
it "opens page with all parameters replaced with specified" do
|
50
|
+
begin
|
51
|
+
PageObjectWrapper.open_page(:dynamic_url_page, :domain => 'google.com')
|
52
|
+
rescue PageObjectWrapper::UnmappedPageObject
|
53
|
+
PageObject.browser.url.should =~ /google.\w+\/:path/
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
context "all dynamic parameters specified" do
|
58
|
+
it "opens page with all parameters replaced with specified" do
|
59
|
+
PageObjectWrapper.open_page(:dynamic_url_page, :domain => 'google.com', :path => 'advanced_search')
|
60
|
+
PageObject.browser.url.should =~ /google.\w+\/advanced_search/
|
61
|
+
end
|
62
|
+
end
|
29
63
|
end
|
30
64
|
|
31
65
|
context "domain is not specified" do
|
data/spec/select_from_spec.rb
CHANGED
@@ -17,6 +17,7 @@ describe "page_object.select_from_xxx" do
|
|
17
17
|
let!(:tp){ PageObjectWrapper.open_page(:some_test_page)}
|
18
18
|
|
19
19
|
context "wrong arguments" do
|
20
|
+
|
20
21
|
it "raises ArgumentError if first_arg not a Symbol" do
|
21
22
|
expect{ tp.select_from_table_without_header(nil,{}) }.to raise_error ArgumentError, "nil not a Symbol"
|
22
23
|
end
|
@@ -38,35 +39,73 @@ describe "page_object.select_from_xxx" do
|
|
38
39
|
it "raises Watir::Exception::UnknownObjectException if requested for non existing column" do
|
39
40
|
expect{ tp.select_from_table_without_header(:column_3).text }.to raise_error(Watir::Exception::UnknownObjectException)
|
40
41
|
end
|
42
|
+
|
43
|
+
context "next_page specified" do
|
44
|
+
it "raises ArgumentError if next_page not symbol" do
|
45
|
+
expect{ tp.select_from_table_without_header(:column_1, nil, 'a string') }.to raise_error ArgumentError, '"a string" not a Symbol'
|
46
|
+
expect{ tp.select_from_table_without_header(:column_1, {:column_1 => 'Ireland'}, 'a string') }.to raise_error ArgumentError, '"a string" not a Symbol'
|
47
|
+
end
|
48
|
+
it "raises ArgumentError if next_page not loaded" do
|
49
|
+
expect{ tp.select_from_table_without_header(:column_1, nil, :nonexistent_page) }.to raise_error ArgumentError, ':nonexistent_page not known Page'
|
50
|
+
expect{ tp.select_from_table_without_header(:column_1, {:column_1 => 'Ireland'}, :nonexistent_page) }.to raise_error ArgumentError, ':nonexistent_page not known Page'
|
51
|
+
end
|
52
|
+
end
|
41
53
|
end
|
42
54
|
|
43
55
|
context "where == nil" do
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
56
|
+
context "next_page not specified" do
|
57
|
+
it "returns last row value from provided column" do
|
58
|
+
tp.select_from_table_without_header(:column_0).text.should eq 'Sweden'
|
59
|
+
tp.select_from_table_without_header(:column_1).text.should eq '449,964'
|
60
|
+
tp.select_from_table_without_header(:column_2).text.should eq '410,928'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
context "next_page specified" do
|
64
|
+
it "returns last row value from provided column" do
|
65
|
+
tp.select_from_table_without_header(:column_0, nil, :some_test_page).should eq PageObjectWrapper.receive_page(:some_test_page)
|
66
|
+
end
|
48
67
|
end
|
49
68
|
end
|
50
69
|
|
51
70
|
context "where not nil" do
|
52
|
-
context "
|
53
|
-
|
54
|
-
|
55
|
-
|
71
|
+
context "next_page not specified" do
|
72
|
+
context "found by String" do
|
73
|
+
it "returns found cells" do
|
74
|
+
tp.select_from_table_without_header(:column_0, :column_1 => '103,000').text.should eq 'Iceland'
|
75
|
+
tp.select_from_table_with_header(:country, :total_area => '337,030').text.should eq 'Finland'
|
76
|
+
end
|
77
|
+
it "returns nil" do
|
78
|
+
tp.select_from_table_without_header(:column_0, :column_1 => '123').should eq nil
|
79
|
+
tp.select_from_table_with_header(:country, :total_area => '123').should eq nil
|
80
|
+
end
|
56
81
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
82
|
+
context "found by Regexp" do
|
83
|
+
it "returns found cells" do
|
84
|
+
tp.select_from_table_without_header(:column_0, :column_1 => /103/).text.should eq 'Iceland'
|
85
|
+
tp.select_from_table_with_header(:country, :total_area => /337/).text.should eq 'Finland'
|
86
|
+
end
|
87
|
+
it "returns nil" do
|
88
|
+
tp.select_from_table_without_header(:column_0, :column_1 => /123/).should eq nil
|
89
|
+
tp.select_from_table_with_header(:country, :total_area => /123/).should eq nil
|
90
|
+
end
|
60
91
|
end
|
61
92
|
end
|
62
|
-
context "
|
63
|
-
|
64
|
-
|
65
|
-
|
93
|
+
context "next_page specified" do
|
94
|
+
context "found by String" do
|
95
|
+
it "returns found cells" do
|
96
|
+
tp.select_from_table_without_header(:column_0, {:column_1 => '103,000'}, :some_test_page).should eq PageObjectWrapper.receive_page(:some_test_page)
|
97
|
+
end
|
98
|
+
it "returns nil" do
|
99
|
+
tp.select_from_table_without_header(:column_0, {:column_1 => '123'}, :some_test_page).should eq nil
|
100
|
+
end
|
66
101
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
102
|
+
context "found by Regexp" do
|
103
|
+
it "returns found cells" do
|
104
|
+
tp.select_from_table_without_header(:column_0, {:column_1 => /103/}, :some_test_page).should eq PageObjectWrapper.receive_page(:some_test_page)
|
105
|
+
end
|
106
|
+
it "returns nil" do
|
107
|
+
tp.select_from_table_without_header(:column_0, {:column_1 => /123/}, :some_test_page).should eq nil
|
108
|
+
end
|
70
109
|
end
|
71
110
|
end
|
72
111
|
end
|
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.2.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-
|
12
|
+
date: 2012-12-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watir-webdriver
|
16
|
-
requirement: &
|
16
|
+
requirement: &8430060 !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: *8430060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &8455200 !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: *8455200
|
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:
|
@@ -48,8 +48,9 @@ files:
|
|
48
48
|
- Rakefile
|
49
49
|
- bad_pages/bad_page.rb
|
50
50
|
- good_pages/another_test_page.rb
|
51
|
+
- good_pages/dynamic_url_page.rb
|
51
52
|
- good_pages/google_page.rb
|
52
|
-
- good_pages/
|
53
|
+
- good_pages/google_wrong_uniq_page.rb
|
53
54
|
- good_pages/goole_as_page.rb
|
54
55
|
- good_pages/some_test_page.rb
|
55
56
|
- good_pages/test_table_page.rb
|
@@ -73,6 +74,7 @@ files:
|
|
73
74
|
- spec/feed_elements_spec.rb
|
74
75
|
- spec/fire_event_spec.rb
|
75
76
|
- spec/generate_spec.rb
|
77
|
+
- spec/get_food_spec.rb
|
76
78
|
- spec/load_spec.rb
|
77
79
|
- spec/open_spec.rb
|
78
80
|
- spec/select_from_spec.rb
|
@@ -110,6 +112,7 @@ test_files:
|
|
110
112
|
- spec/feed_elements_spec.rb
|
111
113
|
- spec/fire_event_spec.rb
|
112
114
|
- spec/generate_spec.rb
|
115
|
+
- spec/get_food_spec.rb
|
113
116
|
- spec/load_spec.rb
|
114
117
|
- spec/open_spec.rb
|
115
118
|
- spec/select_from_spec.rb
|