Unanswered question

How to handle relative file paths in Javascript?

I'm trying to read in a series of files via javascript to populate a POST (content type: text).

If I make the path fixed and then allocate the runtime to another LG, it will fail because the directory path does not exist on the LG.

Attempting to make the path relative (i.e. variables\\blah\\file.txt) also fails because, I assume, that Neoload doesn't assume the path to the project.

I note that if I change the content type to Binary, I can link to a source path, however I am not submitting a file only text therefore I am back to reading a text file in via javascript.

Any suggestions, obvious omissions, etc?

Elliot A.
Elliot A.

Elliot A.

Level
0
14 / 100
points

Answers

Nouredine A.
Nouredine A.

Nouredine A.

Level
4
5000 / 5000
points
Team

What is your NeoLoad version?

Since NeoLoad 5.1 there's a useful variable called "NL-CustomResources". That variable can be used to point to a file that is synchronized between the controller and the LG's.

So let's say you put your file "file.txt" under the "customer-resources" folder in your project folder.

Then that "NL-CustomResources" variable will contain the absolute path on your LG to reach your "file.txt".

If you are using an older NeoLoad version, you can still use the same type of method but instead, create a "resources" folder under your project folder and put your "file.txt" inside.

That file will be automatically synchronized on all the LG's. To get the file in your JAVASCRIPT you can use that code:

var test = java.lang.System.getenv("APPDATA");

It will retrieve the user roaming folder. For example, "C:\Users\<USERNAME>\AppData\Roaming" 

You just need to append that hardcoded path "\Neotys\NeoLoad\v5.1\nlres" to get your "file.txt".

It's a little bit more complicated than 5.1 procedure but it works.

I hope that this will help you.