I'm still new to Cypress but this behavior is driving me batty. Thanks for any help in advance! So, 2 tests on 2 pages. I can run this code on a page in a previous test:
cy.get('meta[property="article:tag"]')
.should("have.attr", "content")
.and("include", subex_subscriberexclusive_only)
.and("not.include", subex_subscriberexclusiveBeta_only);
Then in a subsequent test, on another page, I run the same code, and it seems by the "not.include" step, this time the subject has changed. At least that is the error I'm getting.
So same code, just swapping variables because the test is to make sure the opposite is true on the 2nd page:
cy.get('meta[property="article:tag"]')
.should("have.attr", "content")
.and("include", subex_subscriberexclusiveBeta_only)
.and("not.include", subex_subscriberexclusive_only);
The error reads:
The invalid subject you asserted on was:
> undefined
Another odd thing is that if I comment out the "not.include" test, everything passes. I'm guessing the subject changes after the "include" test, that is where the subject changes.
So is there a way to reset the subject? Or is there another way I should structure this test? I don't want to just comment out the negative test, I want to know we have what we need and not what we don't (And it worked the first time).
Some other things I've tried are using invoke and its but that seems to lead to the same outcome but only for this second page. I can also remove the first test on the first page or swap order and it always hangs up here. Perhaps I made a typo I need second eyes on. In any case, thanks!
Latest try:
cy.get('meta[property="article:tag"]')
.should("have.attr", "content")
.should(($meta) => {
expect($meta).to.include(subex_subscriberexclusiveBeta_only)
expect($meta).not.to.include(subex_subscriberexclusive_only)
})
Same hang up.
Thanks!