Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
Change .page URL based on environment I need to run the suite in

We have been building our automation suite using our staging environment, but are going live soon and want to be ready to tell the project where to run (staging, production).

The only difference between the sites in the environments is the URL. My question is, from start to finish, how can I set the .page URL via a CLI option?

Right now, I have created an environment config file that holds our staging and production URLS and then I call the data into my test files. This is fine for now, but I will need to create a script with an option to set the environment at runtime without having to do a manual find and replace before kicking it off.

I've looked around online and find, what I believe, to be code snippets and general instructions, but I'm not a dev at heart and go crossed eyed. If I could get an ELI5 for this, that would be awesome.

Example of what I'm doing now:

const env = require('../environment_variables.json')


fixture `blog`
  .page `${env.production}`

And then I change production to staging or vice versa manually before kicking off the suite.

Since the project will run from CICD, I would like to be able to do something like this in my CLI and script:

testcafe env=production

The env value will then be set where the .page call is for every test file.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are different ways of doing this. I've used environment variables successfully in this situation, so I'll share this solution since it will solve your problem.

I create config.json in the root of the project:

{    
    "baseUrl": {
        "dev": "https://dev.com/",
        "staging": "https://staging.com/",
        "prod": "https://prod.com/"
    }
}

Then I create two helper functions somewhere like Helpers/env.js:

import config from '../config';

function getEnv () {
    return process.env.TESTCAFE_ENV;
}

function getBaseUrl () {
    return config.baseUrl[getEnv()];
}

export { getEnv, getBaseUrl };

Then in my test files in Tests/:

import { getBaseUrl } from '../Helpers/env';

const baseUrl = getBaseUrl();

fixture `Test Suite`
    .page(baseUrl);

And that's it. Then when I need to run tests on the dev, I execute:

$ TESTCAFE_ENV=dev testcafe

for staging:

$ TESTCAFE_ENV=staging testcafe

and for production:

$ TESTCAFE_ENV=prod testcafe
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda