.

watir file upload tutorial

The problem when trying to run the following Ruby test script under Watir:
(It should simply open a webpage and select a file for upload)

require 'watir'
require 'test/unit'
require 'watir/windowhelper'

b = Watir::Browser.new
b.goto("http://localhost:65519/data/UploadHIVData.aspx")
b.file_field(:name, "ctl00$MainContent$FileUpload1").set("c:\\test\\here.txt")
assert_equal "c:\\test\\here.txt", b.file_field(:name,"ctl00$MainContent$FileUpload1").value
exit

But it fails with the following error:

>ruby GRASP_Upload_File.rb
C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.6/lib/watir/windowhelper.rb:44:in `check_autoit_installed’: The AutoIt dll must be correctly registered for this feature to work properly (Watir::Exception::WatirException)
from C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.6/lib/watir/input_elements.rb:492:in `set’
from GRASP_Upload_File.rb:16
>Exit code: 1

Here is my Solution (tested and working):

gem update
gem install autoit

rem – goto your installation folder e.g.
cd C:\Program Files\Ruby\lib\ruby\gems\1.8\gems\watir-1.6.6\lib\watir

regsvr32 AutoItX3.dll

Then I receive the following confirmation message:

DllRegisterServer in AutoItX3.dll succeeded.

clicked ok and it all works after that.

What's your thoughts on this?

*

Protected by WP Anti Spam