Skip to content

Commit 1221ea5

Browse files
DylanLaceyjarib
authored andcommitted
Throw a real error when uploading non-file things in Ruby.
Signed-off-by: Jari Bakken <jari.bakken@gmail.com>
1 parent 5c7daeb commit 1221ea5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

rb/lib/selenium/webdriver/remote/bridge.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def sendKeysToElement(element, keys)
413413

414414
def upload(local_file)
415415
unless File.file?(local_file)
416-
raise WebDriverError::Error, "you may only upload files: #{local_file.inspect}"
416+
raise Error::WebDriverError, "you may only upload files: #{local_file.inspect}"
417417
end
418418

419419
execute :uploadFile, {}, :file => Zipper.zip_file(local_file)

rb/spec/unit/selenium/webdriver/remote/bridge_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ module Remote
88
it "raises ArgumentError if passed invalid options" do
99
lambda { Bridge.new(:foo => 'bar') }.should raise_error(ArgumentError)
1010
end
11+
12+
it "raises WebDriverError if uploading non-files" do
13+
request_body = {:sessionId => '11123', :value => {}}.to_json
14+
headers = {'Content-Type' => 'application/json'}
15+
stub_request(:post, "http://127.0.0.1:4444/wd/hub/session").to_return(
16+
:status => 200, :body => request_body, :headers => headers)
17+
18+
bridge = Bridge.new
19+
lambda { bridge.upload("NotAFile")}.should raise_error(Error::WebDriverError)
20+
end
1121
end
1222

1323
end # Remote

0 commit comments

Comments
 (0)