Multiple Scripts folders and Network Share

Multiple Scripts folders

question How can we support multiple Scripts folders?
answer To keep scripts at multiple locations, the following is important.
  1. There should be NO hardcoded absolute paths in your scripts at all. Always use relative paths.
  2. Also don't use _userDataDir().
When running the tests, it is possible to specify what the top level scripts folder is. If the scripts always use relative paths, then they will always work, regardless of where they are kept.

This is how you can specify this top level scripts folder.

Controller
  1. Take a backup of userdata/config/userdata.properties.
  2. Edit userdata.properties. Edit the following line
    scripts.dir=scripts;
    and add any path that you want to set as the scripts folder. Let us say, we add D:/temp/scripts.
    scripts.dir=scripts;D:/temp/scripts;
  3. Restart Sahi server.
  4. Now if you go to the Controller Playback tab, you will see D:/temp/scripts in the Script Directory: dropdown. You can choose this folder and run your script and it will work relative to D:/temp/scripts.
Using testrunner.bat
  1. The same thing can be done from testrunner.bat as well.
  2. Take a backup of userdata/bin/testrunner.bat.
  3. Edit testrunner.bat. Replace this line
    SET SCRIPTS_PATH=scripts
    with
    SET SCRIPTS_PATH=D:/temp/scripts
  4. Now when you run testrunner.bat, the suite/script will run relative to D:/temp/scripts.
Using drun.bat
  1. The same thing can be done from drun.bat as well.
  2. Take a backup of userdata/bin/drun.bat.
  3. Edit drun.bat. Replace this line
    SET ORIG_SCRIPTS_PATH=../scripts/
    with
    SET ORIG_SCRIPTS_PATH=D:/temp/scripts
  4. Now when you run drun.bat, the suite/script will run relative to D:/temp/scripts.
Thus by changing the top level scripts folder, you can work with the same set of files as long as they refer to each other through relative paths.

Scripts on a network share

question
  • Scripts need to be kept at a central location, so that they can be run off the central location from any machine.
  • At the same time, we need to have the ability to run scripts locally, since we may change scripts on individual machines to test specific things.
How can we have support for both?
answer Refer to the FAQ above for how to support multiple script locations.

Do the following steps to run scripts from a central location.
  1. Put all central scripts in a central location. Let us say you copied the "scripts" folder into another folder called "shared" on the central machine.
  2. Share the "shared" folder.
  3. On every machine that runs the tests, use Map Network Drive to map the "shared" folder as a drive. Let us say this is mapped as Z: on a machine. So now the central scripts can be accessed as Z:/scripts.
  4. In the FAQ above, replace "D:/temp/scripts" with "Z:/scripts".
You will now be able to run scripts off the central location("Z:/scripts"), from a Controller, testrunner.bat or drun.bat.