Skip to content

Commit c498dad

Browse files
committed
[rb] set a default file detector for Remote Driver
1 parent 702b3aa commit c498dad

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

rb/lib/selenium/webdriver/remote/driver.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def initialize(bridge: nil, listener: nil, **opts)
4242
end
4343
opts[:url] ||= "http://#{Platform.localhost}:4444/wd/hub"
4444
super
45+
@bridge.file_detector = ->((filename, *)) { File.exist?(filename) && filename.to_s }
4546
end
4647

4748
private

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ module Remote
3131
expect(driver).to be_kind_of(DriverExtensions::HasRemoteStatus)
3232
expect(driver.remote_status).to be_kind_of(Hash)
3333
end
34+
35+
it 'uses a default file detector' do
36+
driver.navigate.to url_for('upload.html')
37+
38+
driver.find_element(id: 'upload').send_keys(__FILE__)
39+
driver.find_element(id: 'go').submit
40+
wait.until { driver.find_element(id: 'upload_label').displayed? }
41+
42+
driver.switch_to.frame('upload_target')
43+
wait.until { driver.find_element(xpath: '//body') }
44+
45+
body = driver.find_element(xpath: '//body')
46+
expect(body.text.scan('Licensed to the Software Freedom Conservancy').count).to eq(2)
47+
end
3448
end
3549
end # Remote
3650
end # WebDriver

rb/spec/integration/selenium/webdriver/remote/element_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module WebDriver
3131
end
3232

3333
context 'when uploading one file' do
34-
it 'uses the file detector' do
34+
it 'uses the provided file detector' do
3535
driver.navigate.to url_for('upload.html')
3636

3737
driver.find_element(id: 'upload').send_keys('element_spec.rb')
@@ -47,7 +47,7 @@ module WebDriver
4747
end
4848

4949
context 'when uploading multiple files' do
50-
it 'uses the file detector' do
50+
it 'uses the provided file detector' do
5151
driver.navigate.to url_for('upload_multiple.html')
5252

5353
driver.find_element(id: 'upload').send_keys("driver_spec.rb\nelement_spec.rb")
@@ -58,7 +58,7 @@ module WebDriver
5858
wait.until { driver.find_element(xpath: '//body') }
5959

6060
body = driver.find_element(xpath: '//body')
61-
expect(body.text.scan('Licensed to the Software Freedom Conservancy').count).to eq(4)
61+
expect(body.text.scan('Licensed to the Software Freedom Conservancy').count).to eq(5)
6262
end
6363
end
6464
end

0 commit comments

Comments
 (0)