1

I want to upload a file from remote url in ruby using selenium

My tools:-

watir-webdriver
selenium-webdriver

Upload a file:-

browser.file_field(:id, 'file').set("https://www.google.co.in/logos/doodles/2015/holi-festival-2015-5124794139803648-hp.gif")

Error:-

Errno::ENOENT: No such file or directory - https://www.google.co.in/logos/doodles/2015/holi-festival-2015-5124794139803648-hp.gif

1 Answer 1

3

The value of an upload input field should be an absolute path to the file on your local machine, not a URL. Download the image first.

Sign up to request clarification or add additional context in comments.

6 Comments

Is there anyway to upload a file directly from remote url.
@karan well, could you please explain why don't you want to download the file and use it's local location to set the input value? You can download the file just before setting the input field value in the same script..
I strongly advise against using remote file in your tests. Test should be able to run in any circumstances, thus you should not rely on any thing you don't contain (like API calls, eg. to twitter, or mentioned files). This is just mean as a bad pattern on which many failed. In your situation I would recommend as @alecxe suggested. You may download the file and put it in fixtures directory, and make your tests more reliable.
@alecxe Thanks i will download file from remote and use it.
@alecxe How to read image file from remote. Will this work. where i have to mention source and destination path. require 'open-uri' open('image.png', 'wb') do |file| file << open('example.com/image.png').read end
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.