You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为什么Cypress运行旧代码而非最新修改的测试代码?

Cypress测试代码修改不生效问题解决

使用Cypress(测试版本覆盖7.7.0、8.0.0、8.7.0)编写表单填写E2E测试时,出现代码修改后不生效的异常情况:

  • 曾临时将代码中的.click()方法调整为.click({ multiple: true }),后续删除该配置后,无论怎么修改测试代码,实际运行的始终是旧版本代码,报错也持续指向带有multiple: true参数的click操作
  • 排查最新测试代码,未发现任何和"multiple"相关的内容

当前生效的测试代码如下:

const moment = require('moment');

const destinationElements = 'elem de ci';
const orderedVolume = '100';
const deliveryFrequency = '25';
const deliveryTime = '23:00';
const additionalInfo = 'réalisé via cypress';

Cypress.on('uncaught:exception', err => {
  return false;
});

describe('Create concrete order', () => {
  beforeEach(() => {
    cy.login();
  });

  it('should create a concrete order', () => {
    cy.url().should('eq', Cypress.config().baseUrl + '/home');

    cy.get('[data-testid=createOrderLink] button').click();

    // Fill form

    const tomorrowDate = moment()
      .add(1, 'days')
      .format('YYYY-MM-DD');
    cy.get('input[data-test-id=deliveryDate]').click();
    cy.get(`td[title=${tomorrowDate}]`)
      .click()
      .wait(10);

    cy.fillInput('orderedVolume', orderedVolume);
    cy.fillInput('deliveryFrequency', deliveryFrequency);
    cy.fillInput('deliveryTime', deliveryTime);
    cy.fillInput('destinationElements', destinationElements);

    cy.get('button[data-test-id=create-order-button]').click();

    cy.get('tbody tr:last-child td:nth-child(5)').should(
      'have.text',
      destinationElements,
    );
  });
});

根因与解决方案

该问题由Cypress调用的Chromium浏览器缓存导致,清除Chromium浏览器缓存后重新运行测试,功能即可恢复正常。

内容的提问来源于stack exchange,提问作者Clément Drouin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 15:42:04