Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Upload file based on relative path

yiannis
yiannis Posts: 8

I want to upload a file in my e2e tests and I did manage it by using
/home/john/Documents/doc.txt

but when I share my automation tests the path of the other tester is
/home/george/Documents/doc.txt

I tried to put as relative path
~/Documents/doc.txt
but this didn't work.

Any suggestions?

Comments

  • jakubiak
    jakubiak Posts: 813 admin

    Use a path that is in your workspace and is relative to the location of the .tst file.

  • yiannis
    yiannis Posts: 8
    edited July 2020

    I moved the file inside the workspace in a documents folder and I can see it in Navigator. Then I changed the path relative to my tst file but I got the error message

    Error Message:
    (Chrome 81.0) Unable to perform action due to an unexpected error. View details for more
    information.

    Additional Details:
    invalid argument: File not found : ../documents/myfile.txt

    If I put an absolute path, the above will work.

  • jakubiak
    jakubiak Posts: 813 admin

    Hmmm - since you are typing this into the browser and the browser doesn't understand the relative path, you have to type an absolute path. You could put the value into an environment variable, and use a different environment depending on what machine you are running on. Another option is to switch the input from "Fixed" to "Scripted" and write a simple script that uses the SOAtest API ScriptingContext.getAbsolutePathFile() that takes a relative path as argument and will resolve it relative to the directory in which the .tst file lives. See the Parasoft SOAtest Extensibility API JavaDocs for details on that API.

  • yiannis
    yiannis Posts: 8

    Done
    I worked with ScriptingContext and created a sample Javascript script to get the absolute path.
    Thanks

  • benken_parasoft
    benken_parasoft Posts: 1,306 ✭✭✭

    For future reference, this one is helpful in cases where you need to get an absolute path from a path that is relative to the folder containing the tst file:
    com.parasoft.api.ScriptingContext.getAbsolutePathFile(String filename)