Node.js 在TestCafe中设置环境变量,给出未定义的值
我正在学习TestCafe,对它我是新手 正如这里所提到的,我正试图遵循: 我有一个在我的windows机器上运行的代码Node.js 在TestCafe中设置环境变量,给出未定义的值,node.js,typescript,npm,testcafe,ui-testing,Node.js,Typescript,Npm,Testcafe,Ui Testing,我正在学习TestCafe,对它我是新手 正如这里所提到的,我正试图遵循: 我有一个在我的windows机器上运行的代码 fixture`Getting Started`.page`http://devexpress.github.io/testcafe/example`; test("My First Test", async t => { await t .typeText('#developer-name', 'John Smith')
fixture`Getting Started`.page`http://devexpress.github.io/testcafe/example`;
test("My First Test", async t => {
await t
.typeText('#developer-name', 'John Smith')
.click('#submit-button')
.takeScreenshot();
const articleHeader = await Selector('.result-content').find('h1');
// Obtain the text of the article header
let headerText = await articleHeader.innerText;
console.log(process.env.DEV_MODE);
});
我的脚本部分是这样的
"scripts": {
"setnode": "set DEV_MODE=staging",
"test:chrome": "npm run setnode & npx testcafe \"chrome --start-fullscreen\" e2e/tests"
}
ui-testcafe-poc@1.0.0 setnode C:\TestCafeProjects\ui-testcafe-poc set DEV_MODE=staging
Running tests in:
- Chrome 79.0.3945.130 / Windows 10
Getting Started
undefined
√ My First Test
运行此命令时npm运行测试:chrome
我得到这样的输出
"scripts": {
"setnode": "set DEV_MODE=staging",
"test:chrome": "npm run setnode & npx testcafe \"chrome --start-fullscreen\" e2e/tests"
}
ui-testcafe-poc@1.0.0 setnode C:\TestCafeProjects\ui-testcafe-poc set DEV_MODE=staging
Running tests in:
- Chrome 79.0.3945.130 / Windows 10
Getting Started
undefined
√ My First Test
为什么console.log被写为未定义而不是暂存?脚本中的符号(&
)并行运行它们。但是,您需要使用&&
操作数按顺序运行它们
此外,npm脚本在后台生成shell进程(Windows上的cmd),并且set
命令设置的变量仅在其自己的会话中存在。以下脚本应该可以工作:
"scripts": {
"test:chrome": "set DEV_MODE=staging && npx testcafe \"chrome --start-fullscreen\" e2e/tests"
}