Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Testcafe抛出一个错误无效的参数类型_Javascript_Reactjs_Electron_E2e Testing_Testcafe - Fatal编程技术网

Javascript Testcafe抛出一个错误无效的参数类型

Javascript Testcafe抛出一个错误无效的参数类型,javascript,reactjs,electron,e2e-testing,testcafe,Javascript,Reactjs,Electron,E2e Testing,Testcafe,我尝试在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 brows

我尝试在
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');
}); 
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();
});
ABOVE测试,效果很好

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

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');
}); 
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.
由于错误,
错误无法准备测试。
TypeError[ERR_INVALID_ARG_TYPE]:“path”参数必须是string类型。接收类型未定义
在resolveFileUrl(C:\Users\user\Git\electronApp\node\u modules\testcafe\src\api\test page url.js:20:30)
在Object.resolvePageUrl(C:\Users\user\Git\electronApp\node\u modules\testcafe\src\api\test page url.js:42:16)
在Proxy.createRole(C:\Users\user\Git\electronApp\node\u modules\testcafe\src\role\index.js:73:17)
at角色(C:\Users\user\Git\electronApp\node\u modules\testcafe\src\api\exportable lib\index.js:15:17)
反对。(C:\Users\user\Git\electronApp\tests\e2e\App.e2e.js:8:18)
at Function.\u execAsModule(C:\Users\user\Git\electronApp\node\u modules\testcafe\src\compiler\test file\api-based.js:50:13)
在esnextestfilecompiler.\u运行编译代码(C:\Users\user\Git\electronApp\node\u modules\testcafe\src\compiler\test file\api-based.js:150:42)
在esnextestfilecompiler.execute(C:\Users\user\Git\electronApp\node\u modules\testcafe\src\compiler\test file\api-based.js:174:21)
在esnextestfilecompiler.compile(C:\Users\user\Git\electronApp\node\u modules\testcafe\src\compiler\test file\api-based.js:180:21)
在编译器上获取测试(C:\Users\user\Git\electronApp\node\u modules\testcafe\src\Compiler\index.js:86:31)
键入“testcafe-h”以获取帮助。
错误命令失败,退出代码为1。

testcafe似乎无法找到启动electron应用程序的正确路径,但在第一种情况下,测试使用的是相同的路径。我缺少什么吗?

还不支持角色中的相对URL。跟踪此问题:。作为解决方法,可以使用绝对路径