page-object 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ === Version 0.7.4 / 2012-9-8
2
+ * Enhancements
3
+ * Added ability to find text_fields with :css when using Selenium
4
+ * Added selected_values method to SelectList to get values of all selected elements
5
+ * Fixes
6
+ * Fixed problem getting value from SelectList when it is in a Frame with Selenium
7
+
1
8
  === Version 0.7.3 / 2012-8-18
2
9
  * Enhancements
3
10
  * Improved handling of alert and confirm Javascript popups (George Shakhnazaryan)
@@ -282,7 +282,6 @@ Feature: Elements
282
282
  When I retrieve a button element
283
283
  Then I should be able to flash it
284
284
 
285
- @focus
286
285
  Scenario: Getting an element's id
287
286
  When I retrieve a button element
288
287
  Then I should know its id is "button_id"
@@ -31,6 +31,10 @@ Feature: Page level actions
31
31
  When I handle the alert
32
32
  Then I should be able to get the alert's message
33
33
 
34
+ Scenario: Handling possible alert popups
35
+ When I handle the possible alert
36
+ Then I should be able to verify the popup didn't have a message
37
+
34
38
  Scenario: Handling alert popups that reload the page
35
39
  When I handle the alert that reloads the page
36
40
  Then I should be able to get the alert's message
@@ -39,6 +43,10 @@ Feature: Page level actions
39
43
  When I handle the confirm
40
44
  Then I should be able to get the confirm message
41
45
 
46
+ Scenario: Handling possible confirm popups
47
+ When I handle the possible confirm
48
+ Then I should be able to verify the popup didn't have a message
49
+
42
50
  Scenario: Handling confirm popups that reload the page
43
51
  When I handle the confirm that reloads the page
44
52
  Then I should be able to get the confirm message
@@ -46,6 +54,10 @@ Feature: Page level actions
46
54
  Scenario: Handling prompt popups
47
55
  When I handle the prompt
48
56
  Then I should be able to get the message and default value
57
+
58
+ Scenario: Handling possible prompt popups
59
+ When I handle the possible prompt
60
+ Then I should be able to verify the popup didn't have a message
49
61
 
50
62
  Scenario: Attach to window using title
51
63
  When I open a second window
@@ -64,3 +64,7 @@ Feature: Select List
64
64
  Scenario: Selecting an option by its value
65
65
  When I select an option using the value "option2"
66
66
  Then the selected option should be "Test 2"
67
+
68
+ Scenario: Getting the value from a selected option
69
+ When I select an option using the value "option2"
70
+ Then the selected option should have a value of "option2"
@@ -23,6 +23,12 @@ When /^I handle the alert$/ do
23
23
  end
24
24
  end
25
25
 
26
+ When /^I handle the possible alert$/ do
27
+ @msg = @page.alert do
28
+ @page.alert_button_element.focus
29
+ end
30
+ end
31
+
26
32
  When /^I handle the alert that reloads the page$/ do
27
33
  @msg = @page.alert do
28
34
  @page.alert_button_that_reloads
@@ -33,12 +39,22 @@ Then /^I should be able to get the alert\'s message$/ do
33
39
  @msg.should == "I am an alert"
34
40
  end
35
41
 
42
+ Then /^I should be able to verify the popup didn\'t have a message$/ do
43
+ @msg.should be_nil
44
+ end
45
+
36
46
  When /^I handle the confirm$/ do
37
47
  @msg = @page.confirm(true) do
38
48
  @page.confirm_button
39
49
  end
40
50
  end
41
51
 
52
+ When /^I handle the possible confirm$/ do
53
+ @msg = @page.confirm(true) do
54
+ @page.confirm_button_element.focus
55
+ end
56
+ end
57
+
42
58
  When /^I handle the confirm that reloads the page$/ do
43
59
  @msg = @page.confirm(true) do
44
60
  @page.confirm_button_that_reloads
@@ -55,6 +71,12 @@ When /^I handle the prompt$/ do
55
71
  end
56
72
  end
57
73
 
74
+ When /^I handle the possible prompt$/ do
75
+ @msg = @page.prompt("Cheezy") do
76
+ @page.prompt_button_element.focus
77
+ end
78
+ end
79
+
58
80
  Then /^I should be able to get the message and default value$/ do
59
81
  @msg[:message].should == "enter your name"
60
82
  @msg[:default_value].should == 'John Doe'
@@ -59,3 +59,7 @@ end
59
59
  When /^I select an option using the value "([^\"]*)"$/ do |value|
60
60
  @page.sel_list_id_element.select_value(value)
61
61
  end
62
+
63
+ Then /^the selected option should have a value of "([^\"]*)"$/ do |value|
64
+ @page.sel_list_id_element.selected_values[0].should == value
65
+ end
@@ -25,6 +25,16 @@ Feature: Text Fields
25
25
  | text |
26
26
  | label |
27
27
 
28
+ @selenium_only
29
+ Scenario Outline: Locating text fields on the Page using Selenium
30
+ When I search for the text field by "<search_by>"
31
+ Then I should be able to type "I found it" into the field
32
+
33
+ Examples:
34
+ | search_by |
35
+ | css |
36
+
37
+
28
38
  Scenario Outline: Locating a text field using multiple parameters
29
39
  When I search for the text field by "<param1>" and "<param2>"
30
40
  Then I should be able to type "I found it" into the field
@@ -97,6 +97,7 @@ module PageObject
97
97
  # @param [Hash] identifier how we find a text field. You can use a multiple paramaters
98
98
  # by combining of any of the following except xpath. The valid keys are:
99
99
  # * :class => Watir and Selenium
100
+ # * :css => Selenium only
100
101
  # * :id => Watir and Selenium
101
102
  # * :index => Watir and Selenium
102
103
  # * :label => Watir and Selenium
@@ -19,7 +19,7 @@ module PageObject
19
19
  end
20
20
 
21
21
  def self.selenium_finders
22
- super + [:title, :value, :text, :label]
22
+ super + [:title, :value, :text, :label, :css]
23
23
  end
24
24
 
25
25
  def include_platform_for platform
@@ -71,9 +71,12 @@ module PageObject
71
71
  #
72
72
  def alert(frame=nil, &block)
73
73
  yield
74
- alert = @browser.switch_to.alert
75
- value = alert.text
76
- alert.accept
74
+ begin
75
+ alert = @browser.switch_to.alert
76
+ value = alert.text
77
+ alert.accept
78
+ rescue Selenium::WebDriver::Error::NoAlertPresentError
79
+ end
77
80
  value
78
81
  end
79
82
 
@@ -83,9 +86,12 @@ module PageObject
83
86
  #
84
87
  def confirm(response, frame=nil, &block)
85
88
  yield
86
- alert = @browser.switch_to.alert
87
- value = alert.text
88
- response ? alert.accept : alert.dismiss
89
+ begin
90
+ alert = @browser.switch_to.alert
91
+ value = alert.text
92
+ response ? alert.accept : alert.dismiss
93
+ rescue Selenium::WebDriver::Error::NoAlertPresentError
94
+ end
89
95
  value
90
96
  end
91
97
 
@@ -291,9 +297,13 @@ module PageObject
291
297
  #
292
298
  def select_list_value_for(identifier)
293
299
  process_selenium_call(identifier, Elements::SelectList, 'select') do |how, what|
300
+ selected = nil
294
301
  @browser.find_element(how, what).find_elements(:tag_name => 'option').each do |o|
295
- return o.text if o.selected?
302
+ if selected.nil?
303
+ selected = o.text if o.selected?
304
+ end
296
305
  end
306
+ selected
297
307
  end
298
308
  end
299
309
 
@@ -42,12 +42,19 @@ module PageObject
42
42
  end
43
43
 
44
44
  #
45
- # @return [Array<String>] An array of strings representing the text value of the currently selected options.
45
+ # @return [Array<String>] An array of strings representing the text of the currently selected options.
46
46
  #
47
47
  def selected_options
48
48
  find_options.map { |e| e.text if e.selected? }.compact
49
49
  end
50
50
 
51
+ #
52
+ # @return [Array<String>] An array of strings representing the value of the currently selected options.
53
+ #
54
+ def selected_values
55
+ find_options.map { |e| e.attribute('value') if e.selected? }.compact
56
+ end
57
+
51
58
  #
52
59
  # Returns true if the select list has one or more options where text or label matches the given value.
53
60
  #
@@ -72,8 +72,11 @@ module PageObject
72
72
  def alert(frame=nil, &block)
73
73
  switch_to_frame(frame)
74
74
  yield
75
- value = @browser.alert.text
76
- @browser.alert.ok
75
+ value = nil
76
+ if @browser.alert.exists?
77
+ value = @browser.alert.text
78
+ @browser.alert.ok
79
+ end
77
80
  switch_to_default_content(frame)
78
81
  value
79
82
  end
@@ -85,8 +88,11 @@ module PageObject
85
88
  def confirm(response, frame=nil, &block)
86
89
  switch_to_frame(frame)
87
90
  yield
88
- value = @browser.alert.text
89
- response ? @browser.alert.ok : @browser.alert.close
91
+ value = nil
92
+ if @browser.alert.exists?
93
+ value = @browser.alert.text
94
+ response ? @browser.alert.ok : @browser.alert.close
95
+ end
90
96
  switch_to_default_content(frame)
91
97
  value
92
98
  end
@@ -43,12 +43,20 @@ module PageObject
43
43
  end
44
44
 
45
45
  #
46
- # @return [Array<String>] An array of strings representing the text value of the currently selected options.
46
+ # @return [Array<String>] An array of strings representing the text of the currently selected options.
47
47
  #
48
48
  def selected_options
49
49
  element.selected_options.map { |e| e.text }.compact
50
50
  end
51
51
 
52
+ #
53
+ # @return [Array<String>] An array of strings representing the value of the currently selected options.
54
+ #
55
+ def selected_values
56
+ element.selected_options.map { |e| e.value }.compact
57
+ end
58
+
59
+
52
60
  #
53
61
  # Returns true if the select list has one or more options where text or label matches the given value.
54
62
  #
@@ -1,4 +1,4 @@
1
1
  module PageObject
2
2
  # @private
3
- VERSION = "0.7.3"
3
+ VERSION = "0.7.4"
4
4
  end
@@ -67,6 +67,12 @@ describe PageObject::Elements::SelectList do
67
67
  sel_list.stub(:selected?).with('blah').and_return(true)
68
68
  watir_sel_list.selected?('blah')
69
69
  end
70
+
71
+ it "should be able to get the value for the selected options" do
72
+ sel_list.stub(:selected_options).and_return(opts)
73
+ sel_list.stub(:value).and_return(sel_list)
74
+ watir_sel_list.selected_values.should == opts
75
+ end
70
76
  end
71
77
 
72
78
  context "for selenium" do
@@ -100,6 +106,16 @@ describe PageObject::Elements::SelectList do
100
106
  selected[0].should == 'test1'
101
107
  end
102
108
 
109
+ it "should return an array of selected options" do
110
+ sel_list.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(opts)
111
+ opts[0].should_receive(:selected?).and_return(true)
112
+ opts[0].should_receive(:attribute).and_return('test1')
113
+ opts[1].should_receive(:selected?).and_return(false)
114
+ selected = selenium_sel_list.selected_values
115
+ selected.size.should == 1
116
+ selected[0].should == 'test1'
117
+ end
118
+
103
119
  it "should know if it includes some value" do
104
120
  sel_list.should_receive(:find_elements).and_return(opts)
105
121
  opts[0].should_receive(:text).and_return('blah')
@@ -123,7 +123,8 @@ describe PageObject do
123
123
  end
124
124
 
125
125
  it "should override alert popup behavior" do
126
- watir_browser.should_receive(:alert).twice.and_return(watir_browser)
126
+ watir_browser.should_receive(:alert).exactly(3).times.and_return(watir_browser)
127
+ watir_browser.should_receive(:exists?).and_return(true)
127
128
  watir_browser.should_receive(:text)
128
129
  watir_browser.should_receive(:ok)
129
130
  watir_page_object.alert do
@@ -131,7 +132,8 @@ describe PageObject do
131
132
  end
132
133
 
133
134
  it "should override confirm popup behavior" do
134
- watir_browser.should_receive(:alert).twice.and_return(watir_browser)
135
+ watir_browser.should_receive(:alert).exactly(3).times.and_return(watir_browser)
136
+ watir_browser.should_receive(:exists?).and_return(true)
135
137
  watir_browser.should_receive(:text)
136
138
  watir_browser.should_receive(:ok)
137
139
  watir_page_object.confirm(true) do
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.7.3
4
+ version: 0.7.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-18 00:00:00.000000000 Z
12
+ date: 2012-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
@@ -370,7 +370,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
370
370
  version: '0'
371
371
  segments:
372
372
  - 0
373
- hash: 2357863127966397985
373
+ hash: -734083501090794232
374
374
  required_rubygems_version: !ruby/object:Gem::Requirement
375
375
  none: false
376
376
  requirements:
@@ -379,7 +379,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
379
379
  version: '0'
380
380
  segments:
381
381
  - 0
382
- hash: 2357863127966397985
382
+ hash: -734083501090794232
383
383
  requirements: []
384
384
  rubyforge_project: page-object
385
385
  rubygems_version: 1.8.24