Javascript 如何在测试之间传递变量数据

Javascript 如何在测试之间传递变量数据,javascript,testing,automated-tests,e2e-testing,testcafe,Javascript,Testing,Automated Tests,E2e Testing,Testcafe,我正在尝试做类似的事情 我正在我的helper.js文件中生成一封随机电子邮件。我想使用此随机电子邮件登录test.js文件 这就是我在helper.js中创建电子邮件的方式 var randomemail = 'test+' + Math.floor(Math.random() * 10000) + '@gmail.com' 这就是我想在test.js文件中使用它的方式 .typeText(page.emailInput, randomemail) 我试过几件运气不好的事。如何在我的tes

我正在尝试做类似的事情

我正在我的
helper.js
文件中生成一封随机电子邮件。我想使用此随机电子邮件登录
test.js
文件

这就是我在helper.js中创建电子邮件的方式

var randomemail = 'test+' + Math.floor(Math.random() * 10000) + '@gmail.com'
这就是我想在
test.js
文件中使用它的方式

.typeText(page.emailInput, randomemail)
我试过几件运气不好的事。如何在我的
test.js
文件中使用生成的电子邮件?

两个选项:

1)使用夹具上下文对象(ctx)

2)声明夹具外部的变量

let randomEmail = '';

fixture(`RANDOM EMAIL TESTS`)
    .beforeEach(async t => {
        // Do this if you want to update the email between each test

        randomEmail = `test+${Math.floor(Math.random() * 1000)}@gmail.com`;
    })

test('Display First Email', async t => {
    console.log(randomEmail);
})

test('Display Second Email', async t => {
    console.log(randomEmail);
})

请尝试以下线程中的解决方案:。如果这没有帮助,请提供完整的测试代码。
let randomEmail = '';

fixture(`RANDOM EMAIL TESTS`)
    .beforeEach(async t => {
        // Do this if you want to update the email between each test

        randomEmail = `test+${Math.floor(Math.random() * 1000)}@gmail.com`;
    })

test('Display First Email', async t => {
    console.log(randomEmail);
})

test('Display Second Email', async t => {
    console.log(randomEmail);
})