gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 12:22:25 25 4
gpt4 key购买 nike

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

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:\Users\user\Git\electronApp\node_modules\testcafe\src\api\test-page-url.js:20:30)
at Object.resolvePageUrl (C:\Users\user\Git\electronApp\node_modules\testcafe\src\api\test-page-url.js:42:16)
at Proxy.createRole (C:\Users\user\Git\electronApp\node_modules\testcafe\src\role\index.js:73:17)
at Role (C:\Users\user\Git\electronApp\node_modules\testcafe\src\api\exportable-lib\index.js:15:17)
at Object.<anonymous> (C:\Users\user\Git\electronApp\tests\e2e\App.e2e.js:8:18)
at Function._execAsModule (C:\Users\user\Git\electronApp\node_modules\testcafe\src\compiler\test-file\api-based.js:50:13)
at ESNextTestFileCompiler._runCompiledCode (C:\Users\user\Git\electronApp\node_modules\testcafe\src\compiler\test-file\api-based.js:150:42)
at ESNextTestFileCompiler.execute (C:\Users\user\Git\electronApp\node_modules\testcafe\src\compiler\test-file\api-based.js:174:21)
at ESNextTestFileCompiler.compile (C:\Users\user\Git\electronApp\node_modules\testcafe\src\compiler\test-file\api-based.js:180:21)
at Compiler._getTests (C:\Users\user\Git\electronApp\node_modules\testcafe\src\compiler\index.js:86:31)

Type "testcafe -h" for help.
error Command failed with exit code 1.

似乎 testcafe 找不到正确的 path启动 Electron 应用程序,但在第一种情况下,测试使用相同的路径。有什么我想念的吗?

最佳答案

尚不支持 Angular 色中的相对 URL。跟踪此问题:Support relative urls in Roles .作为解决方法,您可以使用绝对路径。

关于javascript - Testcafe 抛出错误无效的 arg 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60527374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com