page-object 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +10 -0
- data/features/check_box.feature +1 -0
- data/features/element.feature +13 -0
- data/features/hidden_field.feature +1 -0
- data/features/html/static_elements.html +7 -0
- data/features/nested_elements.feature +1 -1
- data/features/step_definitions/element_steps.rb +24 -0
- data/features/support/env.rb +0 -25
- data/features/support/hooks.rb +7 -0
- data/features/support/page.rb +3 -1
- data/features/support/persistent_browser.rb +16 -0
- data/lib/page-object/accessors.rb +2 -0
- data/lib/page-object/elements.rb +29 -0
- data/lib/page-object/elements/button.rb +5 -0
- data/lib/page-object/elements/check_box.rb +11 -0
- data/lib/page-object/elements/div.rb +3 -1
- data/lib/page-object/elements/element.rb +2 -1
- data/lib/page-object/elements/file_field.rb +3 -0
- data/lib/page-object/elements/form.rb +2 -0
- data/lib/page-object/elements/heading.rb +9 -1
- data/lib/page-object/elements/hidden_field.rb +5 -3
- data/lib/page-object/elements/image.rb +3 -1
- data/lib/page-object/elements/link.rb +3 -0
- data/lib/page-object/elements/list_item.rb +4 -1
- data/lib/page-object/elements/option.rb +3 -0
- data/lib/page-object/elements/ordered_list.rb +2 -0
- data/lib/page-object/elements/paragraph.rb +3 -1
- data/lib/page-object/elements/radio_button.rb +2 -0
- data/lib/page-object/elements/select_list.rb +2 -0
- data/lib/page-object/elements/span.rb +4 -1
- data/lib/page-object/elements/table.rb +2 -0
- data/lib/page-object/elements/table_cell.rb +5 -1
- data/lib/page-object/elements/table_row.rb +2 -0
- data/lib/page-object/elements/text_area.rb +3 -0
- data/lib/page-object/elements/text_field.rb +3 -0
- data/lib/page-object/elements/unordered_list.rb +3 -1
- data/lib/page-object/page_populator.rb +7 -3
- data/lib/page-object/platforms/selenium_webdriver/element.rb +33 -0
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +10 -8
- data/lib/page-object/platforms/watir_webdriver/element.rb +24 -0
- data/lib/page-object/platforms/watir_webdriver/file_field.rb +1 -1
- data/lib/page-object/version.rb +1 -1
- data/spec/page-object/elements/button_spec.rb +16 -0
- data/spec/page-object/elements/check_box_spec.rb +5 -2
- data/spec/page-object/elements/div_spec.rb +7 -1
- data/spec/page-object/elements/file_field_spec.rb +4 -0
- data/spec/page-object/elements/form_spec.rb +5 -1
- data/spec/page-object/elements/heading_spec.rb +27 -1
- data/spec/page-object/elements/hidden_field_spec.rb +9 -3
- data/spec/page-object/elements/image_spec.rb +4 -0
- data/spec/page-object/elements/link_spec.rb +5 -1
- data/spec/page-object/elements/list_item_spec.rb +7 -1
- data/spec/page-object/elements/option_spec.rb +11 -0
- data/spec/page-object/elements/ordered_list_spec.rb +5 -1
- data/spec/page-object/elements/paragraph_spec.rb +28 -0
- data/spec/page-object/elements/radio_button_spec.rb +5 -0
- data/spec/page-object/elements/select_list_spec.rb +4 -0
- data/spec/page-object/elements/selenium_element_spec.rb +24 -1
- data/spec/page-object/elements/span_spec.rb +5 -1
- data/spec/page-object/elements/table_cell_spec.rb +15 -0
- data/spec/page-object/elements/table_row_spec.rb +6 -1
- data/spec/page-object/elements/table_spec.rb +4 -0
- data/spec/page-object/elements/text_area_spec.rb +6 -1
- data/spec/page-object/elements/text_field_spec.rb +8 -0
- data/spec/page-object/elements/unordered_list_spec.rb +5 -1
- data/spec/page-object/page_populator_spec.rb +31 -2
- metadata +22 -12
@@ -31,9 +31,9 @@ module PageObject
|
|
31
31
|
#
|
32
32
|
def populate_page_with(data)
|
33
33
|
data.each do |key, value|
|
34
|
-
populate_checkbox(key, value) if is_checkbox?(key)
|
35
|
-
populate_radiobutton(key, value) if is_radiobutton?(key)
|
36
|
-
populate_text(key, value) if is_text?(key)
|
34
|
+
populate_checkbox(key, value) if is_checkbox?(key) and is_enabled?(key)
|
35
|
+
populate_radiobutton(key, value) if is_radiobutton?(key) and is_enabled?(key)
|
36
|
+
populate_text(key, value) if is_text?(key) and is_enabled?(key)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -64,5 +64,9 @@ module PageObject
|
|
64
64
|
def is_radiobutton?(key)
|
65
65
|
respond_to?("select_#{key}".to_sym)
|
66
66
|
end
|
67
|
+
|
68
|
+
def is_enabled?(key)
|
69
|
+
self.send("#{key}_element").enabled?
|
70
|
+
end
|
67
71
|
end
|
68
72
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'watir-webdriver/atoms'
|
2
|
+
|
1
3
|
module PageObject
|
2
4
|
module Platforms
|
3
5
|
#
|
@@ -5,6 +7,7 @@ module PageObject
|
|
5
7
|
#
|
6
8
|
module SeleniumWebDriver
|
7
9
|
module Element
|
10
|
+
include Watir::Atoms
|
8
11
|
|
9
12
|
#
|
10
13
|
# return true if an element is visible
|
@@ -88,6 +91,36 @@ module PageObject
|
|
88
91
|
@element.attribute attribute_name
|
89
92
|
end
|
90
93
|
|
94
|
+
#
|
95
|
+
# Fire the provided event on the current element
|
96
|
+
#
|
97
|
+
def fire_event(event_name)
|
98
|
+
event_name = event_name.to_s.sub(/^on/, '').downcase
|
99
|
+
script = "return (%s).apply(null, arguments)" % ATOMS.fetch(:fireEvent)
|
100
|
+
bridge = @element.instance_variable_get(:@bridge)
|
101
|
+
bridge.executeScript(script, @element, event_name)
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# find the parent element
|
106
|
+
#
|
107
|
+
def parent
|
108
|
+
script = "return (%s).apply(null, arguments)" % ATOMS.fetch(:getParentElement)
|
109
|
+
bridge = @element.instance_variable_get(:@bridge)
|
110
|
+
parent = bridge.executeScript(script, @element)
|
111
|
+
type = @element.type if parent.tag_name.to_sym == :input
|
112
|
+
cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
|
113
|
+
cls.new(parent, :platform => :selenium_webdriver)
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Set the focus to the current element
|
118
|
+
#
|
119
|
+
def focus
|
120
|
+
bridge = @element.instance_variable_get(:@bridge)
|
121
|
+
bridge.executeScript("return arguments[0].focus()", @element)
|
122
|
+
end
|
123
|
+
|
91
124
|
#
|
92
125
|
# Click this element
|
93
126
|
#
|
@@ -800,18 +800,20 @@ module PageObject
|
|
800
800
|
|
801
801
|
def supported_identifier(identifier, tag, additional)
|
802
802
|
return false if identifier[:index]
|
803
|
-
return false if identifier[:
|
803
|
+
return false if identifier[:action] and tag == 'form'
|
804
|
+
return false if identifier[:alt] and tag == 'img'
|
805
|
+
return false if identifier[:alt] and tag == 'input' and
|
806
|
+
['submit', 'image', 'button', 'reset'].include? additional[:type]
|
804
807
|
return false if identifier[:href] and tag == 'a'
|
808
|
+
return false if identifier[:src] and tag == 'input' and
|
809
|
+
['submit', 'image', 'button', 'reset'].include? additional[:type]
|
810
|
+
return false if identifier[:src] and tag == 'img'
|
811
|
+
return false if identifier[:text] and tag == 'input' and additional[:type] == 'hidden'
|
805
812
|
return false if identifier[:text] and ['div', 'span', 'td'].include? tag
|
806
|
-
return false if identifier[:value] and tag == 'input' and additional[:type] == 'submit'
|
807
|
-
return false if identifier[:src] and tag == 'input' and additional[:type] == 'submit'
|
808
|
-
return false if identifier[:alt] and tag == 'input' and additional[:type] == 'submit'
|
809
813
|
return false if identifier[:title] and tag == 'input' and additional[:type] == 'text'
|
810
|
-
return false if identifier[:value] and tag == 'input' and additional[:type] == 'radio'
|
811
814
|
return false if identifier[:title] and tag == 'input' and additional[:type] == 'file'
|
812
|
-
return false if identifier[:
|
813
|
-
|
814
|
-
return false if identifier[:src] and tag == 'img'
|
815
|
+
return false if identifier[:value] and tag == 'input' and
|
816
|
+
['radio', 'submit', 'image', 'button', 'reset', 'checkbox', 'hidden'].include? additional[:type]
|
815
817
|
true
|
816
818
|
end
|
817
819
|
|
@@ -88,6 +88,30 @@ module PageObject
|
|
88
88
|
@element.attribute_value attribute_name
|
89
89
|
end
|
90
90
|
|
91
|
+
#
|
92
|
+
# Fire the provided event on the current element
|
93
|
+
#
|
94
|
+
def fire_event(event_name)
|
95
|
+
@element.fire_event(event_name)
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# find the parent element
|
100
|
+
#
|
101
|
+
def parent
|
102
|
+
parent = @element.parent
|
103
|
+
type = @element.type if parent.tag_name.to_sym == :input
|
104
|
+
cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
|
105
|
+
cls.new(parent, :platform => :watir_webdriver)
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Set the focus to the current element
|
110
|
+
#
|
111
|
+
def focus
|
112
|
+
@element.focus
|
113
|
+
end
|
114
|
+
|
91
115
|
#
|
92
116
|
# Waits until the element is present
|
93
117
|
#
|
data/lib/page-object/version.rb
CHANGED
@@ -23,6 +23,22 @@ describe PageObject::Elements::Button do
|
|
23
23
|
describe "interface" do
|
24
24
|
let(:button_element) { double('button_element') }
|
25
25
|
|
26
|
+
it "should register with type :submit" do
|
27
|
+
::PageObject::Elements.element_class_for(:input, :submit).should == ::PageObject::Elements::Button
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should register with type :image" do
|
31
|
+
::PageObject::Elements.element_class_for(:input, :image).should == ::PageObject::Elements::Button
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should register with type :button" do
|
35
|
+
::PageObject::Elements.element_class_for(:input, :button).should == ::PageObject::Elements::Button
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should retisger with type :reset" do
|
39
|
+
::PageObject::Elements.element_class_for(:input, :reset).should == ::PageObject::Elements::Button
|
40
|
+
end
|
41
|
+
|
26
42
|
context "for selenium" do
|
27
43
|
it "should return error when asked for its' text" do
|
28
44
|
button = PageObject::Elements::Button.new(button_element, :platform => :selenium_webdriver)
|
@@ -6,13 +6,13 @@ describe PageObject::Elements::CheckBox do
|
|
6
6
|
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
|
-
[:class, :id, :index, :name, :xpath].each do |t|
|
9
|
+
[:class, :id, :index, :name, :xpath, :value].each do |t|
|
10
10
|
identifier = checkbox.watir_identifier_for t => 'value'
|
11
11
|
identifier.keys.first.should == t
|
12
12
|
end
|
13
13
|
end
|
14
14
|
it "should map selenium types to same" do
|
15
|
-
[:class, :id, :name, :xpath, :index].each do |t|
|
15
|
+
[:class, :id, :name, :xpath, :index, :value].each do |t|
|
16
16
|
key, value = checkbox.selenium_identifier_for t => 'value'
|
17
17
|
key.should == t
|
18
18
|
end
|
@@ -23,6 +23,9 @@ describe PageObject::Elements::CheckBox do
|
|
23
23
|
let(:check_box) { double('check_box') }
|
24
24
|
let(:selenium_cb) { PageObject::Elements::CheckBox.new(check_box, :platform => :selenium_webdriver) }
|
25
25
|
|
26
|
+
it "should register with type :checkbox" do
|
27
|
+
::PageObject::Elements.element_class_for(:input, :checkbox).should == ::PageObject::Elements::CheckBox
|
28
|
+
end
|
26
29
|
|
27
30
|
context "for selenium" do
|
28
31
|
it "should check" do
|
@@ -18,5 +18,11 @@ describe PageObject::Elements::Div do
|
|
18
18
|
key.should == t
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe "interface" do
|
23
|
+
it "should register with tag :div" do
|
24
|
+
::PageObject::Elements.element_class_for(:div).should == ::PageObject::Elements::Div
|
25
|
+
end
|
26
|
+
end
|
21
27
|
end
|
22
|
-
end
|
28
|
+
end
|
@@ -23,6 +23,10 @@ describe PageObject::Elements::FileField do
|
|
23
23
|
|
24
24
|
describe "interface" do
|
25
25
|
let(:filefield) { double('file_field') }
|
26
|
+
|
27
|
+
it "should register as type :file" do
|
28
|
+
::PageObject::Elements.element_class_for(:input, :file).should == ::PageObject::Elements::FileField
|
29
|
+
end
|
26
30
|
|
27
31
|
context "for selenium" do
|
28
32
|
it "should set its' value" do
|
@@ -5,6 +5,10 @@ describe PageObject::Elements::Form do
|
|
5
5
|
describe "interface" do
|
6
6
|
let(:form_element) { double('form_element') }
|
7
7
|
|
8
|
+
it "should register with tag_name :form" do
|
9
|
+
::PageObject::Elements.element_class_for(:form).should == ::PageObject::Elements::Form
|
10
|
+
end
|
11
|
+
|
8
12
|
context "for watir" do
|
9
13
|
it "should submit a form" do
|
10
14
|
form = PageObject::Elements::Form.new(form_element, :platform => :watir_webdriver)
|
@@ -21,4 +25,4 @@ describe PageObject::Elements::Form do
|
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
24
|
-
end
|
28
|
+
end
|
@@ -19,4 +19,30 @@ describe PageObject::Elements::Heading do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
|
+
describe "interface" do
|
24
|
+
it "should register with tag :h1" do
|
25
|
+
::PageObject::Elements.element_class_for(:h1).should == ::PageObject::Elements::Heading
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should register with tag :h2" do
|
29
|
+
::PageObject::Elements.element_class_for(:h2).should == ::PageObject::Elements::Heading
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should register with tag :h3" do
|
33
|
+
::PageObject::Elements.element_class_for(:h3).should == ::PageObject::Elements::Heading
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should register with tag :h4" do
|
37
|
+
::PageObject::Elements.element_class_for(:h4).should == ::PageObject::Elements::Heading
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should register with tag :h5" do
|
41
|
+
::PageObject::Elements.element_class_for(:h5).should == ::PageObject::Elements::Heading
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should register with tag :h6" do
|
45
|
+
::PageObject::Elements.element_class_for(:h6).should == ::PageObject::Elements::Heading
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -6,7 +6,7 @@ describe PageObject::Elements::HiddenField do
|
|
6
6
|
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
|
-
[:class, :id, :index, :name, :tag_name, :text, :xpath].each do |t|
|
9
|
+
[:class, :id, :index, :name, :tag_name, :text, :xpath, :value].each do |t|
|
10
10
|
identifier = hiddenfield.watir_identifier_for t => 'value'
|
11
11
|
identifier.keys.first.should == t
|
12
12
|
end
|
@@ -18,7 +18,7 @@ describe PageObject::Elements::HiddenField do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should map selenium types to same" do
|
21
|
-
[:class, :css, :id, :name, :xpath, :index].each do |t|
|
21
|
+
[:class, :css, :id, :name, :xpath, :index, :value].each do |t|
|
22
22
|
key, value = hiddenfield.selenium_identifier_for t => 'value'
|
23
23
|
key.should == t
|
24
24
|
end
|
@@ -29,4 +29,10 @@ describe PageObject::Elements::HiddenField do
|
|
29
29
|
key.should == :css
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
|
+
describe "interface" do
|
34
|
+
it "should register with type :hidden" do
|
35
|
+
::PageObject::Elements.element_class_for(:input, :hidden).should == ::PageObject::Elements::HiddenField
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -27,6 +27,10 @@ describe PageObject::Elements::Image do
|
|
27
27
|
image_element.stub(:size).and_return(image_element)
|
28
28
|
end
|
29
29
|
|
30
|
+
it "should register with tag_name :img" do
|
31
|
+
::PageObject::Elements.element_class_for(:img).should == ::PageObject::Elements::Image
|
32
|
+
end
|
33
|
+
|
30
34
|
context "for watir" do
|
31
35
|
it "should know the images width" do
|
32
36
|
image = PageObject::Elements::Image.new(image_element, :platform => :watir_webdriver)
|
@@ -35,6 +35,10 @@ describe PageObject::Elements::Link do
|
|
35
35
|
describe "interface" do
|
36
36
|
let(:link_element) { double('link_element') }
|
37
37
|
|
38
|
+
it "should register with tag :a" do
|
39
|
+
::PageObject::Elements.element_class_for(:a).should == ::PageObject::Elements::Link
|
40
|
+
end
|
41
|
+
|
38
42
|
context "for selenium" do
|
39
43
|
it "should return error when asked for its' value" do
|
40
44
|
link = PageObject::Elements::Link.new(link_element, :platform => :selenium_webdriver)
|
@@ -42,4 +46,4 @@ describe PageObject::Elements::Link do
|
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
45
|
-
end
|
49
|
+
end
|
@@ -18,5 +18,11 @@ describe PageObject::Elements::ListItem do
|
|
18
18
|
key.should == t
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe "interface" do
|
23
|
+
it "should register as tag_name :li" do
|
24
|
+
::PageObject::Elements.element_class_for(:li).should == ::PageObject::Elements::ListItem
|
25
|
+
end
|
26
|
+
end
|
21
27
|
end
|
22
|
-
end
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'page-object/elements'
|
3
|
+
|
4
|
+
describe PageObject::Elements::Option do
|
5
|
+
|
6
|
+
describe "interface" do
|
7
|
+
it "should register as tag_name :option" do
|
8
|
+
::PageObject::Elements.element_class_for(:option).should == ::PageObject::Elements::Option
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -23,6 +23,10 @@ describe PageObject::Elements::OrderedList do
|
|
23
23
|
describe "interface" do
|
24
24
|
let(:ol_element) { double('ol_element') }
|
25
25
|
|
26
|
+
it "should register as tag_name :ol" do
|
27
|
+
::PageObject::Elements.element_class_for(:ol).should == ::PageObject::Elements::OrderedList
|
28
|
+
end
|
29
|
+
|
26
30
|
context "for watir" do
|
27
31
|
it "should return a list item when indexed" do
|
28
32
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :watir_webdriver)
|
@@ -76,4 +80,4 @@ describe PageObject::Elements::OrderedList do
|
|
76
80
|
end
|
77
81
|
end
|
78
82
|
end
|
79
|
-
end
|
83
|
+
end
|