Testcafe抛出一个错误-无效的arg类型



我尝试在React/Electron应用程序上用testcafe编写一些基本的e2e测试。首先,我写了一个获得应用程序的基本测试页面标题:

App.e2e.js

import { Selector } from 'testcafe';
fixture`Electron App`.page('../../app/app.html');
test('should contain expected page title', async browser => {
await browser.expect(getPageTitle()).eql('Electron App');
}); 

上面的测试,效果很好

但现在我正在尝试添加其他测试,比如尝试登录应用程序,下面的例子是:

App.e2e.js

import { Selector, Role } from 'testcafe';
const UserRole = Role('../../app/app.html', async t => {
await t
.typeText('input[name="email"]', 'user@user.com')
.typeText('input[name="password"]', 'secret')
.click(Selector('button[type=submit]').withText('Login'));
});
fixture`Electron App`
.page('../../app/app.html')
.beforeEach(async t => {
await t.useRole(UserRole);
});
test('Click a doc', async t => {
await t
.click(Selector('span').withText('Document'))
.expect(Selector('h1').withText('Document').exists)
.ok();
});

当我尝试运行e2e测试时,我得到了一个奇怪的错误,如下所示:

控制台输出

ERROR Cannot prepare tests due to an error.
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
at resolveFileUrl (C:UsersuserGitelectronAppnode_modulestestcafesrcapitest-page-url.js:20:30)
at Object.resolvePageUrl (C:UsersuserGitelectronAppnode_modulestestcafesrcapitest-page-url.js:42:16)
at Proxy.createRole (C:UsersuserGitelectronAppnode_modulestestcafesrcroleindex.js:73:17)
at Role (C:UsersuserGitelectronAppnode_modulestestcafesrcapiexportable-libindex.js:15:17)
at Object.<anonymous> (C:UsersuserGitelectronApptestse2eApp.e2e.js:8:18)
at Function._execAsModule (C:UsersuserGitelectronAppnode_modulestestcafesrccompilertest-fileapi-based.js:50:13)
at ESNextTestFileCompiler._runCompiledCode (C:UsersuserGitelectronAppnode_modulestestcafesrccompilertest-fileapi-based.js:150:42)
at ESNextTestFileCompiler.execute (C:UsersuserGitelectronAppnode_modulestestcafesrccompilertest-fileapi-based.js:174:21)
at ESNextTestFileCompiler.compile (C:UsersuserGitelectronAppnode_modulestestcafesrccompilertest-fileapi-based.js:180:21)
at Compiler._getTests (C:UsersuserGitelectronAppnode_modulestestcafesrccompilerindex.js:86:31)
Type "testcafe -h" for help.
error Command failed with exit code 1.

testcafe似乎找不到正确的path来启动电子应用程序,但在第一种情况下,测试采用了相同的路径。我有什么东西不见了吗?

角色中的相对URL还不受支持。跟踪这个问题:支持角色中的相对url。作为一种变通方法,您可以使用绝对路径。

最新更新