page_object_wrapper 0.0.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +180 -340
- data/bad_pages/bad_page.rb +34 -0
- data/good_pages/another_test_page.rb +14 -0
- data/good_pages/some_test_page.rb +53 -0
- data/good_pages/test_table_page.rb +12 -0
- data/img/scheme.png +0 -0
- data/lib/page_object_wrapper.rb +57 -92
- data/lib/page_object_wrapper/Action.rb +11 -0
- data/lib/page_object_wrapper/Dsl.rb +35 -0
- data/lib/page_object_wrapper/Element.rb +15 -0
- data/lib/page_object_wrapper/ElementsSet.rb +22 -0
- data/lib/page_object_wrapper/Exceptions.rb +7 -21
- data/lib/page_object_wrapper/PageObject.rb +371 -0
- data/lib/page_object_wrapper/Pagination.rb +6 -57
- data/lib/page_object_wrapper/Table.rb +13 -48
- data/lib/page_object_wrapper/known_elements.rb +31 -0
- data/lib/page_object_wrapper/version.rb +1 -1
- data/spec/define_page_object_spec.rb +162 -0
- data/spec/defined_elements_spec.rb +77 -0
- data/spec/feed_elements_spec.rb +95 -0
- data/spec/fire_event_spec.rb +53 -0
- data/spec/generate_spec.rb +20 -0
- data/spec/load_spec.rb +46 -0
- data/spec/open_spec.rb +70 -0
- data/spec/select_from_spec.rb +84 -0
- data/spec/shared_examples.rb +12 -0
- data/spec/spec_helper.rb +2 -15
- metadata +35 -27
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -1
- data/lib/page_object_wrapper/Distribution.rb +0 -43
- data/lib/page_object_wrapper/DynamicClass.rb +0 -31
- data/lib/page_object_wrapper/Editable.rb +0 -13
- data/lib/page_object_wrapper/Form.rb +0 -116
- data/lib/page_object_wrapper/Submitter.rb +0 -8
- data/page_object_wrapper.gemspec +0 -22
- data/spec/example_spec.rb +0 -42
- data/spec/form_spec.rb +0 -176
- data/spec/page_object_spec.rb +0 -173
- data/spec/pagination_spec.rb +0 -14
- data/spec/table_spec.rb +0 -52
- data/spec/test_data_spec.rb +0 -38
data/spec/page_object_spec.rb
DELETED
@@ -1,173 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe "Page object" do
|
5
|
-
describe "PageObjectWrapper" do
|
6
|
-
let(:google_search_page_class){
|
7
|
-
class GoogleSearchPage < PageObjectWrapper::Page
|
8
|
-
attr_accessor :find_form
|
9
|
-
@url="/"
|
10
|
-
def initialize visit=false
|
11
|
-
super visit
|
12
|
-
end
|
13
|
-
end
|
14
|
-
GoogleSearchPage
|
15
|
-
}
|
16
|
-
|
17
|
-
it "has .start_browser method which puts Watir::Browser.new to Page.accessor by default", :code => 19..20 do
|
18
|
-
PageObjectWrapper.stop_browser # stoping browser of (before :suite) hook
|
19
|
-
PageObjectWrapper.start_browser
|
20
|
-
PageObjectWrapper::Page.accessor.should be_a(Watir::Browser)
|
21
|
-
PageObjectWrapper.stop_browser
|
22
|
-
end
|
23
|
-
|
24
|
-
it "has .stop_browser method which closes browser", :code => 26..27 do
|
25
|
-
PageObjectWrapper.start_browser
|
26
|
-
PageObjectWrapper.stop_browser
|
27
|
-
PageObjectWrapper::Page.accessor.should_not exist
|
28
|
-
end
|
29
|
-
|
30
|
-
it "has .restart_browser method which restart current browser", :code => 31..33 do
|
31
|
-
PageObjectWrapper.start_browser
|
32
|
-
PageObjectWrapper.restart_browser
|
33
|
-
PageObjectWrapper::Page.accessor.should be_a(Watir::Browser)
|
34
|
-
PageObjectWrapper.stop_browser
|
35
|
-
end
|
36
|
-
|
37
|
-
it "has .domain= method which reprsents the domain of DUT", :code => 39..41 do
|
38
|
-
PageObjectWrapper.start_browser
|
39
|
-
PageObjectWrapper.domain = 'www.google.com'
|
40
|
-
google_search_page_class.new(true)
|
41
|
-
PageObjectWrapper::Page.accessor.title.should eq('Google')
|
42
|
-
PageObjectWrapper.stop_browser
|
43
|
-
end
|
44
|
-
|
45
|
-
it "has .timeout= method which sets implicit timeout for webdriver (default is 5 sec)" do
|
46
|
-
pending "not working yet"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "PageObject class and instance in general", :code => 51..60 do
|
51
|
-
let(:page_object){
|
52
|
-
class GoogleSearchPage < PageObjectWrapper::Page
|
53
|
-
attr_accessor :find_form
|
54
|
-
@url="/"
|
55
|
-
def initialize visit=false
|
56
|
-
super visit
|
57
|
-
end
|
58
|
-
end
|
59
|
-
GoogleSearchPage
|
60
|
-
}
|
61
|
-
|
62
|
-
it "PageObject class has @url class variable which can be treated as Page specific path inside current domain", :code => 63 do
|
63
|
-
page_object.url.should eq('/')
|
64
|
-
end
|
65
|
-
|
66
|
-
it "init with \'true\' is similar to openning page in browser", :code => 68..69 do
|
67
|
-
PageObjectWrapper.start_browser
|
68
|
-
google_search_page = page_object.new(true)
|
69
|
-
page_object.accessor.title.should eq('Google')
|
70
|
-
end
|
71
|
-
|
72
|
-
it "init with \'false\' just returns new instanse, but does not opens browser on that page", :code => 74..75 do
|
73
|
-
PageObjectWrapper.restart_browser
|
74
|
-
google_search_page = page_object.new(false)
|
75
|
-
page_object.accessor.title.should_not eq('Google')
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "expected element", :code => 80..103 do
|
80
|
-
let(:google_search_with_wrong_expected_element_page_class){
|
81
|
-
class NotGoogleSearchPage < PageObjectWrapper::Page
|
82
|
-
attr_accessor :find_form
|
83
|
-
@url="/"
|
84
|
-
expected_element :text_field, :name => 'some element that does not exist on the page'
|
85
|
-
|
86
|
-
def initialize visit=false
|
87
|
-
super visit
|
88
|
-
end
|
89
|
-
end
|
90
|
-
NotGoogleSearchPage
|
91
|
-
}
|
92
|
-
let(:google_search_with_correct_expected_element_page_class){
|
93
|
-
class GoogleSearchPage < PageObjectWrapper::Page
|
94
|
-
attr_accessor :find_form
|
95
|
-
@url="/"
|
96
|
-
expected_element :text_field, :name => 'q'
|
97
|
-
|
98
|
-
def initialize visit=false
|
99
|
-
super visit
|
100
|
-
end
|
101
|
-
end
|
102
|
-
GoogleSearchPage
|
103
|
-
}
|
104
|
-
|
105
|
-
it "should raise error when trying to init google_search_with_wrong_expected_element_page_class", :code => 106..113 do
|
106
|
-
begin
|
107
|
-
gsearch_page = google_search_with_wrong_expected_element_page_class.new(true)
|
108
|
-
rescue PageError => e
|
109
|
-
e.should be_a(PageError)
|
110
|
-
e.message.should =~ /PROBLEM:/
|
111
|
-
e.message.should =~ /PAGE:/
|
112
|
-
e.message.should =~ /URL:/
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should init google_search_with_correct_expected_element_page_class successfully", :code => 117..118 do
|
117
|
-
gsearch_page = google_search_with_correct_expected_element_page_class.new(true)
|
118
|
-
gsearch_page.should be_a(google_search_with_correct_expected_element_page_class)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "creation of a PageObject method", :code => 123..163 do
|
123
|
-
let(:pages_definition){
|
124
|
-
class GoogleAdvancedSearchPage < PageObjectWrapper::Page
|
125
|
-
attr_accessor :as_form
|
126
|
-
@url="/advanced_search"
|
127
|
-
expected_element :text_field, :name => 'as_q'
|
128
|
-
def initialize visit=false
|
129
|
-
super visit
|
130
|
-
@as_form = form(GoogleResultsPage, {:name => 'f'})
|
131
|
-
@as_form.editable(:text_field, {:name => 'as_q'}, :with_words, 'with_words default value', true)
|
132
|
-
@as_form.editable(:text_field, {:name => 'as_epq'}, :with_phrase, 'with_phrase default value', true)
|
133
|
-
@as_form.editable(:text_field, {:name => 'as_oq'}, :with_any_word, 'with_any_word default value', false)
|
134
|
-
@as_form.submitter(:input, {:type => 'submit'})
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
class GoogleResultsPage < PageObjectWrapper::Page
|
139
|
-
@url="/"
|
140
|
-
expected_element :button, :name => 'btnG'
|
141
|
-
def initialize visit=false
|
142
|
-
super visit
|
143
|
-
end
|
144
|
-
|
145
|
-
def open_advanced_search
|
146
|
-
@@accessor.span(:id => 'ab_opt_icon').when_present.click
|
147
|
-
@@accessor.a(:id => 'ab_as').when_present.click
|
148
|
-
GoogleAdvancedSearchPage.new
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
class GoogleSearchPage < PageObjectWrapper::Page
|
153
|
-
attr_accessor :find_form
|
154
|
-
@url="/"
|
155
|
-
expected_element :text_field, :name => 'q'
|
156
|
-
def initialize visit=false
|
157
|
-
super visit
|
158
|
-
@find_form = form(GoogleResultsPage, {:action => '/search'})
|
159
|
-
@find_form.editable(:text_field, {:name => 'q'}, :seach_what, '@find_form default value', true)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
{:gsearch_page_class => GoogleSearchPage, :gresults_page => GoogleResultsPage, :gadv_page => GoogleAdvancedSearchPage}
|
163
|
-
}
|
164
|
-
|
165
|
-
it "return value should be another PageObject instance", :code => 166..170 do
|
166
|
-
gsearch_page = pages_definition[:gsearch_page_class].new(true)
|
167
|
-
gsearch_page.find_form.fill_required
|
168
|
-
gresults_page = gsearch_page.find_form.submit(true)
|
169
|
-
gadv_page = gresults_page.open_advanced_search
|
170
|
-
gadv_page.should be_a(pages_definition[:gadv_page])
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
data/spec/pagination_spec.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
describe "Pagination wrapper" do
|
4
|
-
describe "pagination definition" do
|
5
|
-
it "TODO" do
|
6
|
-
pending "Needs to be reimplemented. Current realization is fo rails apps only"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
describe "pagination usage" do
|
10
|
-
it "TODO" do
|
11
|
-
pending "Needs to be reimplemented. Current realization is fo rails apps only"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/spec/table_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe "Table wrapper", :code => 5..19 do
|
5
|
-
before :all do
|
6
|
-
PageObjectWrapper.domain = 'http://wiki.openqa.org'
|
7
|
-
end
|
8
|
-
let(:page_object){
|
9
|
-
class WatirPage < PageObjectWrapper::Page
|
10
|
-
attr_accessor :some_table
|
11
|
-
@url="/display/WTR/HTML+Elements+Supported+by+Watir"
|
12
|
-
expected_element :a, :text => 'HTML Elements Supported by Watir'
|
13
|
-
def initialize visit=false
|
14
|
-
super visit
|
15
|
-
@some_table = table(:class => 'confluenceTable')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
WatirPage
|
19
|
-
}
|
20
|
-
|
21
|
-
describe "table definition" do
|
22
|
-
it "has #table(how_find_hash) method to define a table on the page", :code => 15 do
|
23
|
-
page = page_object.new(true)
|
24
|
-
page.some_table.should be_a(Table)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
describe "table usage" do
|
28
|
-
it "has #cells method which returns all Watir table cells", :code => 29..30 do
|
29
|
-
page = page_object.new(true)
|
30
|
-
page.some_table.cells.first.should be_a(Watir::TableCell)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "has #has_cell?(text) method wich returns true if the table has a cell with specified text", :code => 34..35 do
|
34
|
-
page = page_object.new(true)
|
35
|
-
page.some_table.should have_cell('<td>')
|
36
|
-
end
|
37
|
-
|
38
|
-
it "has #select(column_name, where_hash) method wich returns cell inside specified column wich corresponds to a specified where_hash", :code => 39..42 do
|
39
|
-
page = page_object.new(true)
|
40
|
-
cell = page.some_table.select('HTML tag', :where => {'Watir method' => 'cell'})
|
41
|
-
cell.should be_a(Watir::TableCell)
|
42
|
-
cell.text.should eq '<td>'
|
43
|
-
end
|
44
|
-
|
45
|
-
it "is possible to specify just parts of column names in #select method", :code => 47 do
|
46
|
-
page = page_object.new(true)
|
47
|
-
cell = page.some_table.select('HTML', :where => {'Watir met' => 'cell'})
|
48
|
-
cell.should be_a(Watir::TableCell)
|
49
|
-
cell.text.should eq '<td>'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/spec/test_data_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
describe "TestData class", :code => 5..16 do
|
5
|
-
let(:user1){
|
6
|
-
"login: user1
|
7
|
-
email: user1@example.com
|
8
|
-
password: secret1
|
9
|
-
etc: other data"
|
10
|
-
}
|
11
|
-
let(:user2){
|
12
|
-
"login: user2
|
13
|
-
email: user2@example.com
|
14
|
-
password: secret2
|
15
|
-
etc: other data"
|
16
|
-
}
|
17
|
-
it "is initialized with hash and generates dynamic attributes for an instance", :code => 18..22 do
|
18
|
-
dynamically_defined_user = PageObjectWrapper::TestData.new(YAML.load(user1))
|
19
|
-
dynamically_defined_user.login.should eq 'user1'
|
20
|
-
dynamically_defined_user.email.should eq 'user1@example.com'
|
21
|
-
dynamically_defined_user.password.should eq 'secret1'
|
22
|
-
dynamically_defined_user.etc.should eq 'other data'
|
23
|
-
end
|
24
|
-
|
25
|
-
it "has .find method which allows finding dynamically defined objects", :code => 26..29 do
|
26
|
-
dynamically_defined_user1 = PageObjectWrapper::TestData.new(YAML.load(user1))
|
27
|
-
dynamically_defined_user2 = PageObjectWrapper::TestData.new(YAML.load(user2))
|
28
|
-
user1 = PageObjectWrapper::TestData.find(:login,'user1')
|
29
|
-
user1.email.should eq 'user1@example.com'
|
30
|
-
end
|
31
|
-
it "has .each method which allows navigating between objects", :code => 32..36 do
|
32
|
-
dynamically_defined_user1 = PageObjectWrapper::TestData.new(YAML.load(user1))
|
33
|
-
dynamically_defined_user2 = PageObjectWrapper::TestData.new(YAML.load(user2))
|
34
|
-
PageObjectWrapper::TestData.each{|user|
|
35
|
-
user.etc.should eq 'other data'
|
36
|
-
}
|
37
|
-
end
|
38
|
-
end
|