page-object 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.2
1
+ rvm 1.9.2-p290@page-object
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 1.9.2
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ === Version 0.1.1
2
+ * Enhancements
3
+ * Support for identifying hidden fields by text when using Selenium
4
+ * Support for identifying links by href when using Selenium
5
+ * Updated to use selenium-webdriver 2.0.1
6
+ * Updated to use watir-webdriver 0.2.6
7
+
1
8
  === Version 0.1 / 2011-07-01
2
9
  * Enhancements
3
10
  * Support for using multiple identifiers when locating the following element:
data/cucumber.yml CHANGED
@@ -3,5 +3,5 @@ watir: DRIVER=WATIR --no-source --color --format pretty --tags ~@selenium_only
3
3
  selenium: DRIVER=SELENIUM --no-source --color --format pretty --tags ~@watir_only
4
4
  watir_focus: DRIVER=WATIR --no-source --color --format pretty --tags @focus --tags ~@selenium_only
5
5
  selenium_focus: DRIVER=SELENIUM --no-source --color --format pretty --tags @focus --tags ~@watir_only
6
- autotest: DRIVER=WATIR --no-source --color --format pretty --tags ~@selenium_only
6
+ autotest: DRIVER=SELENIUM features/hidden_field.feature --no-source --color --format pretty --tags ~@watir_only
7
7
 
@@ -20,14 +20,6 @@ Feature: Hidden Fields
20
20
  | css |
21
21
  | tag_name |
22
22
  | index |
23
-
24
- @watir_only
25
- Scenario Outline: Locating hidden fields on Watir only
26
- When I search for the hidden field by "<search_by>"
27
- Then hidden field element should contains "12345"
28
-
29
- Scenarios:
30
- | search_by |
31
23
  | text |
32
24
 
33
25
  Scenario Outline: Locating a hidden field using multiple parameters
@@ -23,16 +23,8 @@ Feature: Links
23
23
  | link_text |
24
24
  | text |
25
25
  | index |
26
-
27
- @watir_only
28
- Scenario Outline: Locating links on Watir only
29
- When I search for the link by "<search_by>"
30
- Then I should be able to select the link
31
-
32
- Scenarios:
33
- | search_by |
34
26
  | href |
35
-
27
+
36
28
  Scenario: Support for multiple parameters
37
29
  When I select a link labeled "Hello" and index "0"
38
30
  Then the page should contain the text "Success"
@@ -74,7 +74,7 @@ module PageObject
74
74
  # * :index => Watir and Selenium
75
75
  # * :name => Watir and Selenium
76
76
  # * :tag_name => Watir and Selenium
77
- # * :text => Watir only
77
+ # * :text => Watir and Selenium
78
78
  # * :xpath => Watir and Selenium
79
79
  # @param optional block to be invoked when element method is called
80
80
  #
@@ -166,7 +166,7 @@ module PageObject
166
166
  # @param [Hash] identifier how we find a link. You can use a multiple paramaters
167
167
  # by combining of any of the following except xpath. The valid keys are:
168
168
  # * :class => Watir and Selenium
169
- # * :href => Watir only
169
+ # * :href => Watir and Selenium
170
170
  # * :id => Watir and Selenium
171
171
  # * :index => Watir and Selenium
172
172
  # * :link => Watir and Selenium
@@ -31,10 +31,6 @@ module PageObject
31
31
  all_identities
32
32
  end
33
33
 
34
- def self.should_build_watir_xpath identifier
35
- ['table', 'span', 'div', 'td', 'li', 'ul', 'ol'].include? identifier[:tag_name] and identifier[:name]
36
- end
37
-
38
34
  # @private
39
35
  def self.selenium_identifier_for identifier
40
36
  if identifier.length == 1
@@ -49,6 +45,10 @@ module PageObject
49
45
 
50
46
  protected
51
47
 
48
+ def self.should_build_watir_xpath identifier
49
+ ['table', 'span', 'div', 'td', 'li', 'ul', 'ol'].include? identifier[:tag_name] and identifier[:name]
50
+ end
51
+
52
52
  def self.build_xpath_for identifier
53
53
  tag_locator = identifier.delete(:tag_name)
54
54
  idx = identifier.delete(:index)
@@ -423,7 +423,7 @@ module PageObject
423
423
  private
424
424
 
425
425
  def add_tagname_if_needed identifier, tag, additional=nil
426
- return identifier if identifier.length < 2 and identifier[:index].nil?
426
+ return identifier if identifier.length < 2 and supported_identifier(identifier, tag, additional)
427
427
  identifier[:tag_name] = tag
428
428
  if additional
429
429
  additional.each do |key, value|
@@ -432,6 +432,13 @@ module PageObject
432
432
  end
433
433
  identifier
434
434
  end
435
+
436
+ def supported_identifier(identifier, tag, additional)
437
+ return false if identifier[:index]
438
+ return false if identifier[:text] and tag == 'input' and additional[:type] == 'hidden'
439
+ return false if identifier[:href] and tag == 'a'
440
+ true
441
+ end
435
442
 
436
443
  end
437
444
  end
@@ -1,4 +1,4 @@
1
1
  module PageObject
2
2
  # @private
3
- VERSION = "0.1"
3
+ VERSION = "0.1.1"
4
4
  end
data/page-object.gemspec CHANGED
@@ -19,11 +19,11 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency 'watir-webdriver', '>= 0.2.5'
23
- s.add_dependency 'selenium-webdriver', '>= 0.2.2'
22
+ s.add_dependency 'watir-webdriver', '>= 0.2.6'
23
+ s.add_dependency 'selenium-webdriver', '>= 2.0.1'
24
24
 
25
- s.add_development_dependency 'rspec', '>= 2.5.0'
26
- s.add_development_dependency 'cucumber', '>= 0.10.2'
27
- s.add_development_dependency 'yard', '>= 0.6.8'
25
+ s.add_development_dependency 'rspec', '>= 2.6.0'
26
+ s.add_development_dependency 'cucumber', '>= 1.0.0'
27
+ s.add_development_dependency 'yard', '>= 0.7.2'
28
28
 
29
29
  end
@@ -7,8 +7,82 @@ describe PageObject::Elements::Element do
7
7
  let(:selenium_driver) { double('selenium') }
8
8
  let(:watir_element) { PageObject::Elements::Element.new(watir_driver, :platform => :watir) }
9
9
  let(:selenium_element) { PageObject::Elements::Element.new(selenium_driver, :platform => :selenium) }
10
+ let(:element) {PageObject::Elements::Element}
10
11
 
11
- context "on a Watir page-object" do
12
+ context "when building the identifiers for Watir" do
13
+ it "should build xpath when finding elements by name where not supported" do
14
+ ['table', 'span', 'div', 'td', 'li', 'ol', 'ul'].each do |tag|
15
+ how = {:tag_name => tag, :name => 'blah'}
16
+ result = element.watir_identifier_for how
17
+ result[:xpath].should == ".//#{tag}[@name='blah']"
18
+ end
19
+ end
20
+ end
21
+
22
+ context "when building the identifiers for Selenium" do
23
+ def all_basic_elements
24
+ ['textarea', 'select', 'a', 'div', 'span', 'table', 'td', 'img', 'form', 'li', 'ul', 'ol']
25
+ end
26
+
27
+ def all_input_elements
28
+ ['text', 'hidden', 'checkbox', 'radio', 'submit']
29
+ end
30
+
31
+ it "should build xpath when index is provided for basic elements" do
32
+ all_basic_elements.each do |tag|
33
+ identifier = {:tag_name => tag, :index => 1}
34
+ how, what = element.selenium_identifier_for identifier
35
+ how.should == :xpath
36
+ what.should == ".//#{tag}[2]"
37
+ end
38
+ end
39
+
40
+ it "should should build xpath when index is provided for input elements" do
41
+ all_input_elements.each do |tag|
42
+ identifier = {:tag_name => 'input', :type => tag, :index => 1}
43
+ how, what = element.selenium_identifier_for identifier
44
+ how.should == :xpath
45
+ what.should == ".//input[@type='#{tag}'][2]"
46
+ end
47
+ end
48
+
49
+ it "should build xpath when locating basic elements by name and index" do
50
+ all_basic_elements.each do |tag|
51
+ identifier = {:tag_name => tag, :name => 'blah', :index => 0}
52
+ how, what = element.selenium_identifier_for identifier
53
+ how.should == :xpath
54
+ what.should == ".//#{tag}[@name='blah'][1]"
55
+ end
56
+ end
57
+
58
+ it "should build xpath when locating input elements by name and index" do
59
+ all_input_elements.each do |type|
60
+ identifier = {:tag_name => 'input', :type => "#{type}", :name => 'blah', :index => 0}
61
+ how, what = element.selenium_identifier_for identifier
62
+ how.should == :xpath
63
+ what.should == ".//input[@type='#{type}' and @name='blah'][1]"
64
+ end
65
+ end
66
+
67
+ it "should build xpath when locating basic elements by name and class" do
68
+ all_basic_elements.each do |tag|
69
+ identifier = {:tag_name => tag, :name => 'foo', :class => 'bar'}
70
+ how, what = element.selenium_identifier_for identifier
71
+ how.should == :xpath
72
+ what.should == ".//#{tag}[@name='foo' and @class='bar']"
73
+ end
74
+ end
75
+
76
+ it "should build xpath when locating input elements by name and class" do
77
+ all_input_elements.each do |type|
78
+ identifier = {:tag_name => 'input', :type => "#{type}", :name => 'foo', :class => 'bar'}
79
+ how, what = element.selenium_identifier_for identifier
80
+ what.should == ".//input[@type='#{type}' and @name='foo' and @class='bar']"
81
+ end
82
+ end
83
+ end
84
+
85
+ context "when using Watir" do
12
86
  it "should know when it is visible" do
13
87
  watir_driver.should_receive(:present?).and_return(true)
14
88
  watir_element.visible?.should == true
@@ -60,7 +134,7 @@ describe PageObject::Elements::Element do
60
134
  end
61
135
  end
62
136
 
63
- context "on a Selenium page-object" do
137
+ context "when using Selenium" do
64
138
  it "should know when it is visible" do
65
139
  selenium_driver.should_receive(:displayed?).and_return(true)
66
140
  selenium_element.visible?.should == true
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'page-object/selenium_page_object'
3
+ require 'page-object/elements'
4
+
5
+ class TestPageObject
6
+ include PageObject
7
+ end
8
+
9
+ describe PageObject::SeleniumPageObject do
10
+ let(:selenium_browser) { mock_selenium_browser }
11
+ let(:selenium_page_object) { TestPageObject.new(selenium_browser) }
12
+
13
+ context "when building identifiers hash" do
14
+ it "should add tag_name when identifying by text for hidden_field" do
15
+ expected_identifier = {:text => 'foo', :tag_name => 'input', :type => 'hidden'}
16
+ PageObject::Elements::HiddenField.should_receive(:selenium_identifier_for).with(expected_identifier)
17
+ selenium_browser.should_receive(:find_element)
18
+ selenium_page_object.platform.hidden_field_for(:text => 'foo')
19
+ end
20
+
21
+ it "should add tag_name when identifying by href for anchor" do
22
+ expected_identifier = {:href => 'foo', :tag_name => 'a'}
23
+ PageObject::Elements::Link.should_receive(:selenium_identifier_for).with(expected_identifier)
24
+ selenium_browser.should_receive(:find_element)
25
+ selenium_page_object.platform.link_for(:href => 'foo')
26
+ end
27
+ end
28
+ 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.1"
5
+ version: 0.1.1
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-07-01 00:00:00 Z
13
+ date: 2011-07-16 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: watir-webdriver
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.2.5
23
+ version: 0.2.6
24
24
  type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.2.2
34
+ version: 2.0.1
35
35
  type: :runtime
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 2.5.0
45
+ version: 2.6.0
46
46
  type: :development
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
@@ -53,7 +53,7 @@ dependencies:
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 0.10.2
56
+ version: 1.0.0
57
57
  type: :development
58
58
  version_requirements: *id004
59
59
  - !ruby/object:Gem::Dependency
@@ -64,7 +64,7 @@ dependencies:
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: 0.6.8
67
+ version: 0.7.2
68
68
  type: :development
69
69
  version_requirements: *id005
70
70
  description: Page Object DSL that works with both Watir and Selenium
@@ -80,6 +80,7 @@ files:
80
80
  - .gitignore
81
81
  - .rspec
82
82
  - .rvmrc
83
+ - .travis.yml
83
84
  - ChangeLog
84
85
  - Gemfile
85
86
  - LICENSE
@@ -183,6 +184,7 @@ files:
183
184
  - spec/page-object/elements/unordered_list_spec.rb
184
185
  - spec/page-object/page-object_spec.rb
185
186
  - spec/page-object/page_factory_spec.rb
187
+ - spec/page-object/selenium_page_object_spec.rb
186
188
  - spec/spec_helper.rb
187
189
  homepage: http://github.com/cheezy/page-object
188
190
  licenses: []
@@ -263,4 +265,5 @@ test_files:
263
265
  - spec/page-object/elements/unordered_list_spec.rb
264
266
  - spec/page-object/page-object_spec.rb
265
267
  - spec/page-object/page_factory_spec.rb
268
+ - spec/page-object/selenium_page_object_spec.rb
266
269
  - spec/spec_helper.rb