Update environment variable in Postman - api

I'm using Newman and Postman to test a website.
My Newman command construction looks like:
newman run
"https://api.getpostman.com/collections/{collection_id}?apikey={my_postman_api_key}"
--environment "https://api.getpostman.com/environments/{environment_id}?apikey={my_postman_api_key}"
--export-environment "https://api.getpostman.com/environments/{environment_id}?apikey={my_postman_api_key}"
--insecure
This all works fine but my environment values don't update after the Newman run.
In my request, I use a Pre-request Script to update the value:
var mail = pm.environment.get("mail_randomizer");
pm.environment.set("mail_randomizer", Number(mail) + 1);
After sending this request in Postman, the value for the mail_randomizer variable has gone up by 1 but after running the request using Newman, it doesn't work.
How can I export the environment correctly in Newman?

create
.env : environment variable let's say
url = http://localhost:3000/api
.env.example should be
url =
in your test call :
var local-url = process.env.url;
add in your package json
npm install dotenv

Related

VITE_ENDPOINT_BASE_URL is no longer working

In our the Javascript file, we were using
export const endpoint_base_url = import.meta.env.VITE_ENDPOINT_BASE_URL;
to read in a URL for our API calls. In our .env.development file we have the value that we needed and all was working properly until we did an NPM update and now this no longer works.
The code is now returning 'undefined'.

Set env variables in Cypress using Vite

I'm using VueJs 3 with Vite and Cypress.
In my app I have an environment variable to define my URL:
const url = import.meta.env.VITE_URL
My goal is to replace this VITE_URL in Cypress. I've tried to create a cypress.env.json file in which I wrote:
{
"VITE_URL": "https://...",
}
but it's not working. I've also tried with CYPRESS_URL or CYPRESS_VITE_URL, but I get the same result. Any idea?
Ok, I solved it. I created a .env.testing file that I use by specifying --mode testing in the npm command that launches cypress.
This env.testing has the properties defined like:
'VITE_URL="http://..."'
If you've declared the value in a cypress.env.json file, you can reference it in code with `Cypress.env('varName');
Cypress.env('VITE_URL');

How do I override just the URL for my test at the command line? [duplicate]

This question already has answers here:
Pass additional parameters to karate-config.js via command line via Maven
(3 answers)
Closed 1 year ago.
in my karate-config.js, I have set up a default url for an endpoint I use in my tests:
var config = {
env: env,
pricingApiUrl: 'http://localhost:8080'
}
and in my tests that need this endpoint, I assign 'url' to that endpoint * url pricingApiUrl
I know about setting up different environments in the karate-config.js file, but in certain situations I don't know the exact url for the 'pricingApiUrl' until runtime.
So I wanted know if it's possible to set the 'pricingApiUrl' via a commandline flag when I run the tests at the command line.
Here's one way I found to do it:
1.) in your karate-config.js add the following so that your tests default to using 'http://localhost:8080' (or whatever the default url is for you) or using the value from karate.properties if it exists:
var config = {
env: env,
pricingApiUrl: karate.properties['platform.pricing.api.url'] || 'http://localhost:8080'
}
2.) then, run your tests at the command line passing a value for the karate.properties you have defined (karate.properties['platform.pricing.api.url'] in my case):
mvn clean test -Dplatform.pricing.api.url=https://your_heroku_app.herokuapp.com
the 'platform.pricing.api.url' is just an arbitrary descriptive name. You could use a different one.
the url https://your_heroku_app.herokuapp.com is just an example -- put the base url of the api your tests are running against
There's no direct way. Maybe you can contribute code :)
You can check for a system-property and conditionally do stuff. For example:
var config = {
env: env,
pricingApiUrl: karate.properties['from.cli'] || 'http://localhost:8080'
}
Other ideas: https://stackoverflow.com/a/52821230/143475

Environment variables for production on Gitlab

I need to set my website on gitlab pages .
Vue cli says me that I need to set a env variable
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/' + process.env.VUE_APP_CI_PROJECT_NAME + '/'
: '/'
}
so I've made a .env file on root and I write it :
VUE_APP_CI_PROJECT_NAME = my_website
But when I console log it , it is undefined
my gitlab url is https://gitlab.com/my_name/company/my_website
so what am I need to write in my variable.
When you push your app to production, you need to set the env variables on Gitlab and not in your .env which should be .gitignore'ed anyway.
The .env is essentially used for development purposes, and should not be committed.
To input some env variables on Gitlab, you can go to your https://gitlab.com/your-group/your-project/-/settings/ci_cd and find it there.
You can set KEY to VUE_APP_CI_PROJECT_NAME and Value to my_website.
Deploy again and it should work fine!

Run Same Testcafe tests with different URLs per environment

I am working on a TestCafe proof of concept. I have a few tests working in one test environment. I need a way to run the same tests in up to 3 different test environments that have different URLs. Is there a best practice for this scenario?
A solution is to add custom options on the testcafe command-line like for example : --env=uat.
Use minimist to read all custom options that you have added to the TestCafe command-line and export a config object like this:
import * as minimist from 'minimist';
const args = minimist(process.argv.slice(2));
// get the options --env=xxx --user=yyy from the command line
export const config = {
env: args.env,
user: args.user,
};
Then import that config object wherever you need it in the test code.
see How do I work with configuration files and environment variables? for more details.
In v1.20.0 and later, TestCafe offers a way to specify the baseUrl in the test run setup:
CLI
Program API runner.run({baseUrl})
Config file
You can use this approach along with environment variables or custom command line arguments to determine what url should be assigned to the baseUrl option.
Alternatively, you can have a different configuration file for each test run setup and switch between these files using the --config-file option.