I have pre request script in my postman test. When i am running manually via postman GUI, there is no issue and it is reading the pre request script but when i tried to run through CLI using API key, it seems that it is not reading the pre request script and all my test which have pre request script is getting failed.
Any config required to read pre request during running from CLI?
Hey @ameneh1986
Welcome to the Postman Community
Could you provide more context about the script and what the script is actually doing, please?
Hey @danny-dainton
Below is details in my pre request:
// Generate a current timestamp in ISO format
var currentDate = new Date();
// Generate a random number of days (1 -30)
var randomDays = Math.floor(Math.random() * 30) + 1;
// Add the random no of days to the current date and update date and save in env:
currentDate.setDate(currentDate.getDate() + randomDays);
var randomIsoTimestamp = currentDate.toISOString();
pm.environment.set("randomIsoTimestamp", randomIsoTimestamp);
Whatโs the Postman CLI command thatโs being used and the version of the CLI that youโre using?
Hi @danny-dainton
Not sure it is the thing that you are looking oe not:
Postman CLI command preview
stages:
- automated-api-tests
automated-api-tests:
stage: automated-api-tests
image: cimg/base: 2021.04 before_script:
Installing Postman CLI
- curl -o- โhttps://dl-cli.pstmn.io/install/linux64.shโ | sh script:
Login using your Postman API keys
- postman login --with-api-key $POSTMAN_API_KEY
- postman collection run โ28067525-e1f57cd4-e870-489d-9460-4d56a855f60dโ - e
โ28067525-b81a2f68-852b-4d14-890e-5c73436cba39โ
Dear @danny-dainton
I also tried with latest image and still it is failing
automated-api-tests:
stage: post-development-tests
image: cimg/base:2024.09
before_script:
- curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh
script:
- postman login --with-api-key $POSTMAN_API_KEY
- postman collection run 28067525-e1f57cd4-e870-489d-9460-4d56a855f60d -e 28067525-b81a2f68-852b-4d14-890e-5c73436cba39
artifacts:
paths:
- automated-api-tests-status.txt
only:
- develop
tags:
- aks-test01
allow_failure: true
when: delayed
start_in: 5 minutes
Taking a look at this now and Iโve raised this with the team - I will update the thread if I have anymore information.
Hey @ameneh1986
Were not able to reproduce this on our side using your script.
As you can see itโs resolved the variable from the pre-request scripts that that executed during the run.