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

367
Visualizações
Trying to read value from .env file throws undefined error in playwright

I am unable to get the url value from the .env file in my playwright test, while running the test, it is throwing error baseURL of undefined,could someone please advise on the issue ? TypeError: Cannot read property 'baseURL' of undefined

  10 | test('Access the Playwright Page', async ({ page }) => {
  11 |   const playwrightDev = new PlaywrightDevPage(page);
> 12 |   await playwrightDev.goto(Config.baseURL);
     |                                   ^

Following is my .env file.

URL=https://playwright.dev/

Below is my playwright.config.js file and settings

const { devices } = require('@playwright/test');

/** @type {import('@playwright/test').PlaywrightTestConfig} */

const config = {
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  use: {
    trace: 'on-first-retry',
    baseURL: process.env.URL,
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
};

module.exports = config;

Below is my example.spec.js file

const { test, expect } = require('@playwright/test');
const { PlaywrightDevPage } = require('./playwright-dev-page');
const { Config } = require('../playwright.config');

test('Access the Playwright Page', async ({ page }) => {
  const playwrightDev = new PlaywrightDevPage(page);
  await playwrightDev.goto(Config.baseURl);
 
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to load dotenv inside your config via: require('dotenv').config()

Then you can inside your tests use the env vars of your "dotenv files" via e.g.: process.env.FOOBAR

See here for dotenv usage: https://www.npmjs.com/package/dotenv

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