Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

Cypress tests passes with `cypress open`, but fails with `cypress run`

I wrote the e2e tests. They pass all the time if I start them with cypress open. But if I use this command: cypress run --browser chrome --headed --no-exit --spec 'tests/e2e/specs/Samples.ts. I get many different errors. These errors are not similar. Some of them I don't know how to fix. And the important fact: If I open developer tools and restart the tests, all tests will pass. The same for Chrome and firefox. I have tried using different versions of cypress but to no avail. I guess the error types are not important in my issue, but I will explain one of them. enter image description here After the 8th step, cypress reports that the page has loaded and redirects to the login page. This could mean that the localStorage with the token was accidentally cleared. If I open developer tools and restart the tests, all tests will pass. The test is very simple. Also, I use two custom functions.

describe('Samples', () => {
  beforeEach(() => {
    cy.login();
  });

  afterEach(() => {
    cy.deleteAccount();
  });

  context('Create sample', () => {
    const SAMPLE_DATA = {
      name: 'Test',
      description: 'Description',
      compound: 'Compound1; Compound1',
    };

    afterEach(() => {
      cy.get('[data-test-id=btn-create]').click();
      cy.location('hash').should('match', //samples/d+$/);
      // archive
      cy.get('[data-test-id=btn-more-menu]').click();
      cy.get('[data-test-id=btn-archive]').click();
      cy.get('[data-test-id=btn-restore]');
    });

    it('should create sample without device', () => {
      cy.visit(urlPages.app.SAMPLES);
      cy.get('[data-test-id=btn-show-create-sample-modal]').click();
      cy.get('[data-test-id=input-name]').type(SAMPLE_DATA.name);
      cy.get('[data-test-id=input-description]').type(SAMPLE_DATA.description);
      cy.get('[data-test-id=input-compounds]').type(SAMPLE_DATA.compound);
    });
  });
})
question from:https://stackoverflow.com/questions/65845635/cypress-tests-passes-with-cypress-open-but-fails-with-cypress-run

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...