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

Galet
  • 5,853
  • 21
  • 82
  • 148

1 Answers1

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.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Is there anyway to upload a file directly from remote url. – Galet Mar 06 '15 at 06:43
  • @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.. – alecxe Mar 06 '15 at 06:46
  • 1
    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. – Paweł Dawczak Mar 06 '15 at 07:07
  • @alecxe Thanks i will download file from remote and use it. – Galet Mar 06 '15 at 07:10
  • 1
    @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('http://example.com/image.png').read end – Galet Mar 06 '15 at 07:25
  • @karan should work, though make sure you'll make an absolute path to `image.png` after. See http://stackoverflow.com/questions/1937743/how-to-get-the-current-working-directorys-absolute-path-from-irb. – alecxe Mar 06 '15 at 08:09