Search code examples
javascriptcypressassertion

Is it possible to use OR condition between strings in Cypress 'Should' assertion


I have a scenario where the text String in element could be either 'Value exist in Queue' or 'Value doesn't exist'

So I want to use should assertion to make sure any string of both is rendring properly.

I am trying these options but doesn't work

   cy.get("Attribute").should('include', 'Value exist in Queue' || 'Value doesn't exist')

Is there any work arround to tackle this situation.


Solution

  • Use match with a regular expression that matches either string.

    cy.get("Attribute").should('match', /Value exist in Queue|Value doesn't exist/)