Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

For example, consider the following script:


   require 'rubygems' 
   require 'watir-webdriver' 

   browser = Watir::Browser.new(:firefox)
   browser.goto("http://tinypic.com/") 

   file = "C:\\\\assets\\image.jpg"
   browser.file_field(:name,"the_file").set(file)  
   browser.close

Which will work, I will be able to add the file into the file_field but I always have to have image.jpg in C:\assets and I don't want this to always be enforced. I'd like to search the underlying OS and find the path for the file I want to use and I'd like the script to be able to run on Windows and *nix systems. Relying on hard-coding the file's location as a string is somewhat limiting.

It should help to know that the files I wish to use will be under source control and will always be in a specific location in relation to the test script - the directory will always be something like ../../assets

share|improve this question
1  
This might be good on Stack Overflow, since it's essentially a coding question. –  Ethel Evans May 25 '11 at 22:57
    
Yeah, fair point. Stackoverflow is where I used to submit these types of questions. Although this site is intended to include browser automation questions so I'd hope that an answer would also be possible to find here. :) –  sean_robbins May 25 '11 at 23:57
    
I like it here, too. There is some overlap between SE sites. I just wasn't seeing many answers at that time :) –  Ethel Evans May 27 '11 at 17:23
1  
I'd prefer this kind of question be placed on SO. There's more of the watir people monitoring that site, and also better assistance for aspects of these questions that end up dealing with things like Ruby, JQuery, etc –  Chuck van der Linden May 30 '11 at 1:01
1  
There are more Watir people monitoring SO at the moment, but seeing as how Selenium was merged into SQA, it only makes sense that Watir questions should also be here. There is overlap, for sure. In fact, EVERY question on SQA could be on SO or Programmers instead - the idea is to bring them together to bring the philosophy of testing from Programmers to the technical aspects from SO under one roof. They're called growing pains for a reason :-) –  corsiKa May 30 '11 at 3:19
add comment

2 Answers

up vote 2 down vote accepted

create a path provider where you test data is located. in a file create a method that returns expanded path

def datapath filename
  File.expand_path(File.join(File.dirname(__FILE__), filename))
end

use it in your test

browser.file_field(:name,"the_file").set(datapath(filename))
share|improve this answer
add comment

One approach that my work is to extract paths like this to a config file of some point that could be set depending on where you run the script from. Then you can read the value out of the config at start up. Another approach I have taken in C# is to have a directory that is part of my project that gets built out with the project so if I have dependencies they are build out as part of the project so they are always in a path relative with the binary.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.