testcafe
testcafe copied to clipboard
Support relative urls in Roles
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:
- Go to my website ...
- Execute this command...
- See the error...
Your Environment details:
- testcafe version: 0.23.3
- node.js version: v11.0.0
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
.
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.
Thank you for your feedback. We will take it into consideration.
Relative paths in Electron https://stackoverflow.com/questions/60527374/testcafe-throws-an-error-invalid-arg-type
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.
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.
Could this issue be reopened now that #1932 have added support for a global start url?
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.
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.
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