我无法在我的.env测试中从playwright文件中获得url值,在运行测试时,它正在抛出未定义的错误baseURL,有人能就此问题提出建议吗?TypeError:无法读取未定义的属性“baseURL”
10 | test('Access the Playwright Page', async ({ page }) => {
11 | const playwrightDev = new PlaywrightDevPage(page);
> 12 | await playwrightDev.goto(Config.baseURL);
| ^下面是我的.env文件。
URL=https://playwright.dev/下面是我的playwright.config.js文件和设置
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;下面是我的example.spec.js文件
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);
});发布于 2022-02-25 21:48:22
您需要通过:dotenv在配置中加载require('dotenv').config()
然后,您可以在测试中使用"dotenv文件“的env vars,例如:process.env.FOOBAR
有关dotenv的用法,请参阅此处:https://www.npmjs.com/package/dotenv
https://stackoverflow.com/questions/71260266
复制相似问题