Hey guys! I’m trying to run the following code in the ‘Pre-request Script’ tab. But I’m getting the error: SyntaxError: Cannot use import statement outside a module
I have imported and the only tip I have is:
Hey guys! I’m trying to run the following code in the ‘Pre-request Script’ tab. But I’m getting the error: SyntaxError: Cannot use import statement outside a module
I have imported and the only tip I have is:
Hey @tsouza,
Welcome to the Postman community!
I hope I’m understanding this correctly - To get those different dates you can simply use the new Date() object and its different functions.
You can just use this syntax in the Scripting sandbox like this:
let date = new Date(),
ano = date.getFullYear(),
dia = date.getDay(),
mes = date.getMonth();
let str = `${ano}-${dia}-${mes}`
pm.environment.set("unique", str)
This is just a cut down version of what was in your question but hopefully, you get the idea.
Got it! I works!
Thank you so much!
to fill in an attribute with this information, just put the name of the parameter in the attribute: {{unique}}
Is it possible to get the hour, minutes, and seconds?
If you head to the page I linked and look at the Date Object Methods
section, all the functions can be found there.
I kept my example short because I honestly didn’t want to completely replicate the code you had in the question…lazy
If you just replace the import
statement with let date = new Date(),
and then change Datetime.
to date.
your code it should work.
It did look like you had an extra 4
in the last variable though.
I have tried for a websocket creation in API tests using an external library. ws
Is there a possibility to create an websocket connection from API Tests?
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.