Skip to content

Commit ce3c51b

Browse files
committed
rb - update spec locators from ordered parameters to hash syntax
1 parent 0363996 commit ce3c51b

12 files changed

Lines changed: 110 additions & 110 deletions

File tree

rb/lib/selenium/webdriver/common/action_builder.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def initialize(mouse, keyboard)
6868
#
6969
# @example Press a key on an element
7070
#
71-
# el = driver.find_element(:id, "some_id")
71+
# el = driver.find_element(id: "some_id")
7272
# driver.action.key_down(el, :shift).perform
7373
#
7474
# @param [:shift, :alt, :control, :command, :meta] The key to press.
@@ -94,7 +94,7 @@ def key_down(*args)
9494
#
9595
# @example Release a key from an element
9696
#
97-
# el = driver.find_element(:id, "some_id")
97+
# el = driver.find_element(id: "some_id")
9898
# driver.action.key_up(el, :alt).perform
9999
#
100100
# @param [:shift, :alt, :control, :command, :meta] The modifier key to release.
@@ -119,7 +119,7 @@ def key_up(*args)
119119
#
120120
# @example Send the text "help" to an element
121121
#
122-
# el = driver.find_element(:id, "some_id")
122+
# el = driver.find_element(id: "some_id")
123123
# driver.action.send_keys(el, "help").perform
124124
#
125125
# @example Send the text "help" to the currently focused element
@@ -146,7 +146,7 @@ def send_keys(*args)
146146
#
147147
# @example Clicking and holding on some element
148148
#
149-
# el = driver.find_element(:id, "some_id")
149+
# el = driver.find_element(id: "some_id")
150150
# driver.action.click_and_hold(el).perform
151151
#
152152
# @param [Selenium::WebDriver::Element] element the element to move to and click.
@@ -163,7 +163,7 @@ def click_and_hold(element = nil)
163163
#
164164
# @example Releasing an element after clicking and holding it
165165
#
166-
# el = driver.find_element(:id, "some_id")
166+
# el = driver.find_element(id: "some_id")
167167
# driver.action.click_and_hold(el).release.perform
168168
#
169169
# @return [ActionBuilder] A self reference.
@@ -183,7 +183,7 @@ def release(element = nil)
183183
#
184184
# @example Clicking on an element
185185
#
186-
# el = driver.find_element(:id, "some_id")
186+
# el = driver.find_element(id: "some_id")
187187
# driver.action.click(el).perform
188188
#
189189
# @example Clicking at the current mouse position
@@ -206,7 +206,7 @@ def click(element = nil)
206206
#
207207
# @example Double click an element
208208
#
209-
# el = driver.find_element(:id, "some_id")
209+
# el = driver.find_element(id: "some_id")
210210
# driver.action.double_click(el).perform
211211
#
212212
# @param [Selenium::WebDriver::Element] element An optional element to move to.
@@ -227,12 +227,12 @@ def double_click(element = nil)
227227
#
228228
# @example Scroll element into view and move the mouse to it
229229
#
230-
# el = driver.find_element(:id, "some_id")
230+
# el = driver.find_element(id: "some_id")
231231
# driver.action.move_to(el).perform
232232
#
233233
# @example
234234
#
235-
# el = driver.find_element(:id, "some_id")
235+
# el = driver.find_element(id: "some_id")
236236
# driver.action.move_to(el, 100, 100).perform
237237
#
238238
# @param [Selenium::WebDriver::Element] element to move to.
@@ -283,7 +283,7 @@ def move_by(right_by, down_by)
283283
#
284284
# @example Context-click at middle of given element
285285
#
286-
# el = driver.find_element(:id, "some_id")
286+
# el = driver.find_element(id: "some_id")
287287
# driver.action.context_click(el).perform
288288
#
289289
# @param [Selenium::WebDriver::Element] element An element to context click.
@@ -302,8 +302,8 @@ def context_click(element = nil)
302302
#
303303
# @example Drag and drop one element onto another
304304
#
305-
# el1 = driver.find_element(:id, "some_id1")
306-
# el2 = driver.find_element(:id, "some_id2")
305+
# el1 = driver.find_element(id: "some_id1")
306+
# el2 = driver.find_element(id: "some_id2")
307307
# driver.action.drag_and_drop(el1, el2).perform
308308
#
309309
# @param [Selenium::WebDriver::Element] source element to emulate button down at.
@@ -326,7 +326,7 @@ def drag_and_drop(source, target)
326326
#
327327
# @example Drag and drop an element by offset
328328
#
329-
# el = driver.find_element(:id, "some_id1")
329+
# el = driver.find_element(id: "some_id1")
330330
# driver.action.drag_and_drop_by(el, 100, 100).perform
331331
#
332332
# @param [Selenium::WebDriver::Element] source Element to emulate button down at.

rb/lib/selenium/webdriver/common/driver.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,13 @@ def execute_async_script(script, *args)
239239
#-------------------------------- sugar --------------------------------
240240

241241
#
242-
# driver.first(:id, 'foo')
242+
# driver.first(id: 'foo')
243243
#
244244

245245
alias_method :first, :find_element
246246

247247
#
248-
# driver.all(:class, 'bar') #=> [#<WebDriver::Element:0x1011c3b88, ...]
248+
# driver.all(class: 'bar') #=> [#<WebDriver::Element:0x1011c3b88, ...]
249249
#
250250

251251
alias_method :all, :find_elements

rb/lib/selenium/webdriver/common/element.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def hash
6464
#
6565
# @example Click on a button
6666
#
67-
# driver.find_element(:tag_name, "button").click
67+
# driver.find_element(tag_name: "button").click
6868
#
6969
# @raise [StaleElementReferenceError] if the element no longer exists as
7070
# defined
@@ -79,7 +79,7 @@ def click
7979
#
8080
# @example Get the tagname of an INPUT element(returns "input")
8181
#
82-
# driver.find_element(:xpath, "//input").tag_name
82+
# driver.find_element(xpath: "//input").tag_name
8383
#
8484
# @return [String] The tag name of this element.
8585
#
@@ -248,13 +248,13 @@ def size
248248
#-------------------------------- sugar --------------------------------
249249

250250
#
251-
# element.first(:id, 'foo')
251+
# element.first(id: 'foo')
252252
#
253253

254254
alias_method :first, :find_element
255255

256256
#
257-
# element.all(:class, 'bar')
257+
# element.all(class: 'bar')
258258
#
259259

260260
alias_method :all, :find_elements

rb/lib/selenium/webdriver/support/select.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def multiple?
5353
#
5454

5555
def options
56-
@element.find_elements :tag_name, 'option'
56+
@element.find_elements tag_name: 'option'
5757
end
5858

5959
#
@@ -242,7 +242,7 @@ def deselect_options(opts)
242242

243243
def find_by_text(text)
244244
xpath = ".//option[normalize-space(.) = #{Escaper.escape text}]"
245-
opts = @element.find_elements(:xpath, xpath)
245+
opts = @element.find_elements(xpath: xpath)
246246

247247
return opts unless opts.empty? && text =~ /\s+/
248248

@@ -251,7 +251,7 @@ def find_by_text(text)
251251
candidates = options
252252
else
253253
xpath = ".//option[contains(., #{Escaper.escape longest_word})]"
254-
candidates = @element.find_elements(:xpath, xpath)
254+
candidates = @element.find_elements(xpath: xpath)
255255
end
256256

257257
return Array(candidates.find { |option| text == option.text }) unless multiple?
@@ -263,7 +263,7 @@ def find_by_index(index)
263263
end
264264

265265
def find_by_value(value)
266-
@element.find_elements(:xpath, ".//option[@value = #{Escaper.escape value}]")
266+
@element.find_elements(xpath: ".//option[@value = #{Escaper.escape value}]")
267267
end
268268
end # Select
269269
end # Support

rb/spec/integration/selenium/webdriver/driver_spec.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ module WebDriver
3535
it 'should refresh the page' do
3636
driver.navigate.to url_for('javascriptPage.html')
3737
sleep 1 # javascript takes too long to load
38-
driver.find_element(:id, 'updatediv').click
39-
expect(driver.find_element(:id, 'dynamo').text).to eq('Fish and chips!')
38+
driver.find_element(id: 'updatediv').click
39+
expect(driver.find_element(id: 'dynamo').text).to eq('Fish and chips!')
4040
driver.navigate.refresh
41-
expect(driver.find_element(:id, 'dynamo').text).to eq("What's for dinner?")
41+
expect(driver.find_element(id: 'dynamo').text).to eq("What's for dinner?")
4242
end
4343

4444
not_compliant_on browser: :iphone do
@@ -73,55 +73,55 @@ module WebDriver
7373
describe 'one element' do
7474
it 'should find by id' do
7575
driver.navigate.to url_for('xhtmlTest.html')
76-
element = driver.find_element(:id, 'id1')
76+
element = driver.find_element(id: 'id1')
7777
expect(element).to be_kind_of(WebDriver::Element)
7878
expect(element.text).to eq('Foo')
7979
end
8080

8181
it 'should find by field name' do
8282
driver.navigate.to url_for('formPage.html')
83-
expect(driver.find_element(:name, 'x').attribute('value')).to eq('name')
83+
expect(driver.find_element(name: 'x').attribute('value')).to eq('name')
8484
end
8585

8686
it 'should find by class name' do
8787
driver.navigate.to url_for('xhtmlTest.html')
88-
expect(driver.find_element(:class, 'header').text).to eq('XHTML Might Be The Future')
88+
expect(driver.find_element(class: 'header').text).to eq('XHTML Might Be The Future')
8989
end
9090

9191
it 'should find by link text' do
9292
driver.navigate.to url_for('xhtmlTest.html')
93-
expect(driver.find_element(:link, 'Foo').text).to eq('Foo')
93+
expect(driver.find_element(link: 'Foo').text).to eq('Foo')
9494
end
9595

9696
it 'should find by xpath' do
9797
driver.navigate.to url_for('xhtmlTest.html')
98-
expect(driver.find_element(:xpath, '//h1').text).to eq('XHTML Might Be The Future')
98+
expect(driver.find_element(xpath: '//h1').text).to eq('XHTML Might Be The Future')
9999
end
100100

101101
it 'should find by css selector' do
102102
driver.navigate.to url_for('xhtmlTest.html')
103-
expect(driver.find_element(:css, 'div.content').attribute('class')).to eq('content')
103+
expect(driver.find_element(css: 'div.content').attribute('class')).to eq('content')
104104
end
105105

106106
it 'should find by tag name' do
107107
driver.navigate.to url_for('xhtmlTest.html')
108-
expect(driver.find_element(:tag_name, 'div').attribute('class')).to eq('navigation')
108+
expect(driver.find_element(tag_name: 'div').attribute('class')).to eq('navigation')
109109
end
110110

111111
it 'should find child element' do
112112
driver.navigate.to url_for('nestedElements.html')
113113

114-
element = driver.find_element(:name, 'form2')
115-
child = element.find_element(:name, 'selectomatic')
114+
element = driver.find_element(name: 'form2')
115+
child = element.find_element(name: 'selectomatic')
116116

117117
expect(child.attribute('id')).to eq('2')
118118
end
119119

120120
it 'should find child element by tag name' do
121121
driver.navigate.to url_for('nestedElements.html')
122122

123-
element = driver.find_element(:name, 'form2')
124-
child = element.find_element(:tag_name, 'select')
123+
element = driver.find_element(name: 'form2')
124+
child = element.find_element(tag_name: 'select')
125125

126126
expect(child.attribute('id')).to eq('2')
127127
end
@@ -147,18 +147,18 @@ module WebDriver
147147
describe 'many elements' do
148148
it 'should find by class name' do
149149
driver.navigate.to url_for('xhtmlTest.html')
150-
expect(driver.find_elements(:class, 'nameC').size).to eq(2)
150+
expect(driver.find_elements(class: 'nameC').size).to eq(2)
151151
end
152152

153153
it 'should find by css selector' do
154154
driver.navigate.to url_for('xhtmlTest.html')
155-
driver.find_elements(:css, 'p')
155+
driver.find_elements(css: 'p')
156156
end
157157

158158
it 'should find children by field name' do
159159
driver.navigate.to url_for('nestedElements.html')
160-
element = driver.find_element(:name, 'form2')
161-
children = element.find_elements(:name, 'selectomatic')
160+
element = driver.find_element(name: 'form2')
161+
children = element.find_elements(name: 'selectomatic')
162162
expect(children.size).to eq(2)
163163
end
164164
end
@@ -219,7 +219,7 @@ module WebDriver
219219
it 'should be able to call functions on the page' do
220220
driver.navigate.to url_for('javascriptPage.html')
221221
driver.execute_script("displayMessage('I like cheese');")
222-
expect(driver.find_element(:id, 'result').text.strip).to eq('I like cheese')
222+
expect(driver.find_element(id: 'result').text.strip).to eq('I like cheese')
223223
end
224224
end
225225

@@ -250,7 +250,7 @@ module WebDriver
250250

251251
it 'should be able to pass element arguments' do
252252
driver.navigate.to url_for('javascriptPage.html')
253-
button = driver.find_element(:id, 'plainButton')
253+
button = driver.find_element(id: 'plainButton')
254254
js = "arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble'];"
255255
expect(driver.execute_script(js, button))
256256
.to eq('plainButton')

0 commit comments

Comments
 (0)