late-planet-4481
11/11/2022, 10:59 PMcy 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:
js
// invalid
if(cy.location('pathname') == 'home') {
cy.get('.startButton').click()
}
You'd want to do this instead:
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.