我正在学习TestCafe,并且是我的新手。
我正在尝试遵循此处提到的内容:https://devexpress.github.io/testcafe/documentation/recipes/access-environment-variables-in-tests.html
我有在Windows机器上运行的代码!
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"
}
当我运行此命令npm run test:chrome
我正在得到这样的输出
[email protected] setnode C:\TestCafeProjects\dynatrace-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脚本在后台(在Windows上为cmd)生成shell进程,并且set
命令设置的变量仅存在于其自己的会话中。以下脚本应该起作用:
"scripts": {
"test:chrome": "set DEV_MODE=staging && npx testcafe \"chrome --start-fullscreen\" e2e/tests"
}