02 January 2013

Automating File Upload prompts

I really love using Watir with Cucumber.  It has some great built in methods.

There's this awesome method in Watir called file_field.  It basically references any input of type = "file" and follows the prompts to push the file you give through the submit process.

Here's an example of how I'm doing it:

  @browser.span(:text=>"Upload New").click
  @browser.file_field(:class=>"UploadSoundfile").set("C:\\Users\\Public\\Music\\Sample Music\\Kalimba.mp3")
  sleep(2)
  @browser.div(:text=>"Submit").click
  sleep(2)

For windows to work, I did have to escape the \ with double \\.

But it works like  a charm!

No comments:

Post a Comment