【发布时间】:2020-06-17 00:33:35
【问题描述】:
我尝试在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:\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 来启动电子应用程序,但在第一种情况下,测试使用相同的路径。我有什么遗漏吗?
【问题讨论】:
标签: javascript reactjs electron e2e-testing testcafe