Testcafe throws an error invalid arg type

Viewed 340

I try to write some basic e2e tests with testcafe on a React/Electron app. First I wrote a basic test getting the app Page Title:

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');
}); 

The aboove test, it worked well!

But now I'm trying to add other tests like trying to login into the app with the next example:

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();
});

When I try to run e2e tests, I get a weird error like this:

Console output

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.

It seems like testcafe can't find the correct path to launch the electron app, but in the first case the test worked with the same path. Is there something I'm missing?

1 Answers

Relative URLs in Roles are not supported yet. Keep track of this issue: Support relative urls in Roles. As a workaround, you can use an absolute path.

Related