testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Support relative urls in Roles

Open eric-burel opened this issue 6 years ago • 7 comments

What is your Test Scenario?

Setup a Role for an authenticated user.

Here is the role:

const candidateRole = Role('/', async t => {
    await t
    .typeText('#usernameOrEmail', 'test')
    .typeText('#password', 'testtest')
    .click('[type="submit"]');
});

Here is the test:

test('can signin', async t => {
  await t.useRole(candidateRole)
})

What is the Current behavior?

Here is the error. First problem is that it is cryptic.

   1) - Error in Role initializer -
      Uncaught object "[object Object]" was thrown. Throw Error instead.

After adding a try/catch, I can have this clearer error message.

{ stack:
  "Error: Failed to set the 'href' property on 'Location': 'http:////' is not a valid URL.\n    at e.navigateTo (http://192.168.1.80:34025/hammerhead.js:1:19301)\n    at http://192.168.1.80:34025/testcafe-driver.js:1:32674\n    at s (http://192.168.1.80:34025/hammerhead.js:1:8513)\n    at Array.forEach (<anonymous>)\n    at p (http://192.168.1.80:34025/hammerhead.js:1:9091)\n    at Array.d (http://192.168.1.80:34025/hammerhead.js:1:9127)\n    at n (http://192.168.1.80:34025/hammerhead.js:1:8262)",
 callsite: undefined,
 isRejectedDriverTask: true }

So I figured out the Role expected an absolute URL.

What is the Expected behavior?

Cases when an absolute URL is necessary is unclear. But the biggest issue here is the error message, some part of the code seems to be throwing an object instead of an E

What is your web application and your TestCafe test code?

Your website URL (or attach your complete example):

Your complete test code (or attach your test files):
 
Your complete test report:

Screenshots:

Steps to Reproduce:

  1. Go to my website ...
  2. Execute this command...
  3. See the error...

Your Environment details:

  • testcafe version: 0.23.3
  • node.js version: v11.0.0

eric-burel avatar Feb 06 '19 17:02 eric-burel

Hi @eric-burel

The problem is related to the relative url in your Role definition. To fix it, use an absolute url.

I will mark the issue as a suggestion - Support relative urls in Roles.

miherlosev avatar Feb 07 '19 08:02 miherlosev

At the very least, can we improve the error message? I was getting TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined before testing whether an absolute URL was required.

rob4629 avatar Jul 24 '19 23:07 rob4629

Thank you for your feedback. We will take it into consideration.

Dmitry-Ostashev avatar Jul 25 '19 12:07 Dmitry-Ostashev

Relative paths in Electron https://stackoverflow.com/questions/60527374/testcafe-throws-an-error-invalid-arg-type

miherlosev avatar Mar 04 '20 14:03 miherlosev

This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.

github-actions[bot] avatar Mar 05 '21 02:03 github-actions[bot]

We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.

github-actions[bot] avatar Mar 15 '21 02:03 github-actions[bot]

Could this issue be reopened now that #1932 have added support for a global start url?

Nisden avatar Jul 22 '22 08:07 Nisden

This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.

github-actions[bot] avatar Jul 26 '23 01:07 github-actions[bot]

We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.

github-actions[bot] avatar Aug 06 '23 01:08 github-actions[bot]

can we please find a solution? it directly affects me and probably many others, since you can't have Role feature enabled + --base-url feature enabled on the same project. Thank you!

Description: I am using --base-url CLI flag to pass the URL of my environments, however I am facing an issue when running tests that use Role feature because its constructor does not support relative URLs ( You cannot specify relative login page URLs in the Role constructor. Use an absolute URL)

Testcafe v3.1.0-rc.3

razvanvancea avatar Sep 15 '23 11:09 razvanvancea

Hello everyone,

We added support for relative URLs in Role with a base URL in the latest release

PavelMor25 avatar Nov 13 '23 06:11 PavelMor25