Zoran
Zoran

Reputation: 499

Request with status:401 and popup message fails

Have assertion with 401 request, which passes, but want, also, to confirm popup error which appears (that part fails). Below are screenshots of page layout and test results:

enter image description here

enter image description here

And code which wrote:

it('should not be loaded any data without mocks', () => {
cy.visit('/partURL');
cy.server();
cy.route({
  method: 'GET',
  url: '**/forms?workspace?**',
}).as('myUrlAlias');
cy.wait('@myUrlAlias')
  .its('status')
  .should('eq', 401);
 cy.get('div.inner_page__content div.embedded_alert__wrapper img')
  .should('have.attr', 'src')
  .and('include', 'alt');
  });

enter image description here

Upvotes: 1

Views: 430

Answers (1)

Rosen Mihaylov
Rosen Mihaylov

Reputation: 1427

It seems to me your chain on the target element is wrong. .and() checks for assertion on the original element, if you wana check the attr - you should chain a second .should(). Here an alternative idea:

it('should not be loaded any data without mocks', () => {
    cy.visit('/partURL');
    cy.server();
    cy.route({
        method: 'GET',
        url: '**/forms?workspace?**',
    }).as('myUrlAlias');
    cy.wait('@myUrlAlias')
        .its('status')
        .should('eq', 401);
    cy.get('img[alt="Warning icon"]')
        .should('exist')
});

Upvotes: 1

Related Questions