title |
---|
hash |
Get the current URL hash of the page that is currently active.
This is an alias of cy.location('hash')
cy.hash()
cy.hash(options)
Correct Usage
cy.hash() // Get the url hash
options (Object)
Pass in an options object to change the default behavior of cy.hash()
.
cy.hash( options )
Option | Default | Description |
---|---|---|
log |
true |
Displays the command in the Command log |
timeout |
defaultCommandTimeout |
Time to wait for cy.hash() to resolve before timing out |
cy.hash()
"yields the current URL's hash (including the #
character)" cy.hash()
"yields an empty string" // yields #/users/1
cy.hash().should('eq', '#/users/1') // => true
<ul id="users">
<li>
<a href="#/users/8fc45b67-d2e5-465a-b822-b281d9c8e4d1">Fred</a>
</li>
</ul>
cy.get('#users li').find('a').click()
cy.hash().should('match', /users\/.+$/) // => true
cy.hash()
requires being chained off of cy
.cy.hash()
will automatically retry until all chained assertions have passedcy.hash()
can time out waiting for assertions you've added to pass.Assert that the hash matches #users/new
cy.hash().should('eq', '#users/new')
The commands above will display in the Command Log as:
When clicking on hash
within the command log, the console outputs the following: