Skip to content

Commit 709611e

Browse files
committed
[rb] use tempfiles for testing uploads
1 parent 6b40037 commit 709611e

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module Selenium
2323
module WebDriver
2424
module Remote
2525
describe Driver, exclusive: [{bidi: false, reason: 'Not yet implemented with BiDi'}, {driver: :remote}] do
26+
let(:tempfile) { create_tempfile }
27+
2628
it 'exposes session_id' do
2729
expect(driver.session_id).to be_a(String)
2830
end
@@ -35,15 +37,15 @@ module Remote
3537
flaky: {browser: :safari, ci: :github, reason: 'unreliable with downloads'} do
3638
driver.navigate.to url_for('upload.html')
3739

38-
driver.find_element(id: 'upload').send_keys(__FILE__)
40+
driver.find_element(id: 'upload').send_keys(tempfile.path)
3941
driver.find_element(id: 'go').submit
4042
wait.until { driver.find_element(id: 'upload_label').displayed? }
4143

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

4547
body = driver.find_element(xpath: '//body')
46-
expect(body.text.scan('Licensed to the Software Freedom Conservancy').count).to eq(2)
48+
expect(body.text.scan('This is a dummy test file').count).to eq(1)
4749
end
4850

4951
it 'lists downloads', exclude: {browser: :safari, reason: 'grid hangs'} do

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Selenium
2323
module WebDriver
2424
describe Element, exclusive: {bidi: false, reason: 'Not yet implemented with BiDi'} do
2525
before do
26-
driver.file_detector = ->(filename) { File.join(__dir__, filename) }
26+
driver.file_detector = lambda(&:first)
2727
end
2828

2929
after { driver.file_detector = nil }
@@ -35,15 +35,15 @@ module WebDriver
3535
reason: 'unreliable with downloads'} do
3636
driver.navigate.to url_for('upload.html')
3737

38-
driver.find_element(id: 'upload').send_keys('element_spec.rb')
38+
driver.find_element(id: 'upload').send_keys(create_tempfile.path)
3939
driver.find_element(id: 'go').click
4040
wait.until { driver.find_element(id: 'upload_label').displayed? }
4141

4242
driver.switch_to.frame('upload_target')
4343
wait.until { !driver.find_element(xpath: '//body').text.empty? }
4444

4545
body = driver.find_element(xpath: '//body')
46-
expect(body.text.scan('Licensed to the Software Freedom Conservancy').count).to eq(3)
46+
expect(body.text.scan('This is a dummy test file').count).to eq(1)
4747
end
4848
end
4949

@@ -53,16 +53,18 @@ module WebDriver
5353
ci: :github,
5454
reason: 'unreliable with downloads'} do
5555
driver.navigate.to url_for('upload_multiple.html')
56+
file1 = create_tempfile
57+
file2 = create_tempfile
5658

57-
driver.find_element(id: 'upload').send_keys("driver_spec.rb\nelement_spec.rb")
59+
driver.find_element(id: 'upload').send_keys("#{file1.path}\n#{file2.path}")
5860
driver.find_element(id: 'go').click
5961
wait.until { driver.find_element(id: 'upload_label').displayed? }
6062

6163
driver.switch_to.frame('upload_target')
6264
wait.until { !driver.find_element(xpath: '//body').text.empty? }
6365

6466
body = driver.find_element(xpath: '//body')
65-
expect(body.text.scan('Licensed to the Software Freedom Conservancy').count).to eq(5)
67+
expect(body.text.scan('This is a dummy test file').count).to eq(2)
6668
end
6769
end
6870
end

rb/spec/integration/selenium/webdriver/spec_support/helpers.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ def png_size(path)
113113

114114
[width, height]
115115
end
116+
117+
def create_tempfile
118+
Tempfile.new.tap do |file|
119+
file.write('This is a dummy test file')
120+
file.close
121+
end
122+
end
116123
end # Helpers
117124
end # SpecSupport
118125
end # WebDriver

0 commit comments

Comments
 (0)