Javascript 如何在TestCafe的装置之间使用窗口变量?
我有一个装置,“Page1”,我使用一个随机词生成器来创建一个命名的输入框。我需要在另一个装置“Page2”上使用此变量。我怎样才能做到这一点?我们无法使用window for testcafe,所有导出结果的努力都会导致Javascript 如何在TestCafe的装置之间使用窗口变量?,javascript,automated-tests,e2e-testing,web-testing,testcafe,Javascript,Automated Tests,E2e Testing,Web Testing,Testcafe,我有一个装置,“Page1”,我使用一个随机词生成器来创建一个命名的输入框。我需要在另一个装置“Page2”上使用此变量。我怎样才能做到这一点?我们无法使用window for testcafe,所有导出结果的努力都会导致ReferenceError:fixture未定义错误 在第1页,我有这样的代码: const words = require('random-words'); export let inputName; fixture('Page1'); test('Create P
ReferenceError:fixture未定义错误
在第1页,我有这样的代码:
const words = require('random-words');
export let inputName;
fixture('Page1');
test('Create Page1', async (t) => {
await loginPage.login();
inputName = `input ${words()}`;
在第2页
import {inputName} from './page1';
如果我拿出导入语句,一切都会正常 您可以将变量存储在单独的文件中,例如:
fixture1.js
import getInputName from./get input name';
固定装置(“第1页”);
测试('createpage1',异步t=>{
等待t.typeText('input',getInputName());
});
fixture2.js
import getInputName from./get input name';
固定装置(“第2页”);
测试('createpage2',异步t=>{
等待t.typeText('input',getInputName());
});
get-input-name.js
const words=require('random-words');
让inputName=null;
导出默认函数getInputName(){
如果(!inputName)
inputName=`input${words()}`
返回inputName;
}
要获得有关在TestCafe中使用帮助程序的更多信息,请查看