0

I am using the selenium-client gem with Webrat and Cucumber to test a rails project. I have Cucumber set up pretty much as described here: https://github.com/cucumber/cucumber/wiki/Setting-up-Selenium

My problem is that Selenium is prevented from performing file uploads. Ideally I'd like to be able to replicate webrat's 'attach_file' method. I tried dodging the issue by using selenium-client's 'type' method to type the path to the required file, but this seems to fail.

Does anyone have a sugestion for a workaround using selenium-client (i.e. not the regular Selenium gem)?

RamC
  • 1,287
  • 1
  • 11
  • 15
Rodreegez
  • 576
  • 5
  • 15

2 Answers2

1

The normal selenium can't do this because browser security prevents javascript from writing to input=file elements. This is a security feature so that your password file doesnt get uploaded to hackers if you go to a site thats been hacked.

http://jira.openqa.org/browse/SEL-63 has the details

AutomatedTester
  • 22,188
  • 7
  • 49
  • 62
0

I finally figured this out.

You need to be using firefox with the chrome backend, and you need to specifiy an absolute filepath.

I ended up creating a helper module to specify the filepath, and a "fixtures" folder containing test content. Here is a gist of the solution I came up with: http://gist.github.com/214185

Therefore it is totally possible to replicate Webrat's attach_file method!

Rodreegez
  • 576
  • 5
  • 15