page-object 0.5.2 → 0.5.3

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/.rspec CHANGED
@@ -1 +1,2 @@
1
- --color --format doc
1
+ --color
2
+ --format Fuubar
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ === Version 0.5.3
2
+ * Enhancements
3
+ * Added new module PagePopulator with single method populate_page_with
4
+ * Updated to use selenium-webdriver 2.15.0
5
+ * Updated to use watir-webdriver 0.4.1
6
+ * Fixes
7
+ * Updated prompt method to make it compatible with latest dependencies
8
+
1
9
  === Version 0.5.2 / 2011-11-30
2
10
  * Enhancements
3
11
  * Added ability to find image buttons by src
data/Gemfile CHANGED
@@ -2,5 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  # adding rake so travis-ci will build properly
4
4
  gem 'rake'
5
+ gem 'fuubar'
6
+ gem 'fuubar-cucumber'
5
7
 
6
8
  gemspec
data/cucumber.yml CHANGED
@@ -1,7 +1,9 @@
1
- default: DRIVER=WATIR --no-source --color --format pretty
2
- watir: DRIVER=WATIR --no-source --color --format pretty --tags ~@selenium_only
3
- selenium: DRIVER=SELENIUM --no-source --color --format pretty --tags ~@watir_only
4
- watir_focus: DRIVER=WATIR --no-source --color --format pretty --tags @focus --tags ~@selenium_only
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
1
+ <%
2
+ std_opts = "--no-source --color --format Cucumber::Formatter::Fuubar"
3
+ %>
4
+
5
+ default: DRIVER=WATIR <%= std_opts %>
6
+ watir: DRIVER=WATIR <%= std_opts %> --tags ~@selenium_only
7
+ selenium: DRIVER=SELENIUM <%= std_opts %> --tags ~@watir_only
8
+ autotest: DRIVER=WATIR <%= std_opts %> --tags ~@selenium_only
7
9
 
data/lib/page-object.rb CHANGED
@@ -3,6 +3,7 @@ require 'page-object/accessors'
3
3
  require 'page-object/platforms'
4
4
  require 'page-object/element_locators'
5
5
  require 'page-object/nested_elements'
6
+ require 'page-object/page_populator'
6
7
 
7
8
  #
8
9
  # Module that when included adds functionality to a page object. This module
@@ -35,6 +36,7 @@ require 'page-object/nested_elements'
35
36
  module PageObject
36
37
  include LoadsPlatform
37
38
  include ElementLocators
39
+ include PagePopulator
38
40
 
39
41
  # @return [Watir::Browser or Selenium::WebDriver::Driver] the platform browser passed to the constructor
40
42
  attr_reader :browser
@@ -5,7 +5,7 @@ module PageObject
5
5
  protected
6
6
 
7
7
  def self.watir_finders
8
- [:class, :id, :text, :index, :xpath]
8
+ [:class, :id, :name, :text, :index, :xpath]
9
9
  end
10
10
 
11
11
  def self.selenium_finders
@@ -0,0 +1,68 @@
1
+ module PageObject
2
+ module PagePopulator
3
+
4
+ #
5
+ # This method will populate all matched page TextFields,
6
+ # TextAreas, SelectLists, Checkboxes, and Radio Buttons from the
7
+ # Hash passed as an argument. The way it find an element is by
8
+ # matching the Hash key to the name you provided when declaring
9
+ # the element on your page.
10
+ #
11
+ # Checkboxe and Radio Button values must be true or false.
12
+ #
13
+ # @example
14
+ # class ExamplePage
15
+ # include PageObject
16
+ #
17
+ # text_field(:username, :id => 'username_id')
18
+ # checkbox(:active, :id => 'active_id')
19
+ # end
20
+ #
21
+ # ...
22
+ #
23
+ # @browser = Watir::Browser.new :firefox
24
+ # example_page = ExamplePage.new(@browser)
25
+ # example_page.populate_page_with :username => 'a name', :active => true
26
+ #
27
+ # @param [Hash] the data to use to populate this page. The key
28
+ # can be either a string or a symbol. The value must be a string
29
+ # for TextField, TextArea, and SelectList and must be true or
30
+ # false for a Checkbox or RadioButton.
31
+ #
32
+ def populate_page_with(data)
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)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def populate_text(key, value)
43
+ self.send "#{key}=", value
44
+ end
45
+
46
+ def populate_checkbox(key, value)
47
+ return self.send "check_#{key}" if value
48
+ return self.send "uncheck_#{key}"
49
+ end
50
+
51
+ def populate_radiobutton(key, value)
52
+ return self.send "select_#{key}" if value
53
+ return self.send "clear_#{key}"
54
+ end
55
+
56
+ def is_text?(key)
57
+ respond_to?("#{key}=".to_sym)
58
+ end
59
+
60
+ def is_checkbox?(key)
61
+ respond_to?("check_#{key}".to_sym)
62
+ end
63
+
64
+ def is_radiobutton?(key)
65
+ respond_to?("select_#{key}".to_sym)
66
+ end
67
+ end
68
+ end
@@ -89,7 +89,7 @@ module PageObject
89
89
  # See PageObject#prompt
90
90
  #
91
91
  def prompt(answer, frame=nil, &block)
92
- @browser.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer.to_json}; }"
92
+ @browser.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer}; }"
93
93
  yield
94
94
  result = @browser.execute_script "return window.__lastWatirPrompt"
95
95
  result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
@@ -462,7 +462,6 @@ module PageObject
462
462
  #
463
463
  def click_button_for(identifier)
464
464
  how, what, frame_identifiers = parse_identifiers(identifier, Elements::Button, 'input', :type => 'submit')
465
- puts "how=#{how}, what=#{what}"
466
465
  switch_to_frame(frame_identifiers)
467
466
  @browser.find_element(how, what).click
468
467
  @browser.switch_to.default_content unless frame_identifiers.nil?
@@ -97,7 +97,7 @@ module PageObject
97
97
  #
98
98
  def prompt(answer, frame=nil, &block)
99
99
  switch_to_frame(frame)
100
- @browser.wd.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer.to_json}; }"
100
+ @browser.wd.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer}; }"
101
101
  yield
102
102
  result = @browser.wd.execute_script "return window.__lastWatirPrompt"
103
103
  switch_to_default_content(frame)
@@ -1,4 +1,4 @@
1
1
  module PageObject
2
2
  # @private
3
- VERSION = "0.5.2"
3
+ VERSION = "0.5.3"
4
4
  end
data/page-object.gemspec CHANGED
@@ -19,8 +19,8 @@ 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.3.9'
23
- s.add_dependency 'selenium-webdriver', '>= 2.14.0'
22
+ s.add_dependency 'watir-webdriver', '>= 0.4.1'
23
+ s.add_dependency 'selenium-webdriver', '>= 2.15.0'
24
24
 
25
25
  s.add_development_dependency 'rspec', '>= 2.6.0'
26
26
  s.add_development_dependency 'cucumber', '>= 1.1.0'
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ class PageObjectTestPageObject
4
+ include PageObject
5
+
6
+ text_field(:tf, :id => 'id')
7
+ text_area(:ta, :id => 'id')
8
+ select_list(:sl, :id => 'id')
9
+ checkbox(:cb, :id => 'id')
10
+ radio_button(:rb, :id => 'id')
11
+ end
12
+
13
+ describe PageObject::PagePopulator do
14
+ let(:browser) { mock_watir_browser }
15
+ let(:page_object) { PageObjectTestPageObject.new(browser) }
16
+
17
+ it "should set a value in a text field" do
18
+ page_object.should_receive(:tf=).with('value')
19
+ page_object.populate_page_with('tf' => 'value')
20
+ end
21
+
22
+ it "should not set a value if it is not found on the page" do
23
+ browser.should_not_receive(:text_field)
24
+ page_object.populate_page_with('coffee' => 'value')
25
+ end
26
+
27
+ it "should set a value in a text area" do
28
+ page_object.should_receive(:ta=).with('value')
29
+ page_object.populate_page_with('ta' => 'value')
30
+ end
31
+
32
+ it "should set a value in a select list" do
33
+ page_object.should_receive(:sa=).with('value')
34
+ page_object.populate_page_with('sa' => 'value')
35
+ end
36
+
37
+ it "should check a checkbox to true is specified" do
38
+ page_object.should_receive(:check_cb)
39
+ page_object.populate_page_with('cb' => true)
40
+ end
41
+
42
+ it "should uncheck a checkbox to false is specified" do
43
+ page_object.should_receive(:uncheck_cb)
44
+ page_object.populate_page_with('cb' => false)
45
+ end
46
+
47
+ it "should select a radio button when true is specified" do
48
+ page_object.should_receive(:select_rb)
49
+ page_object.populate_page_with('rb' => true)
50
+ end
51
+
52
+ it "should clear a radio button when false is specified" do
53
+ page_object.should_receive(:clear_rb)
54
+ page_object.populate_page_with('rb' => false)
55
+ end
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page-object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-30 00:00:00.000000000 Z
12
+ date: 2011-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
16
- requirement: &70095900630940 !ruby/object:Gem::Requirement
16
+ requirement: &70269994307840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.3.9
21
+ version: 0.4.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70095900630940
24
+ version_requirements: *70269994307840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: selenium-webdriver
27
- requirement: &70095900629300 !ruby/object:Gem::Requirement
27
+ requirement: &70269994307020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 2.14.0
32
+ version: 2.15.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70095900629300
35
+ version_requirements: *70269994307020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70095900627260 !ruby/object:Gem::Requirement
38
+ requirement: &70269994305640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.6.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70095900627260
46
+ version_requirements: *70269994305640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: cucumber
49
- requirement: &70095900626440 !ruby/object:Gem::Requirement
49
+ requirement: &70269994302500 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.1.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70095900626440
57
+ version_requirements: *70269994302500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &70095900625280 !ruby/object:Gem::Requirement
60
+ requirement: &70269994301820 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.7.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70095900625280
68
+ version_requirements: *70269994301820
69
69
  description: Page Object DSL that works with both Watir and Selenium
70
70
  email:
71
71
  - jeff.morgan@leandog.com
@@ -185,6 +185,7 @@ files:
185
185
  - lib/page-object/loads_platform.rb
186
186
  - lib/page-object/nested_elements.rb
187
187
  - lib/page-object/page_factory.rb
188
+ - lib/page-object/page_populator.rb
188
189
  - lib/page-object/platforms.rb
189
190
  - lib/page-object/platforms/selenium_webdriver.rb
190
191
  - lib/page-object/platforms/selenium_webdriver/button.rb
@@ -245,6 +246,7 @@ files:
245
246
  - spec/page-object/loads_platform_spec.rb
246
247
  - spec/page-object/page-object_spec.rb
247
248
  - spec/page-object/page_factory_spec.rb
249
+ - spec/page-object/page_populator_spec.rb
248
250
  - spec/page-object/platforms/selenium_webdriver/selenium_page_object_spec.rb
249
251
  - spec/page-object/platforms/selenium_webdriver_spec.rb
250
252
  - spec/page-object/platforms/watir_webdriver_spec.rb
@@ -373,6 +375,7 @@ test_files:
373
375
  - spec/page-object/loads_platform_spec.rb
374
376
  - spec/page-object/page-object_spec.rb
375
377
  - spec/page-object/page_factory_spec.rb
378
+ - spec/page-object/page_populator_spec.rb
376
379
  - spec/page-object/platforms/selenium_webdriver/selenium_page_object_spec.rb
377
380
  - spec/page-object/platforms/selenium_webdriver_spec.rb
378
381
  - spec/page-object/platforms/watir_webdriver_spec.rb