Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

What is the difference between assertions in cypress?

What is the difference between:

  • cy.contains('text').should('be.visible'); and
  • cy.should('be.visible','text')?

Because for me the first option is working to check the text but the second it doesn't check properly, so I was wondering in which cases I can use the second option for checking the text?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
cy.should()

doesn't exist, you need to yield something before you run an assertion on it. You can read more about the command here.

The syntax mentioned in the documentation:

.should(chainers)

it does not start with cy., so it means you have to have another command that yields something before you use .should().

You can compare it to what documentation mentions for cy.get() command that could be directly chained with cy:

cy.get(selector)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...