skip to Main Content

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.

2

Answers


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

    cy.get("Attribute").should('match', /Value exist in Queue|Value doesn't exist/)
    
    Login or Signup to reply.
  2. If you prefer to not use a regex,cy.should() allows you to pass in a function. So, we can pass in a function that uses chai’s oneOf method.

    cy.get('Attribute').should(($attribute) => {
      expect($attribute).to.be.oneOf(['Value exist in Queue', 'Value doesn't exist']);
    });
    

    Note: I left your cy.get().should() the same in terms of yielded subject, however, you may need to change $attribute to $attribute.text().

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search