page-object 0.6 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/ChangeLog +10 -0
  2. data/features/button.feature +2 -1
  3. data/features/check_box.feature +2 -1
  4. data/features/div.feature +2 -1
  5. data/features/element.feature +2 -0
  6. data/features/form.feature +2 -1
  7. data/features/hidden_field.feature +4 -3
  8. data/features/image.feature +2 -1
  9. data/features/link.feature +1 -1
  10. data/features/list_item.feature +2 -1
  11. data/features/ordered_list.feature +2 -1
  12. data/features/paragraph.feature +2 -1
  13. data/features/radio_button.feature +2 -1
  14. data/features/select_list.feature +14 -1
  15. data/features/span.feature +2 -1
  16. data/features/step_definitions/button_steps.rb +4 -0
  17. data/features/step_definitions/check_box_steps.rb +4 -0
  18. data/features/step_definitions/div_steps.rb +4 -0
  19. data/features/step_definitions/element_steps.rb +8 -0
  20. data/features/step_definitions/form_steps.rb +4 -0
  21. data/features/step_definitions/hidden_field_steps.rb +5 -1
  22. data/features/step_definitions/image_steps.rb +4 -0
  23. data/features/step_definitions/link_steps.rb +6 -0
  24. data/features/step_definitions/list_item_steps.rb +4 -0
  25. data/features/step_definitions/ordered_list_steps.rb +4 -0
  26. data/features/step_definitions/paragraph_steps.rb +4 -0
  27. data/features/step_definitions/radio_button_steps.rb +4 -0
  28. data/features/step_definitions/select_list_steps.rb +18 -1
  29. data/features/step_definitions/span_steps.rb +4 -0
  30. data/features/step_definitions/table_cell_steps.rb +4 -0
  31. data/features/step_definitions/table_steps.rb +4 -0
  32. data/features/step_definitions/text_area_steps.rb +4 -0
  33. data/features/step_definitions/text_field_steps.rb +9 -1
  34. data/features/step_definitions/unordered_list_steps.rb +3 -0
  35. data/features/table.feature +5 -1
  36. data/features/table_cell.feature +2 -1
  37. data/features/text_area.feature +2 -1
  38. data/features/text_field.feature +8 -1
  39. data/features/unordered_list.feature +2 -1
  40. data/lib/page-object/accessors.rb +191 -68
  41. data/lib/page-object/elements/element.rb +8 -1
  42. data/lib/page-object/elements/text_field.rb +4 -0
  43. data/lib/page-object/platforms/selenium_webdriver/select_list.rb +34 -7
  44. data/lib/page-object/platforms/watir_webdriver/select_list.rb +26 -2
  45. data/lib/page-object/version.rb +1 -1
  46. data/page-object.gemspec +1 -1
  47. data/spec/page-object/elements/element_spec.rb +37 -2
  48. data/spec/page-object/elements/select_list_spec.rb +49 -8
  49. data/spec/page-object/elements/text_field_spec.rb +8 -2
  50. metadata +13 -13
@@ -38,6 +38,13 @@ module PageObject
38
38
  def enabled?
39
39
  @element.enabled?
40
40
  end
41
+
42
+ #
43
+ # return true if the element is not enabled
44
+ #
45
+ def disabled?
46
+ not enabled?
47
+ end
41
48
 
42
49
  #
43
50
  # get the value of the given CSS property
@@ -83,7 +90,7 @@ module PageObject
83
90
  def method_missing(*args, &block)
84
91
  m = args.shift
85
92
  puts "*** DEPRECATION WARNING"
86
- puts "*** You are calling a method named #{m}."
93
+ puts "*** You are calling a method named #{m} at #{caller[0]}."
87
94
  puts "*** This method does not exist in page-object so it is being passed to the driver."
88
95
  puts "*** This feature will be removed in the near future."
89
96
  puts "*** Please change your code to call the correct page-object method."
@@ -8,6 +8,10 @@ module PageObject
8
8
  include_platform_for platform
9
9
  end
10
10
 
11
+ def append(text)
12
+ @element.send_keys text
13
+ end
14
+
11
15
  protected
12
16
 
13
17
  def self.watir_finders
@@ -25,15 +25,42 @@ module PageObject
25
25
  #
26
26
  # @return [array of PageObject::Elements::Option]
27
27
  def options
28
- options = @element.find_elements(:xpath, child_xpath)
29
- elements = []
30
- options.each do |opt|
31
- elements << Object::PageObject::Elements::Option.new(opt, :platform => :selenium_webdriver)
32
- end
33
- elements
28
+ find_options.map { |e| ::PageObject::Elements::Option.new(e, :platform => :selenium_webdriver) }
29
+ end
30
+
31
+ #
32
+ # @return [Array<String>] An array of strings representing the text value of the currently selected options.
33
+ #
34
+ def selected_options
35
+ find_options.map { |e| e.text if e.selected? }.compact
36
+ end
37
+
38
+ #
39
+ # Returns true if the select list has one or more options where text or label matches the given value.
40
+ #
41
+ # @param [String, Regexp] value A value.
42
+ # @return [Boolean]
43
+ def include?(value)
44
+ find_options.any? { |e| e.text == value }
45
+ end
46
+
47
+ #
48
+ # Returns true if any of the selected options' text match the given value.
49
+ #
50
+ # @param [String, Regexp] value A value.
51
+ # @return [Boolean]
52
+ def selected?(value)
53
+ selected = find_options.select { |e| e if e.selected? }
54
+ selected.any? { |e| e.text == value }
55
+ end
56
+
57
+ private
58
+
59
+ def find_options
60
+ @element.find_elements(:xpath, child_xpath)
34
61
  end
35
62
  end
36
63
  end
37
64
  end
38
65
 
39
- end
66
+ end
@@ -33,8 +33,32 @@ module PageObject
33
33
  end
34
34
  elements
35
35
  end
36
+
37
+ #
38
+ # @return [Array<String>] An array of strings representing the text value of the currently selected options.
39
+ #
40
+ def selected_options
41
+ @element.selected_options
42
+ end
43
+
44
+ #
45
+ # Returns true if the select list has one or more options where text or label matches the given value.
46
+ #
47
+ # @param [String, Regexp] value A value.
48
+ # @return [Boolean]
49
+ def include?(value)
50
+ @element.include? value
51
+ end
52
+
53
+ #
54
+ # Returns true if any of the selected options' text or label match the given value.
55
+ #
56
+ # @param [String, Regexp] value A value.
57
+ # @return [Boolean]
58
+ def selected?(value)
59
+ @element.selected? value
60
+ end
36
61
  end
37
62
  end
38
63
  end
39
-
40
- end
64
+ end
@@ -1,4 +1,4 @@
1
1
  module PageObject
2
2
  # @private
3
- VERSION = "0.6"
3
+ VERSION = "0.6.1"
4
4
  end
data/page-object.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency 'watir-webdriver', '>= 0.4.1'
23
- s.add_dependency 'selenium-webdriver', '>= 2.16.0'
23
+ s.add_dependency 'selenium-webdriver', '>= 2.17.0'
24
24
 
25
25
  s.add_development_dependency 'rspec', '>= 2.6.0'
26
26
  s.add_development_dependency 'cucumber', '>= 1.1.0'
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'page-object/elements'
3
3
 
4
4
 
5
- describe "Element class methods" do
5
+ describe "Element" do
6
6
 
7
7
  context "when building the identifiers for Watir" do
8
8
  it "should build xpath when finding elements by name where not supported" do
@@ -75,5 +75,40 @@ describe "Element class methods" do
75
75
  what.should include ".//input[@type='#{type}' and @name='foo' and @class='bar']"
76
76
  end
77
77
  end
78
- end
78
+ end
79
+
80
+ context "interaction with native element" do
81
+ let(:native) { double('') }
82
+ let(:element) { PageObject::Elements::Element.new(native, :platform => :watir_webdriver) }
83
+
84
+ it "should check if native is enabled" do
85
+ native.should_receive(:enabled?).and_return(true)
86
+ element.should be_enabled
87
+ end
88
+
89
+ it "should click the native" do
90
+ native.should_receive(:click)
91
+ element.click
92
+ end
93
+
94
+ it "should double click the native" do
95
+ native.should_receive(:double_click)
96
+ element.double_click
97
+ end
98
+
99
+ it "should inspect the native" do
100
+ native.should_receive(:inspect)
101
+ element.inspect
102
+ end
103
+
104
+ it "should retrieve the native's style" do
105
+ native.should_receive(:style).with('foo').and_return("cheezy_style")
106
+ element.style('foo').should == 'cheezy_style'
107
+ end
108
+
109
+ it "should know if a native is disabled" do
110
+ native.should_receive(:enabled?).and_return(false)
111
+ element.should be_disabled
112
+ end
113
+ end
79
114
  end
@@ -27,6 +27,12 @@ describe PageObject::Elements::SelectList do
27
27
  before(:each) do
28
28
  sel_list.stub(:find_elements).and_return(sel_list)
29
29
  sel_list.stub(:each)
30
+ sel_list.stub(:wd).and_return(sel_list)
31
+ sel_list.stub(:map).and_return(opts)
32
+ sel_list.stub(:any?)
33
+ sel_list.stub(:include?)
34
+ sel_list.stub(:select).and_return(opts)
35
+ sel_list.stub(:text).and_return('blah')
30
36
  end
31
37
 
32
38
  it "should register with tag_name :select" do
@@ -34,39 +40,74 @@ describe PageObject::Elements::SelectList do
34
40
  end
35
41
 
36
42
  context "for watir" do
43
+ let(:watir_sel_list) { PageObject::Elements::SelectList.new(sel_list, :platform => :watir_webdriver) }
44
+
37
45
  it "should return an option when indexed" do
38
- watir_sel_list = PageObject::Elements::SelectList.new(sel_list, :platform => :watir_webdriver)
39
- sel_list.stub(:wd).and_return(sel_list)
40
46
  sel_list.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(opts)
41
47
  watir_sel_list[0].should be_instance_of PageObject::Elements::Option
42
48
  end
43
49
 
44
50
  it "should return an array of options" do
45
- watir_sel_list = PageObject::Elements::SelectList.new(sel_list, :platform => :watir_webdriver)
46
- sel_list.stub(:wd).and_return(sel_list)
47
51
  sel_list.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(opts)
48
52
  watir_sel_list.options.size.should == 2
49
53
  end
54
+
55
+ it "should return an array of selected options" do
56
+ sel_list.stub(:selected_options).and_return(opts)
57
+ watir_sel_list.selected_options.should == opts
58
+ end
59
+
60
+ it "should know if it includes some value" do
61
+ sel_list.stub(:include?).with('blah').and_return(true)
62
+ watir_sel_list.include?('blah')
63
+ end
64
+
65
+ it "should know if an option is selected" do
66
+ sel_list.stub(:selected?).with('blah').and_return(true)
67
+ watir_sel_list.selected?('blah')
68
+ end
50
69
  end
51
70
 
52
- context "for selenium" do
71
+ context "for selenium" do
72
+ let(:selenium_sel_list) { PageObject::Elements::SelectList.new(sel_list, :platform => :selenium_webdriver) }
73
+
53
74
  it "should return an option when indexed" do
54
- selenium_sel_list = PageObject::Elements::SelectList.new(sel_list, :platform => :selenium_webdriver)
55
75
  sel_list.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(opts)
56
76
  selenium_sel_list[1].should be_instance_of PageObject::Elements::Option
57
77
  end
58
78
 
59
79
  it "should return an array of options" do
60
- selenium_sel_list = PageObject::Elements::SelectList.new(sel_list, :platform => :selenium_webdriver)
61
80
  sel_list.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(opts)
62
81
  selenium_sel_list.options.size.should == 2
63
82
  end
64
83
 
65
84
  it "should select an element" do
66
- selenium_sel_list = PageObject::Elements::SelectList.new(sel_list, :platform => :selenium_webdriver)
67
85
  sel_list.should_receive(:send_keys).with('something')
68
86
  selenium_sel_list.select 'something'
69
87
  end
88
+
89
+ it "should return an array of selected options" do
90
+ sel_list.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(opts)
91
+ opts[0].should_receive(:selected?).and_return(true)
92
+ opts[0].should_receive(:text).and_return('test1')
93
+ opts[1].should_receive(:selected?).and_return(false)
94
+ selected = selenium_sel_list.selected_options
95
+ selected.size.should == 1
96
+ selected[0].should == 'test1'
97
+ end
98
+
99
+ it "should know if it includes some value" do
100
+ sel_list.should_receive(:find_elements).and_return(opts)
101
+ opts[0].should_receive(:text).and_return('blah')
102
+ selenium_sel_list.should include 'blah'
103
+ end
104
+
105
+ it "should know if an option is selected" do
106
+ sel_list.should_receive(:find_elements).and_return(opts)
107
+ opts[0].should_receive(:selected?).twice.and_return(true)
108
+ opts[0].should_receive(:text).and_return('blah')
109
+ selenium_sel_list.selected?('blah').should be_true
110
+ end
70
111
  end
71
112
  end
72
113
  end
@@ -32,6 +32,9 @@ describe PageObject::Elements::TextField do
32
32
  end
33
33
 
34
34
  describe "interface" do
35
+ let(:text_field_element) { double('text_field') }
36
+ let(:selenium_text_field) { PageObject::Elements::TextField.new(text_field_element, :platform => :selenium_webdriver) }
37
+
35
38
  it "should register with type :text" do
36
39
  ::PageObject::Elements.element_class_for(:input, :text).should == ::PageObject::Elements::TextField
37
40
  end
@@ -39,11 +42,14 @@ describe PageObject::Elements::TextField do
39
42
  it "should register with type :password" do
40
43
  ::PageObject::Elements.element_class_for(:input, :password).should == ::PageObject::Elements::TextField
41
44
  end
45
+
46
+ it "should append text" do
47
+ text_field_element.should_receive(:send_keys).with('abc')
48
+ selenium_text_field.append('abc')
49
+ end
42
50
 
43
51
  context "for selenium" do
44
52
  it "should set its' value" do
45
- text_field_element = double('selenium_text_field')
46
- selenium_text_field = PageObject::Elements::TextField.new(text_field_element, :platform => :selenium_webdriver)
47
53
  text_field_element.should_receive(:clear)
48
54
  text_field_element.should_receive(:send_keys).with('Joseph')
49
55
  selenium_text_field.value = 'Joseph'
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.6'
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-11 00:00:00.000000000 Z
12
+ date: 2012-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
16
- requirement: &70258715882600 !ruby/object:Gem::Requirement
16
+ requirement: &70219783537560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: 0.4.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70258715882600
24
+ version_requirements: *70219783537560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: selenium-webdriver
27
- requirement: &70258711304260 !ruby/object:Gem::Requirement
27
+ requirement: &70219783530900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 2.16.0
32
+ version: 2.17.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70258711304260
35
+ version_requirements: *70219783530900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70258711301120 !ruby/object:Gem::Requirement
38
+ requirement: &70219789108140 !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: *70258711301120
46
+ version_requirements: *70219789108140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: cucumber
49
- requirement: &70258711300560 !ruby/object:Gem::Requirement
49
+ requirement: &70219789106820 !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: *70258711300560
57
+ version_requirements: *70219789106820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &70258711298760 !ruby/object:Gem::Requirement
60
+ requirement: &70219789105960 !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: *70258711298760
68
+ version_requirements: *70219789105960
69
69
  description: Page Object DSL that works with both Watir and Selenium
70
70
  email:
71
71
  - jeff.morgan@leandog.com