使用cypress-allure-plugin遇TS错误:类型'Allure'不存在'then'属性
解决cypress-allure-plugin的TypeScript错误:Property 'then' does not exist on type 'Allure'
问题根源
你代码里的.then(() => {})写法错误,因为cy.allure().startStep()返回的是Allure实例对象,不是Cypress的可链式调用Promise,所以不存在then方法。
解决方案1:修正步骤写法
不需要用then包裹命令,直接按顺序编写步骤和测试命令:
cy.allure().startStep('Step 1'); cy.visit('/path1/path2'); cy.allure().endStep();
更推荐使用step方法(自动处理步骤的开始和结束,无需手动调用endStep):
cy.allure().step('Step 1', () => { cy.visit('/path1/path2'); });
解决方案2:修复TypeScript配置问题
检查你的tsconfig.json,修正两处语法错误:
- 移除
compilerOptions中types数组末尾的逗号(JSON不允许尾逗号) - 确保
lib字段的引号是英文双引号(你的配置里存在转义后的异常引号,可能导致解析失败)
修正后的tsconfig.json示例:
{ "compilerOptions": { "baseUrl": "..", "target": "es5", "lib": [ "es5", "es2016", "dom" ], "types": [ "cypress", "@testing-library/cypress", "@shelex/cypress-allure-plugin" ] }, "include": [ "**/*.ts" ] }
如果类型仍未生效,在测试文件顶部手动添加类型引用:
/// <reference types="@shelex/cypress-allure-plugin" />
内容的提问来源于stack exchange,提问作者ShaynaRosado
相关产品推荐
相关产品推荐

