Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda