3

I am using selenium IDE to make automated test cases for my webapp.

scenario - to test file upload.

Directory structure :-

myapp/ 
      testsuite/
                Resources (contains csv upload file)
                folder for testsuit(contains testsuit and relevent testcase files)                         

Issue - currently i am making test suits on my local machine, so the path of file to be uploaded is local to my system. now if any other team member runs test suit on his system/server then the path of upload file need to be changed. but this is a bad practice to change the path for each system. so, i am trying to make path of the upload file relative to location of my tests suit file.

<tr>
<td>type</td>
<td>id=QuestionUpload_file</td>
<td>/home/sbl4/public_html/atumbarium/testsuite/resources/question_upload.csv</td>
</tr>

I tried the approach specified in following post:- Can you specify a 'relative' path for the data file using Sel-Blocks Selenium add-on?

Community
  • 1
  • 1
rahul
  • 366
  • 1
  • 5
  • 21
  • What language, Java? Ruby script? The quick answer is to make the file location a property in a property,file. – MikeJRamsey56 Mar 24 '16 at 01:40
  • If Java, look [here](http://stackoverflow.com/questions/17540942/how-to-get-the-path-of-running-java-program). For Ruby, look [here](https://www.ruby-forum.com/topic/143383). – MikeJRamsey56 Mar 25 '16 at 23:04

1 Answers1

3

Plugin-free solution:

<tr>
    <td>storeEval</td>
    <td>Preferences.getString(TestSuite.TEST_SUITE_DIRECTORY_PREF);</td>
    <td>testSuiteFolder</td>
</tr>
<tr>
    <td>type</td>
    <td>id=QuestionUpload_file</td>
    <td>${testSuiteFolder}/resources/question_upload.csv</td>
</tr>

No config necessary.

Lee Kowalkowski
  • 11,591
  • 3
  • 40
  • 46
  • `TestSuite.TEST_SUITE_DIRECTORY_PREF` is the folder to show when the user does `File > Open Test Suite...` from the menu in Selenium IDE. So you must open your Test Suite using `File > Open Test Suite...` and not `File > Open...` for this to work. – Lee Kowalkowski Jul 14 '16 at 23:18
  • This approach works great on my Ubuntu desktop, but when a colleague runs the regression test on OSX, Preferences.getString(TestSuite.TEST_SUITE_DIRECTORY_PREF) returns an empty string . . Any idea why this might be? – Simon Woolf Mar 02 '17 at 15:36
  • @SimonWoolf is your colleague definitely opening the test suite using `File > Open Test Suite...`? If you use `File > Open...` it will open test suites just fine, however, it will not set the `TestSuite.TEST_SUITE_DIRECTORY_PREF`, but `Format.TEST_CASE_DIRECTORY_PREF`, instead. – Lee Kowalkowski Mar 15 '17 at 00:47