How to concatenate URLs to avoid getting TypeError [ERR_INVALID_URL]: Invalid URL #2297
-
What happened?I am clicking on a link on page which is opening new tab. I want to navigate to the new tab. const url = '/questions/datascience/'+questionID.toString()+'/edit'
await actor.attemptsTo(
Wait.upTo(Duration.ofSeconds(60))
.until(Page.whichUrl(endsWith(url)), isPresent())
.pollingEvery(Duration.ofSeconds(1)),
Switch.to(Page.whichUrl(endsWith(url)))
); But I am getting invalid url error even though it is correct one. What did you expect to happen?Want to switch context to new page and perform further operations Node.js version18.18.2 Execution environmentMAC OS, SERENITY JS and Playwright , chrome How to reproduce the bug.const url = '/questions/datascience/'+questionID.toString()+'/edit'
await actor.attemptsTo(
Wait.upTo(Duration.ofSeconds(60))
.until(Page.whichUrl(endsWith(url)), isPresent())
.pollingEvery(Duration.ofSeconds(1)),
Switch.to(Page.whichUrl(endsWith(url)))
); Serenity/JS version"playwright": "^1.38.1",
"@playwright/test": "^1.39.0",
"@serenity-js/assertions": "^3.11.1",
"@serenity-js/console-reporter": "^3.11.1",
"@serenity-js/core": "^3.11.1",
"@serenity-js/cucumber": "^3.11.1",
"@serenity-js/playwright": "^3.11.1",
"@serenity-js/rest": "^3.11.1",
"@serenity-js/serenity-bdd": "^3.11.1",
"@serenity-js/web": "^3.11.1", |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The root cause of the issue you're seeing is that the code sample concatenates the URL with the description of the Since the const url = '/questions/datascience/'+questionID.toString()+'/edit'
// produces: '/questions/datascience/description of questionID/edit' Questions are asynchronous data structures, so to concatenate the value of a question with a static string or with the value of another question, you'll need to use the helper function called In your case, this gives us: const url = q`/questions/datascience/${ questionID }/edit`
await actor.attemptsTo(
Wait.upTo(Duration.ofSeconds(60))
.until(Page.whichUrl(endsWith(url)), isPresent())
.pollingEvery(Duration.ofSeconds(1)),
Switch.to(Page.whichUrl(endsWith(url)))
); Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey @ChandanHackerrank
The root cause of the issue you're seeing is that the code sample concatenates the URL with the description of the
questionID
question, instead of the value of the question.Since the
url
contains the description, it doesn't match any registered window URLs.Questions are asynchronous data structures, so to concatenate the value of a question with a static string or with the value of another question, you'll need to use the helper function called
q
.In your case, this gives us: