Search code examples
robotframework

File Should Exist is not recognizing filepath


I'm using the File Should Exist keyword to check for an existing file in a List. This is the high-level format:

Variables:
@{Files}    /Desktop/Other/scooby.txt
...         /Desktop/DummyFiles/daffy.txt
...         %{CURDIR}/mickey.txt

Test Case:
Given File Should Exist ${Files[0]} 
[...]

Output:
Setup failed:
Path '/Desktop/Other/scooby.txt' does not exist.

I'm not sure why this happens. The file name and filepath are correct. I also tried a bunch of different combinations (I copied the file over to the subdirectory this script is running from but that also doesn't work). I tried making the filepath a scalar variable instead of a List/array. Adding ".." in front of the file path doesn't work either. I've looked into "Glob pattern" but I don't think that's the issue either.


Solution

  • Always use absolute paths if in doubt. For example - /Desktop/Other/scooby.txt Does not point to any "meaningful" path even on windows because its lacking the the drive. On windows, using C:/Users/$yourlocalusername/Desktop/Other/scooby.txt might be working (replace $yourlocalusername with correct value)

    Relying on relative paths (like in your example, 2 first ones are relative even thought you start with /, because in windows you still have a drive at the start) - you will need to ensure that working directory is set to a specific directory before you run your suite. Now, if you run your suite via IDE, current working directory might not be what you expect it to be so before you are familiar with how relative & absolute paths work - prefer to use absolute paths. See https://www.computerhope.com/issues/ch001708.htm - maybe that will clear out your issue.