read local xml/json files to set env-variables #64
Mahmoud-Elsaqqa
started this conversation in
Ideas
Replies: 1 comment
|
Hello, Currently, there is no built-in function for reading files, but since the script runs on GraalVM JS, you can use Java classes. To read a file, you can write something like this: const Files = Java.type('java.nio.file.Files');
const Paths = Java.type('java.nio.file.Paths');
const path = Paths.get("path_to_your_file.txt");
try {
console.log(Files.readString(path));
} catch (e) {
console.error("Error reading file: " + e.message);
}This method is not very convenient, so I'm planning to implement an "Embedded Expressions" feature. This will allow you to write JavaScript expressions using variables along with predefined or user-defined functions. Among the predefined functions, there will definitely be a With this feature, resolving the variable will execute the expression and return its result, such as the content of a file in the example. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello Anton,
I'm a big fan of your plugin really,
I encountered a case where I'm trying to send a POST request to a mockserver with multiple response expectation, so it would be very useful to have a chance to read a local json/xml file and set it as the value of env-variable in pre-request script, to dynamically change json expectations.
This also will have many more benefits.
I don't know if there is currently a way that I can achieve this or not, anyway, let me know what you think about this.
All reactions