规范中有多个描述会导致奇怪的行为

Jas*_*eet 3 mocha.js cypress

我在规范文件中有 2 个描述块。首先,描述访问xyz.com,其次,描述访问abc.com

我只需要在一个规范中描述这两个。我看到的连线行为是它顺利运行测试,但从第二个描述访问 abc.com 后,它再次开始运行第一个描述。无限循环的测试

var signedOutArtifactID = null;

describe('WEB APP E2E tests', function() {
  var token = null;

  before(function() {
    cy.visit('/');

    // Login
    cy.get('#username')
      .type(auth.geneticist.username);

    cy.get('#password')
      .type(auth.geneticist.password);

    cy.get('button')
      .contains('Login')
      .click()
      .should(function() {
        token = localStorage.getItem('token');
        expect(token).not.to.be.null;
      });
  });

  beforeEach(function() {
    localStorage.setItem('token', token);

    cy.contains('Logout')
      .should('exist');

    expect(localStorage.getItem('token'));
  });

  it('should land on home page', function() {
    cy.url()
      .should('include', '/home');
  });


  it('should save and generate and end up on signout page', function() {
    cy.contains('Save and Generate Report')
      .click();

    cy.url()
      .should('include', '/sign-out');
  });

  it('should signout and send successfully', function() {
    cy.url()
      .should(function(currentURL) {
        signedOutArtifactID = currentURL.match(/2-([0-9]+)/)[0];
        expect(signedOutArtifactID).not.to.be.null;
    });

    // Make sure interpretation was updated
    cy.get('.card-body pre')
      .should('contain', 'test interpretation added by cypress');

    cy.contains('Sign Out and Send')
      .click();

    cy.contains('Yes, sign out and send')
      .click();

  });


});


describe('2nd WEB APP E2E tests', function() {

  before(function () {
    cy.visit({
      url:`https://webappurl.com/search?scope=All&query=${signedOutArtifactID}`,
      failOnStatusCode: false
    })
  })  

  it('Review Completed step in clarity', async () => {

    cy.get('#username').type(auth.clarity_creds.username)
    cy.get('#password').type(auth.clarity_creds.password)
    cy.get('#sign-in').click()

    cy.get('.result-name').click()
    cy.get('.view-work-link').contains('QWERTYU-IDS').click()

    cy.get('.download-file-link ')
      .should(($downloads) => {
        expect($downloads).to.have.length(2)
      })

  });

});
Run Code Online (Sandbox Code Playgroud)

Zac*_*ist 7

describe定义一个测试套件。每个文件只能有一个顶级测试套件,每个测试只能有一个域。

我只需将您的describes 更改为contexts 并将两个contexts 包装在一个中describe,如下所示:

var signedOutArtifactID = null;

describe('e2e tests', function() {

  context('WEB APP E2E tests', function() {
    var token = null;

    before(function() {
      cy.visit('/');

      // Login
      cy.get('#username')
        .type(auth.geneticist.username);

      cy.get('#password')
        .type(auth.geneticist.password);

      cy.get('button')
        .contains('Login')
        .click()
        .should(function() {
          token = localStorage.getItem('token');
          expect(token).not.to.be.null;
        });
    });

    beforeEach(function() {
      localStorage.setItem('token', token);

      cy.contains('Logout')
        .should('exist');

      expect(localStorage.getItem('token'));
    });

    it('should land on home page', function() {
      cy.url()
        .should('include', '/home');
    });


    it('should save and generate and end up on signout page', function() {
      cy.contains('Save and Generate Report')
        .click();

      cy.url()
        .should('include', '/sign-out');
    });

    it('should signout and send successfully', function() {
      cy.url()
        .should(function(currentURL) {
          signedOutArtifactID = currentURL.match(/2-([0-9]+)/)[0];
          expect(signedOutArtifactID).not.to.be.null;
      });

      // Make sure interpretation was updated
      cy.get('.card-body pre')
        .should('contain', 'test interpretation added by cypress');

      cy.contains('Sign Out and Send')
        .click();

      cy.contains('Yes, sign out and send')
        .click();

    });


  });


  context('2nd WEB APP E2E tests', function() {

    before(function () {
      cy.visit({
        url:`https://webappurl.com/search?scope=All&query=${signedOutArtifactID}`,
        failOnStatusCode: false
      })
    })  

    it('Review Completed step in clarity', async () => {

      cy.get('#username').type(auth.clarity_creds.username)
      cy.get('#password').type(auth.clarity_creds.password)
      cy.get('#sign-in').click()

      cy.get('.result-name').click()
      cy.get('.view-work-link').contains('QWERTYU-IDS').click()

      cy.get('.download-file-link ')
        .should(($downloads) => {
          expect($downloads).to.have.length(2)
        })

    });

  });

})
Run Code Online (Sandbox Code Playgroud)