Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up environment variables #39

Open
ArisuRen opened this issue Jan 20, 2020 · 2 comments
Open

Setting up environment variables #39

ArisuRen opened this issue Jan 20, 2020 · 2 comments

Comments

@ArisuRen
Copy link

ArisuRen commented Jan 20, 2020

Hello,
it might be will be beneficial to add possibility to setup environment variable before running testCafe runner extension?
If you have different production environments, Tester can test it in development, on staging or live.
Please let me know if it can be added there,
thank you a lot in advance.

PS. I have found workaround so if this is not needed, please delete/close this issue. thank you

@Tall-KU-RideOn
Copy link

@ArisuRen - Could you explain your workaround that you figured out?

I have code in my files that dynamically edits teh URL of pages depending on an ENV variable. I'd like to define this using the Extension

@ArisuRen
Copy link
Author

ArisuRen commented May 5, 2022

Hello, unfortunatly this was 2 years ago, and I do not remember for 100% but I think at that time I did this workaround:
In .ts file used this code

//chooses which config to use
var config = (process.env.DEV_MODE === "true" || process.env.DEV_MODE === undefined) ? require("../config.json") : require("../config.prod.json")

and in package.json when starting script I had this

    "test": "set DEV_MODE=true&& node ./testcafe.config.js",
    "test_prod": "set DEV_MODE=false&& node ./testcafe.config.js",

Right now I do it a little bit differently since I have more then 2 env versions:

//chooses which config to use
let env = process.env.ENV;
let config;
switch (env) {
    case "STAG": {
        config = require('../config/config.stag.json');
        break;
    }
    case "PROD": {
        config = require("../src/config/config.prod.json");
        break;
    }
    case "UAT": {
        config = require("../src/config/config.uat.json");
        break;
    }
    case "AWS": {
        config = require("../src/config/config.aws.json");
        break;
    }
    default: {
        console.log('config file not defined');
    }
}

and package.json

    "test-stag": "export ENV=STAG && npx codeceptjs run --steps",
    "test-uat": "export ENV=UAT && npx codeceptjs run --steps",
    "test-prod": "export ENV=PROD && npx codeceptjs run --steps",
    "test-aws": "export ENV=AWS && npx codeceptjs run --steps",

I hope my answer will help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants