【发布时间】:2018-12-19 12:59:11
【问题描述】:
我有helper.js,它的功能是
async function getLink() {
try {
const message = await authorize(content);
const link = message.match(/href=\"(.*?)\"/i);
return link[1];
}
catch(error) {
console.log('Error loading:',+error);
throw(error);
}
}
module.exports.getLink = getLink;
我想在测试执行后在 testcafe 脚本中使用这个函数
在 test.spec.js 中
import { Selector } from 'testcafe';
let link = '';
fixture My fixture
.page `https://devexpress.github.io/testcafe/example/`;
test('test1', async t => {
// do something with clientWidth
});
test('test2', async t => {
// use the getLink function here from the helper.js to get the string value
mailer.getLink().then(res=>{
link = res;
})
t.navigateTo(link)
});
如何解决这个问题?
我尝试使用 clientFunction 但得到错误_ref is not defined 代码如下
const validationLink = ClientFunction(() => {
return getLink();
}, { dependencies: { getLink } });
let link = await validationLink();
【问题讨论】:
-
用
mailer.getLink().then(res=>{link = res;})代替link = await mailer.getLink(); -
等待没有用:(
标签: javascript automated-tests e2e-testing web-testing testcafe