page-object 0.4.1 → 0.4.2
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/ChangeLog +5 -0
- data/features/button.feature +22 -0
- data/features/html/static_elements.html +1 -0
- data/features/step_definitions/button_steps.rb +4 -0
- data/features/support/page.rb +9 -0
- data/lib/page-object/elements/element.rb +15 -2
- data/lib/page-object/page_factory.rb +3 -3
- data/lib/page-object/version.rb +1 -1
- data/spec/page-object/elements/element_spec.rb +4 -4
- data/spec/page-object/page_factory_spec.rb +6 -0
- metadata +2 -2
data/ChangeLog
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
=== Version 0.4.2 / 2011-10-01
|
2
|
+
* Enhancements
|
3
|
+
* Proper handling of <button> elements
|
4
|
+
* Changed PageFactory so it also sets and instance variable @current_page to the newly created page
|
5
|
+
|
1
6
|
=== Version 0.4.1 / 2011-09-30
|
2
7
|
* Fixes
|
3
8
|
* Fixed error when loading plugins using Selenium
|
data/features/button.feature
CHANGED
@@ -28,6 +28,18 @@ Feature: Button
|
|
28
28
|
| index |
|
29
29
|
| value |
|
30
30
|
|
31
|
+
Scenario Outline: Locating real buttons on the page
|
32
|
+
When I search for the button by "<search_by>"
|
33
|
+
Then I should be able to click the real button
|
34
|
+
|
35
|
+
Scenarios:
|
36
|
+
| search_by |
|
37
|
+
| id |
|
38
|
+
| class |
|
39
|
+
| name |
|
40
|
+
| index |
|
41
|
+
| value |
|
42
|
+
|
31
43
|
@watir_only
|
32
44
|
Scenario Outline: Locating buttons on Watir only
|
33
45
|
When I search for the button by "<search_by>"
|
@@ -46,6 +58,16 @@ Feature: Button
|
|
46
58
|
| class | index |
|
47
59
|
| name | index |
|
48
60
|
|
61
|
+
Scenario Outline: Locating real button using multiple parameters
|
62
|
+
When I search for the button by "<param1>" and "<param2>"
|
63
|
+
Then I should be able to click the real button
|
64
|
+
|
65
|
+
Scenarios:
|
66
|
+
| param1 | param2 |
|
67
|
+
| class | index |
|
68
|
+
| name | index |
|
69
|
+
|
70
|
+
|
49
71
|
Scenario: Finding a button dynamically
|
50
72
|
When I find a button while the script is executing
|
51
73
|
Then I should be able to click the button element
|
@@ -47,6 +47,7 @@
|
|
47
47
|
|
48
48
|
<form method="get" action="success.html">
|
49
49
|
<input id='button_id' name='button_name' class='button_class' type="submit" value="Click Me">
|
50
|
+
<button type='button' id='btn_id' name='btn_name' class='btn_class'>Click Me Too</button>
|
50
51
|
</form>
|
51
52
|
|
52
53
|
<img src="images/circle.png" id="image_id" name="image_name" class="image_class">
|
@@ -14,6 +14,10 @@ Then /^I should be able to click the button$/ do
|
|
14
14
|
@page.send "button_#{@how}"
|
15
15
|
end
|
16
16
|
|
17
|
+
Then /^I should be able to click the real button$/ do
|
18
|
+
@page.send "btn_#{@how}"
|
19
|
+
end
|
20
|
+
|
17
21
|
When /^I find a button while the script is executing$/ do
|
18
22
|
@button = @page.button_element(:id => 'button_id')
|
19
23
|
end
|
data/features/support/page.rb
CHANGED
@@ -124,6 +124,15 @@ class Page
|
|
124
124
|
button(:button_class_index, :class => "button_class", :index => 0)
|
125
125
|
button(:button_name_index, :name => "button_name", :index => 0)
|
126
126
|
|
127
|
+
button(:btn_id, :id => 'btn_id')
|
128
|
+
button(:btn_name, :name => 'btn_name')
|
129
|
+
button(:btn_class, :class => 'btn_class')
|
130
|
+
button(:btn_index, :index => 0)
|
131
|
+
button(:btn_text, :text => 'Click Me Too')
|
132
|
+
button(:btn_value, :value => 'Click Me Too')
|
133
|
+
button(:btn_class_index, :class => "btn_class", :index => 0)
|
134
|
+
button(:btn_name_index, :name => "btn_name", :index => 0)
|
135
|
+
|
127
136
|
image(:image_id, :id => 'image_id')
|
128
137
|
image(:image_name, :name => 'image_name')
|
129
138
|
image(:image_class, :class => 'image_class')
|
@@ -84,8 +84,21 @@ module PageObject
|
|
84
84
|
def self.build_xpath_for identifier
|
85
85
|
tag_locator = identifier.delete(:tag_name)
|
86
86
|
idx = identifier.delete(:index)
|
87
|
-
identifier
|
88
|
-
|
87
|
+
if tag_locator == 'input' and identifier[:type] == 'submit'
|
88
|
+
identifier.delete(:type)
|
89
|
+
btn_ident = identifier.clone
|
90
|
+
if btn_ident[:value]
|
91
|
+
btn_ident[:text] = btn_ident[:value]
|
92
|
+
btn_ident.delete(:value)
|
93
|
+
end
|
94
|
+
xpath = ".//button"
|
95
|
+
xpath << "[#{attribute_expression(btn_ident)}]" unless btn_ident.empty?
|
96
|
+
xpath << "[#{idx+1}]" if idx
|
97
|
+
identifier[:type] = %w[button reset submit image]
|
98
|
+
xpath << " | .//input"
|
99
|
+
else
|
100
|
+
xpath = ".//#{tag_locator}"
|
101
|
+
end
|
89
102
|
xpath << "[#{attribute_expression(identifier)}]" unless identifier.empty?
|
90
103
|
xpath << "[#{idx+1}]" if idx
|
91
104
|
xpath
|
@@ -41,9 +41,9 @@ module PageObject
|
|
41
41
|
# @return [PageObject] the newly created page object
|
42
42
|
#
|
43
43
|
def on_page(page_class, visit=false, &block)
|
44
|
-
|
45
|
-
block.call
|
46
|
-
|
44
|
+
@current_page = page_class.new(@browser, visit)
|
45
|
+
block.call @current_page if block
|
46
|
+
@current_page
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
data/lib/page-object/version.rb
CHANGED
@@ -29,7 +29,7 @@ describe "Element class methods" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def all_input_elements
|
32
|
-
['text', 'hidden', 'checkbox', 'radio'
|
32
|
+
['text', 'hidden', 'checkbox', 'radio']
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should build xpath when index is provided for basic elements" do
|
@@ -46,7 +46,7 @@ describe "Element class methods" do
|
|
46
46
|
identifier = {:tag_name => 'input', :type => tag, :index => 1}
|
47
47
|
how, what = PageObject::Elements::Element.selenium_identifier_for identifier
|
48
48
|
how.should == :xpath
|
49
|
-
what.should
|
49
|
+
what.should include ".//input[@type='#{tag}'][2]"
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -64,7 +64,7 @@ describe "Element class methods" do
|
|
64
64
|
identifier = {:tag_name => 'input', :type => "#{type}", :name => 'blah', :index => 0}
|
65
65
|
how, what = PageObject::Elements::Element.selenium_identifier_for identifier
|
66
66
|
how.should == :xpath
|
67
|
-
what.should
|
67
|
+
what.should include ".//input[@type='#{type}' and @name='blah'][1]"
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -81,7 +81,7 @@ describe "Element class methods" do
|
|
81
81
|
all_input_elements.each do |type|
|
82
82
|
identifier = {:tag_name => 'input', :type => "#{type}", :name => 'foo', :class => 'bar'}
|
83
83
|
how, what = PageObject::Elements::Element.selenium_identifier_for identifier
|
84
|
-
what.should
|
84
|
+
what.should include ".//input[@type='#{type}' and @name='foo' and @class='bar']"
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
@@ -31,4 +31,10 @@ describe PageObject::PageFactory do
|
|
31
31
|
page.should be_instance_of FactoryTestPageObject
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
it "should set an instance variable that can be used outside of the block" do
|
36
|
+
page = @world.on_page FactoryTestPageObject
|
37
|
+
current_page = @world.instance_variable_get "@current_page"
|
38
|
+
current_page.should === page
|
39
|
+
end
|
34
40
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: page-object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeff Morgan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-10-01 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: watir-webdriver
|