Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在TestCafe的装置之间使用窗口变量?_Javascript_Automated Tests_E2e Testing_Web Testing_Testcafe - Fatal编程技术网

Javascript 如何在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

我有一个装置,“Page1”,我使用一个随机词生成器来创建一个命名的输入框。我需要在另一个装置“Page2”上使用此变量。我怎样才能做到这一点?我们无法使用window for testcafe,所有导出结果的努力都会导致
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中使用帮助程序的更多信息,请查看