title |
---|
hash |
Get the current URL hash of the page that is currently active.
{% note info %}
This is an alias of {% url "cy.location('hash')
" location %}
{% endnote %}
cy.hash()
cy.hash(options)
{% fa fa-check-circle green %} Correct Usage
cy.hash() // Get the url hash
{% fa fa-angle-right %} options (Object)
Pass in an options object to change the default behavior of cy.hash()
.
cy.hash( options )
Option | Default | Description |
---|---|---|
log |
true |
{% usage_options log %} |
timeout |
{% url defaultCommandTimeout configuration#Timeouts %} |
{% usage_options timeout cy.hash %} |
{% yields sets_subject cy.hash "yields the current URL's hash (including the #
character)" %}
{% yields sets_subject 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
{% requirements parent cy.hash %}
{% assertions retry cy.hash %}
{% timeouts assertions cy.hash %}
Assert that the hash matches #users/new
cy.hash().should('eq', '#users/new')
The commands above will display in the Command Log as:
{% imgTag /img/api/hash/test-url-hash-for-users-page.png "Command Log for hash" %}
When clicking on hash
within the command log, the console outputs the following:
{% imgTag /img/api/hash/hash-command-yields-url-after-hash.png "Console Log for hash" %}
- {% url
cy.location()
location %} - {% url
cy.url()
url %}