https://cypress.io logo
You'll need to keep in mind that `cy` commands are...
# best-practices
l
You'll need to keep in mind that
cy
commands are collected and executed after your test's JavaScript has run. So in your case you'd need to run the
if
inside a callback with access to the
cy.xpath()
result beforehand. So for example, this hypothetical would not work:
Copy code
js
// invalid
if(cy.location('pathname') == 'home') {
  cy.get('.startButton').click()
}
You'd want to do this instead:
Copy code
js
// valid
cy.location('pathname').then((pathname) => {
  if(pathname == 'home') {
    cy.get('.startButton').click()
  }
})
But Gleb is right, avoid creating tests that have an uncertain path.