question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.url() and/or cy.location('href') does not return a string as documentation claims

See original GitHub issue

Current behavior:

According to the documentation, Cy.url() should produce a string. I wanted to capture the current URL into a variable and then reference it after I run a custom Cypress command.

My question is, if cy.url() and cy.location(‘href’) no longer return strings in 3.0.1 - how do we get that value?

Desired behavior:

Expecting a string of the current URL; instead an object is received that looks like:

// JSON.stringify(cy.url())
{ "chainerId": "chainer2504", "firstCall": false }

// JSON.stringify(cy.location('href'))
{ "chainerId": "chainer2558", "firstCall": false }

Steps to reproduce:

Attempting to log either cy.url() or cy.location('href') does not result in a string as indicated by the documentation.

Versions

Cypress 3.0.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

58reactions
dugajeancommented, Oct 27, 2019

@brian-mann Then you should update your documentation and stop claiming that url() returns a string?

image

29reactions
kristinamongocommented, Jan 2, 2020

// if you need the current url in order to store it and use it later, you may do that:

let currentURL
  cy.url().then(url => {
    currentURL = url
  });

// and then use it later like that

cy.then(() => cy.visit(currentURL))
Read more comments on GitHub >

github_iconTop Results From Across the Web

cy.url() and/or cy.location('href') does not return a string
Commands are enqueued and run asynchronously. The solution is shown too: To access what each Cypress command yields you use .then() . cy....
Read more >
url - Cypress Documentation
cy.url() exists because it's what most developers naturally assume would return them the full current URL. We almost never refer to the URL...
Read more >
Location | Cypress examples (v9.7.0) - Gleb Bahmutov
To get the current URL hash, use the cy.hash() command. ... cy.location().should((location) => { // returns an object with every part of the...
Read more >
How to Test that URL Should Not Include a String in Cypress
If you want to verify that your URL should not include a string in ... cy.url().should('not.contain', '/home'); // You can also use a...
Read more >
LTX2X: A L ATEX to X Auto-tagger Contents - CTAN
In the command table bye.ct these are only included to. prevent printing before the \begin{document}. To run LTX2X with the above command table, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found