views:

260

answers:

2

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: http://wiki.github.com/aslakhellesoy/cucumber/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)?

+1  A: 

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
A: 

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