watir 6.2.1 → 6.3.0

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.
@@ -1,147 +1,145 @@
1
1
  require "watirspec_helper"
2
2
 
3
- bug "https://github.com/ariya/phantomjs/issues/13115", :phantomjs do
4
- describe "Browser#cookies" do
5
- after { browser.cookies.clear }
3
+ describe "Browser#cookies" do
4
+ after { browser.cookies.clear }
6
5
 
7
- it 'gets an empty list of cookies' do
8
- browser.goto WatirSpec.url_for 'collections.html' # no cookie set.
9
- expect(browser.cookies.to_a).to eq []
10
- end
6
+ it 'gets an empty list of cookies' do
7
+ browser.goto WatirSpec.url_for 'collections.html' # no cookie set.
8
+ expect(browser.cookies.to_a).to eq []
9
+ end
11
10
 
12
- it "gets any cookies set" do
13
- browser.goto set_cookie_url
11
+ it "gets any cookies set" do
12
+ browser.goto set_cookie_url
14
13
 
15
- verify_cookies_count 1
14
+ verify_cookies_count 1
16
15
 
17
- cookie = browser.cookies.to_a.first
18
- expect(cookie[:name]).to eq 'monster'
19
- expect(cookie[:value]).to eq '1'
20
- end
16
+ cookie = browser.cookies.to_a.first
17
+ expect(cookie[:name]).to eq 'monster'
18
+ expect(cookie[:value]).to eq '1'
19
+ end
21
20
 
22
- describe '#[]' do
23
- before do
24
- browser.goto set_cookie_url
25
- verify_cookies_count 1
26
- end
21
+ describe '#[]' do
22
+ before do
23
+ browser.goto set_cookie_url
24
+ verify_cookies_count 1
25
+ end
27
26
 
28
- it 'returns cookie by symbol name' do
29
- cookie = browser.cookies[:monster]
30
- expect(cookie[:name]).to eq('monster')
31
- expect(cookie[:value]).to eq('1')
32
- end
27
+ it 'returns cookie by symbol name' do
28
+ cookie = browser.cookies[:monster]
29
+ expect(cookie[:name]).to eq('monster')
30
+ expect(cookie[:value]).to eq('1')
31
+ end
33
32
 
34
- it 'returns cookie by string name' do
35
- cookie = browser.cookies['monster']
36
- expect(cookie[:name]).to eq('monster')
37
- expect(cookie[:value]).to eq('1')
38
- end
33
+ it 'returns cookie by string name' do
34
+ cookie = browser.cookies['monster']
35
+ expect(cookie[:name]).to eq('monster')
36
+ expect(cookie[:value]).to eq('1')
37
+ end
39
38
 
40
- it 'returns nil if there is no cookie with such name' do
41
- expect(browser.cookies[:non_monster]).to eq(nil)
42
- end
39
+ it 'returns nil if there is no cookie with such name' do
40
+ expect(browser.cookies[:non_monster]).to eq(nil)
43
41
  end
42
+ end
44
43
 
45
- not_compliant_on :internet_explorer do
46
- it 'adds a cookie' do
47
- browser.goto set_cookie_url
48
- verify_cookies_count 1
44
+ not_compliant_on :internet_explorer do
45
+ it 'adds a cookie' do
46
+ browser.goto set_cookie_url
47
+ verify_cookies_count 1
49
48
 
50
- browser.cookies.add 'foo', 'bar'
51
- verify_cookies_count 2
49
+ browser.cookies.add 'foo', 'bar'
50
+ verify_cookies_count 2
52
51
 
53
- compliant_on :safari do
54
- $browser.close
55
- $browser = WatirSpec.new_browser
56
- end
52
+ compliant_on :safari do
53
+ $browser.close
54
+ $browser = WatirSpec.new_browser
57
55
  end
58
56
  end
57
+ end
59
58
 
60
- # TODO - Split this up into multiple tests or figure out which parts are not compliant
61
- not_compliant_on :chrome, :internet_explorer, :safari, :firefox do
62
- it 'adds a cookie with options' do
63
- browser.goto set_cookie_url
59
+ # TODO - Split this up into multiple tests or figure out which parts are not compliant
60
+ not_compliant_on :chrome, :internet_explorer, :safari, :firefox do
61
+ it 'adds a cookie with options' do
62
+ browser.goto set_cookie_url
64
63
 
65
- expires = Time.now + 10000
66
- options = {path: "/set_cookie",
67
- secure: true,
68
- expires: expires}
64
+ expires = Time.now + 10000
65
+ options = {path: "/set_cookie",
66
+ secure: true,
67
+ expires: expires}
69
68
 
70
- browser.cookies.add 'a', 'b', options
71
- cookie = browser.cookies.to_a.find { |e| e[:name] == 'a' }
72
- expect(cookie).to_not be_nil
69
+ browser.cookies.add 'a', 'b', options
70
+ cookie = browser.cookies.to_a.find { |e| e[:name] == 'a' }
71
+ expect(cookie).to_not be_nil
73
72
 
74
- expect(cookie[:name]).to eq 'a'
75
- expect(cookie[:value]).to eq 'b'
73
+ expect(cookie[:name]).to eq 'a'
74
+ expect(cookie[:value]).to eq 'b'
76
75
 
77
- expect(cookie[:path]).to eq "/set_cookie"
78
- expect(cookie[:secure]).to be true
76
+ expect(cookie[:path]).to eq "/set_cookie"
77
+ expect(cookie[:secure]).to be true
79
78
 
80
- expect(cookie[:expires]).to be_kind_of(Time)
81
- # a few ms slack
82
- expect((cookie[:expires]).to_i).to be_within(2).of(expires.to_i)
83
- end
79
+ expect(cookie[:expires]).to be_kind_of(Time)
80
+ # a few ms slack
81
+ expect((cookie[:expires]).to_i).to be_within(2).of(expires.to_i)
84
82
  end
83
+ end
85
84
 
86
- not_compliant_on :internet_explorer do
87
- it 'removes a cookie' do
88
- browser.goto set_cookie_url
89
- verify_cookies_count 1
85
+ not_compliant_on :internet_explorer do
86
+ it 'removes a cookie' do
87
+ browser.goto set_cookie_url
88
+ verify_cookies_count 1
90
89
 
91
- browser.cookies.delete 'monster'
92
- verify_cookies_count 0
93
- end
90
+ browser.cookies.delete 'monster'
91
+ verify_cookies_count 0
92
+ end
94
93
 
95
- bug "https://code.google.com/p/selenium/issues/detail?id=5487", :safari do
96
- it 'clears all cookies' do
97
- browser.goto set_cookie_url
98
- browser.cookies.add 'foo', 'bar'
99
- verify_cookies_count 2
94
+ bug "https://code.google.com/p/selenium/issues/detail?id=5487", :safari do
95
+ it 'clears all cookies' do
96
+ browser.goto set_cookie_url
97
+ browser.cookies.add 'foo', 'bar'
98
+ verify_cookies_count 2
100
99
 
101
- browser.cookies.clear
102
- verify_cookies_count 0
103
- end
100
+ browser.cookies.clear
101
+ verify_cookies_count 0
104
102
  end
105
103
  end
104
+ end
106
105
 
107
- not_compliant_on :internet_explorer do
108
- let(:file) { "#{Dir.tmpdir}/cookies" }
106
+ not_compliant_on :internet_explorer do
107
+ let(:file) { "#{Dir.tmpdir}/cookies" }
109
108
 
110
- before do
111
- browser.goto set_cookie_url
112
- browser.cookies.save file
113
- end
109
+ before do
110
+ browser.goto set_cookie_url
111
+ browser.cookies.save file
112
+ end
114
113
 
115
- describe '#save' do
116
- it 'saves cookies to file' do
117
- expect(IO.read(file)).to eq(browser.cookies.to_a.to_yaml)
118
- end
114
+ describe '#save' do
115
+ it 'saves cookies to file' do
116
+ expect(IO.read(file)).to eq(browser.cookies.to_a.to_yaml)
119
117
  end
118
+ end
120
119
 
121
- describe '#load' do
122
- it 'loads cookies from file' do
123
- browser.cookies.clear
124
- browser.cookies.load file
125
- expected = browser.cookies.to_a
126
- actual = YAML.load(IO.read(file))
120
+ describe '#load' do
121
+ it 'loads cookies from file' do
122
+ browser.cookies.clear
123
+ browser.cookies.load file
124
+ expected = browser.cookies.to_a
125
+ actual = YAML.load(IO.read(file))
127
126
 
128
- # https://code.google.com/p/selenium/issues/detail?id=6834
129
- expected.each { |cookie| cookie.delete(:expires) }
130
- actual.each { |cookie| cookie.delete(:expires) }
127
+ # https://code.google.com/p/selenium/issues/detail?id=6834
128
+ expected.each { |cookie| cookie.delete(:expires) }
129
+ actual.each { |cookie| cookie.delete(:expires) }
131
130
 
132
- expect(actual).to eq(expected)
133
- end
131
+ expect(actual).to eq(expected)
134
132
  end
135
133
  end
134
+ end
136
135
 
137
- def set_cookie_url
138
- # add timestamp to url to avoid caching in IE8
139
- WatirSpec.url_for('set_cookie/index.html') + "?t=#{Time.now.to_i + Time.now.usec}"
140
- end
136
+ def set_cookie_url
137
+ # add timestamp to url to avoid caching in IE8
138
+ WatirSpec.url_for('set_cookie/index.html') + "?t=#{Time.now.to_i + Time.now.usec}"
139
+ end
141
140
 
142
- def verify_cookies_count expected_size
143
- cookies = browser.cookies.to_a
144
- expect(cookies.size).to eq(expected_size), "expected #{expected_size} cookies, got #{cookies.size}: #{cookies.inspect}"
145
- end
141
+ def verify_cookies_count expected_size
142
+ cookies = browser.cookies.to_a
143
+ expect(cookies.size).to eq(expected_size), "expected #{expected_size} cookies, got #{cookies.size}: #{cookies.inspect}"
146
144
  end
147
145
  end
@@ -166,9 +166,7 @@ describe "Div" do
166
166
  it "fires the oncontextmenu event" do
167
167
  browser.goto(WatirSpec.url_for("right_click.html"))
168
168
  browser.div(id: "click").right_click
169
- bug "https://github.com/detro/ghostdriver/issues/125", :phantomjs do
170
- expect(messages.first).to eq 'right-clicked'
171
- end
169
+ expect(messages.first).to eq 'right-clicked'
172
170
  end
173
171
  end
174
172
  end
@@ -249,6 +249,20 @@ describe "Element" do
249
249
  end
250
250
  end
251
251
 
252
+ context "attribute presence" do
253
+ before { browser.goto WatirSpec.url_for("data_attributes.html") }
254
+
255
+ it "finds element by attribute presence" do
256
+ expect(browser.p(data_type: true)).to exist
257
+ expect(browser.p(class: true)).not_to exist
258
+ end
259
+
260
+ it "finds element by attribute absence" do
261
+ expect(browser.p(data_type: false)).not_to exist
262
+ expect(browser.p(class: false)).to exist
263
+ end
264
+ end
265
+
252
266
  it "doesn't raise when called on nested elements" do
253
267
  expect(browser.div(id: 'no_such_div').link(id: 'no_such_id')).to_not exist
254
268
  end
@@ -277,8 +291,7 @@ describe "Element" do
277
291
  bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255906", :firefox do
278
292
  describe '#send_keys' do
279
293
  before(:each) do
280
- phantom = browser.driver.capabilities.browser_name == 'phantomjs'
281
- @c = Selenium::WebDriver::Platform.mac? && !phantom ? :command : :control
294
+ @c = Selenium::WebDriver::Platform.mac? ? :command : :control
282
295
  browser.goto(WatirSpec.url_for('keylogger.html'))
283
296
  end
284
297
 
@@ -110,20 +110,18 @@ describe "FileField" do
110
110
  describe "#set" do
111
111
  not_compliant_on :safari do
112
112
  bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1260233", :firefox do
113
- bug "https://github.com/detro/ghostdriver/issues/183", :phantomjs do
114
- it "is able to set a file path in the field and click the upload button and fire the onchange event" do
115
- browser.goto WatirSpec.url_for("forms_with_input_elements.html")
113
+ it "is able to set a file path in the field and click the upload button and fire the onchange event" do
114
+ browser.goto WatirSpec.url_for("forms_with_input_elements.html")
116
115
 
117
- path = File.expand_path(__FILE__)
118
- element = browser.file_field(name: "new_user_portrait")
116
+ path = File.expand_path(__FILE__)
117
+ element = browser.file_field(name: "new_user_portrait")
119
118
 
120
- element.set path
119
+ element.set path
121
120
 
122
- expect(element.value).to include(File.basename(path)) # only some browser will return the full path
123
- expect(messages.first).to include(File.basename(path))
121
+ expect(element.value).to include(File.basename(path)) # only some browser will return the full path
122
+ expect(messages.first).to include(File.basename(path))
124
123
 
125
- browser.button(name: "new_user_submit").click
126
- end
124
+ browser.button(name: "new_user_submit").click
127
125
  end
128
126
 
129
127
  it "raises an error if the file does not exist" do
@@ -135,41 +133,38 @@ describe "FileField" do
135
133
  end
136
134
  end
137
135
 
136
+ not_compliant_on :safari do
137
+ describe "#value=" do
138
+ bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1260233", :firefox do
139
+ it "is able to set a file path in the field and click the upload button and fire the onchange event" do
140
+ browser.goto WatirSpec.url_for("forms_with_input_elements.html")
138
141
 
139
- bug "https://github.com/detro/ghostdriver/issues/183", :phantomjs do
140
- not_compliant_on :safari do
141
- describe "#value=" do
142
- bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1260233", :firefox do
143
- it "is able to set a file path in the field and click the upload button and fire the onchange event" do
144
- browser.goto WatirSpec.url_for("forms_with_input_elements.html")
145
-
146
- path = File.expand_path(__FILE__)
147
- element = browser.file_field(name: "new_user_portrait")
142
+ path = File.expand_path(__FILE__)
143
+ element = browser.file_field(name: "new_user_portrait")
148
144
 
149
- element.value = path
150
- expect(element.value).to include(File.basename(path)) # only some browser will return the full path
151
- end
145
+ element.value = path
146
+ expect(element.value).to include(File.basename(path)) # only some browser will return the full path
147
+ end
152
148
 
153
- not_compliant_on :internet_explorer do
154
- bug "Raises File not found error - File Bug Report", :firefox do
155
- it "does not raise an error if the file does not exist" do
156
- path = File.join(Dir.tmpdir, 'unlikely-to-exist')
157
- browser.file_field.value = path
149
+ not_compliant_on :internet_explorer do
150
+ bug "Raises File not found error - File Bug Report", :firefox do
151
+ it "does not raise an error if the file does not exist" do
152
+ path = File.join(Dir.tmpdir, 'unlikely-to-exist')
153
+ browser.file_field.value = path
158
154
 
159
- expected = path
160
- expected.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
155
+ expected = path
156
+ expected.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
161
157
 
162
- expect(browser.file_field.value).to include(File.basename(expected)) # only some browser will return the full path
163
- end
158
+ expect(browser.file_field.value).to include(File.basename(expected)) # only some browser will return the full path
164
159
  end
160
+ end
165
161
 
166
- not_compliant_on %i(chrome windows) do
167
- bug "Raises File not found error - File Bug Report", :firefox do
168
- it "does not alter its argument" do
169
- value = '/foo/bar'
170
- browser.file_field.value = value
171
- expect(value).to eq '/foo/bar'
172
- end
162
+ not_compliant_on %i(chrome windows) do
163
+ bug "Raises File not found error - File Bug Report", :firefox do
164
+ it "does not alter its argument" do
165
+ value = '/foo/bar'
166
+ browser.file_field.value = value
167
+ expect(value).to eq '/foo/bar'
173
168
  end
174
169
  end
175
170
  end
@@ -50,15 +50,13 @@ describe "Frame" do
50
50
  expect(browser.frame(xpath: "//frame[@id='no_such_id']")).to_not exist
51
51
  end
52
52
 
53
- bug "https://github.com/detro/ghostdriver/issues/159", :phantomjs do
54
- bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255946", :firefox do
55
- it "handles nested frames" do
56
- browser.goto(WatirSpec.url_for("nested_frames.html"))
53
+ bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255946", :firefox do
54
+ it "handles nested frames" do
55
+ browser.goto(WatirSpec.url_for("nested_frames.html"))
57
56
 
58
- browser.frame(id: "two").frame(id: "three").link(id: "four").click
57
+ browser.frame(id: "two").frame(id: "three").link(id: "four").click
59
58
 
60
- Watir::Wait.until { browser.title == "definition_lists" }
61
- end
59
+ Watir::Wait.until { browser.title == "definition_lists" }
62
60
  end
63
61
  end
64
62
 
@@ -82,15 +82,13 @@ describe "IFrame" do
82
82
  end
83
83
 
84
84
 
85
- bug "https://github.com/detro/ghostdriver/issues/159", :phantomjs do
86
- bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255946", :firefox do
87
- it "handles nested iframes" do
88
- browser.goto(WatirSpec.url_for("nested_iframes.html"))
85
+ bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255946", :firefox do
86
+ it "handles nested iframes" do
87
+ browser.goto(WatirSpec.url_for("nested_iframes.html"))
89
88
 
90
- browser.iframe(id: "two").iframe(id: "three").link(id: "four").click
89
+ browser.iframe(id: "two").iframe(id: "three").link(id: "four").click
91
90
 
92
- Watir::Wait.until { browser.title == "definition_lists" }
93
- end
91
+ Watir::Wait.until { browser.title == "definition_lists" }
94
92
  end
95
93
  end
96
94
 
@@ -102,6 +102,18 @@ describe "SelectList" do
102
102
  expect { browser.select_list(index: 1337).value }.to raise_unknown_object_exception
103
103
  end
104
104
  end
105
+
106
+ describe "#text" do
107
+ it "returns the text of the selected option" do
108
+ expect(browser.select_list(index: 0).text).to eq "Norway"
109
+ browser.select_list(index: 0).select(/Sweden/)
110
+ expect(browser.select_list(index: 0).text).to eq "Sweden"
111
+ end
112
+
113
+ it "raises UnknownObjectException if the select list doesn't exist" do
114
+ expect { browser.select_list(index: 1337).text }.to raise_unknown_object_exception
115
+ end
116
+ end
105
117
 
106
118
  describe "#respond_to?" do
107
119
  it "returns true for all attribute methods" do
@@ -189,12 +201,10 @@ describe "SelectList" do
189
201
  end
190
202
 
191
203
  not_compliant_on :safari do
192
- bug "Not firing events", :phantomjs do
193
- bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
194
- it "fires onchange event" do
195
- browser.select_list(name: "new_user_languages").clear
196
- expect(messages.size).to eq 2
197
- end
204
+ bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
205
+ it "fires onchange event" do
206
+ browser.select_list(name: "new_user_languages").clear
207
+ expect(messages.size).to eq 2
198
208
  end
199
209
  end
200
210
 
@@ -305,23 +315,19 @@ describe "SelectList" do
305
315
  end
306
316
 
307
317
  not_compliant_on :safari do
308
- bug "Not firing events", :phantomjs do
309
- it "fires onchange event when selecting an item" do
310
- browser.select_list(id: "new_user_languages").select("Danish")
311
- expect(messages).to eq ['changed language']
312
- end
318
+ it "fires onchange event when selecting an item" do
319
+ browser.select_list(id: "new_user_languages").select("Danish")
320
+ expect(messages).to eq ['changed language']
313
321
  end
314
322
 
315
- bug "Not firing events", :phantomjs do
316
- bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
317
- it "doesn't fire onchange event when selecting an already selected item" do
318
- browser.select_list(id: "new_user_languages").clear # removes the two pre-selected options
319
- browser.select_list(id: "new_user_languages").select("English")
320
- expect(messages.size).to eq 3
323
+ bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
324
+ it "doesn't fire onchange event when selecting an already selected item" do
325
+ browser.select_list(id: "new_user_languages").clear # removes the two pre-selected options
326
+ browser.select_list(id: "new_user_languages").select("English")
327
+ expect(messages.size).to eq 3
321
328
 
322
- browser.select_list(id: "new_user_languages").select("English")
323
- expect(messages.size).to eq 3
324
- end
329
+ browser.select_list(id: "new_user_languages").select("English")
330
+ expect(messages.size).to eq 3
325
331
  end
326
332
  end
327
333
  end