Skip to content

Commit

Permalink
[rb] set a default file detector for Remote Driver
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Aug 3, 2021
1 parent 702b3aa commit c498dad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/remote/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def initialize(bridge: nil, listener: nil, **opts)
end
opts[:url] ||= "http://#{Platform.localhost}:4444/wd/hub"
super
@bridge.file_detector = ->((filename, *)) { File.exist?(filename) && filename.to_s }
end

private
Expand Down
14 changes: 14 additions & 0 deletions rb/spec/integration/selenium/webdriver/remote/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ module Remote
expect(driver).to be_kind_of(DriverExtensions::HasRemoteStatus)
expect(driver.remote_status).to be_kind_of(Hash)
end

it 'uses a default file detector' do
driver.navigate.to url_for('upload.html')

driver.find_element(id: 'upload').send_keys(__FILE__)
driver.find_element(id: 'go').submit
wait.until { driver.find_element(id: 'upload_label').displayed? }

driver.switch_to.frame('upload_target')
wait.until { driver.find_element(xpath: '//body') }

body = driver.find_element(xpath: '//body')
expect(body.text.scan('Licensed to the Software Freedom Conservancy').count).to eq(2)
end
end
end # Remote
end # WebDriver
Expand Down
6 changes: 3 additions & 3 deletions rb/spec/integration/selenium/webdriver/remote/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module WebDriver
end

context 'when uploading one file' do
it 'uses the file detector' do
it 'uses the provided file detector' do
driver.navigate.to url_for('upload.html')

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

context 'when uploading multiple files' do
it 'uses the file detector' do
it 'uses the provided file detector' do
driver.navigate.to url_for('upload_multiple.html')

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

body = driver.find_element(xpath: '//body')
expect(body.text.scan('Licensed to the Software Freedom Conservancy').count).to eq(4)
expect(body.text.scan('Licensed to the Software Freedom Conservancy').count).to eq(5)
end
end
end
Expand Down

0 comments on commit c498dad

Please sign in to comment.