【发布时间】:2019-12-05 15:55:19
【问题描述】:
假设“mywebsite.com”具有全局功能:
function sayHello(message){
console.log(message)
}
是否可以在 nodejs 中使用 testcafé 运行该功能的测试?
到目前为止我有这个
import { Selector } from 'testcafe';
fixture `mywebsite test`
.page `http://mywebsite.com`;
test('sayHelloFuncTest', async t => {
sayHello('HELLO!')
});
这会给我一个错误提示:ReferenceError: sayHello is not defined
那么有没有办法访问 sayHello() 函数?
【问题讨论】:
-
testcafe 用于模拟网页上的用户交互。如果您想测试特定的功能,您可能需要导出您想要测试的功能,并将它们导入您的测试脚本
-
我试过了,但遇到了很多错误,例如“未定义提取”。所以它不会像我出于某种原因在浏览器中运行它一样运行。是否有更合乎逻辑的方式在浏览器中打开网站,运行全局定义的函数并返回错误,使用 nodeJs
标签: javascript node.js testing automated-tests testcafe