leen M
leen M

Reputation: 613

How to assert if this text contain at least one words from one statement in cypress

For example

cy.get('.stitle').contains("learning table",{ matchCase: false })

This statement will pass the test if .stitle has the full text of "learning table", but what I really want is .stitle either has "learning just", or "table just". And so both can pass the test

because I want it to be reusable for any statement

Upvotes: 1

Views: 412

Answers (1)

Joshua
Joshua

Reputation: 3186

You can use regular expression to do so, here is a quick example:

cy.get(".stitle").contains(/(learning|table)/i);

This matches:

<p class="stitle">
  learning Lorem ipsum, dolor sit amet consectetur adipisicing elit.
  Dolor, in nulla dolores vero autem cum vitae. Eaque ipsum, numquam, ea
  nam iste a quaerat excepturi facilis praesentium repellendus laudantium
  blanditiis.
</p>

or

<p class="stitle">
  Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dolor, in
  nulla dolores table vero autem cum vitae. Eaque ipsum, numquam, ea nam
  iste a quaerat excepturi facilis praesentium repellendus laudantium
  blanditiis.
</p>

Upvotes: 1

Related Questions