- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚开始将 mochawesome 与 Cypress (9.7) 一起使用。我们的测试结构基本上是许多规范文件,每个文件都遵循以下格式:
describe('(A): description of this spec', () => {
describe ('(B): description of test abc', () => {
before(() => {
// do specific set up bits for this test
})
it('(C): runs test abc', () => {
// do actual test stuff
})
})
})
每个规范文件中都有一个“A”描述 block ,但可以有许多“B”级 block (每个 block 都有一个“C”) - 这样做是因为每个“C”的前 block ' 总是不同的 - 我无法使用 beforeEach。
当我运行各种规范文件时,每个规范文件的结构都与上面类似,mochaewsome 输出大部分是正确的 - 我在“A”级别为每个规范文件获得一个可折叠 block ,每个文件在 B 级都有多个可折叠 block ,每个测试信息符合 C 级预期。
但是......圆形图表仅在B级显示。我希望的是,可能有A级的聚合图表,以及所有A级区 block 的进一步聚合图表。
不确定我是否已经很好地解释了这一点(!),但希望有人理解,并可以提供建议?!
最佳答案
在cypress-mochawesome-reporter
中,有一个使用on('after:run')
的替代设置可以执行聚合。
在Cypress v9.7.0中
// cypress/plugins/index.js
const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib');
const { aggregateResults } = require('./aggregate-mochawesome-report-chart');
module.exports = (on, config) => {
on('before:run', async (details) => {
await beforeRunHook(details);
});
on('after:run', async () => {
aggregateResults(config)
await afterRunHook();
});
};
在 Cypress v10+
// cypress.config.js
const { defineConfig } = require('cypress');
const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib');
const { aggregateResults } = require('./aggregate-mochawesome-report-chart');
module.exports = defineConfig({
reporter: 'cypress-mochawesome-reporter',
video: false,
retries: 1,
reporterOptions: {
reportDir: 'test-report',
charts: true,
reportPageTitle: 'custom-title',
embeddedScreenshots: true,
inlineAssets: false,
saveAllAttempts: false,
saveJson: true
},
e2e: {
setupNodeEvents(on, config) {
on('before:run', async (details) => {
await beforeRunHook(details);
});
on('after:run', async () => {
aggregateResults(config)
await afterRunHook();
});
},
},
});
进行聚合的模块是
// aggregate-mochawesome-reporter-chart.js
const path = require('path');
const fs = require('fs-extra')
function aggregateResults(config) {
const jsonPath = path.join(config.reporterOptions.reportDir , '/.jsons', '\mochawesome.json');
const report = fs.readJsonSync(jsonPath)
const topSuite = report.results[0].suites[0]
aggregate(topSuite)
fs.writeJsonSync(jsonPath, report)
}
function aggregate(suite, level = 0) {
const childSuites = suite.suites.map(child => aggregate(child, ++level))
suite.passes = suite.passes.concat(childSuites.map(child => child.passes)).flat()
suite.failures = suite.failures.concat(childSuites.map(child => child.failures)).flat()
suite.pending = suite.pending.concat(childSuites.map(child => child.pending)).flat()
suite.skipped = suite.skipped.concat(childSuites.map(child => child.skipped)).flat()
if (!suite.tests.length && suite.suites[0].tests.length) {
// trigger chart when to describe has no tests
suite.tests = [
{
"title": "Aggregate of tests",
"duration": 20,
"pass": true,
"context": null,
"err": {},
"uuid": "0",
"parentUUID": suite.uuid,
},
]
}
return suite
}
module.exports = {
aggregateResults
}
函数aggregate()
递归地循环遍历子套件并将测试结果添加到父套件。
请注意,json
文件在 afterRunHook
运行时和测试运行结束时是不同的。
如果您设置了 saveJson: true
选项,您将在报告目录中获得一个名为 index.json
的最终 json 文件。
在 afterRunHook 阶段,文件为 mochawesome.json
。
关于aggregate - Mochawesome with Cypress - 如何获得更高级别的聚合图表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72907573/
问题:Cypress npm 父项目能否导入/添加/运行其依赖项 Cypress npm 项目的 Cypress 测试? 问题的答案是这个链接有效,将一个整体的 Cypress 测试包分解成多个 Cy
我编写了端到端测试。如果我在打开柏树的情况下启动它们,它们就会一直通过。但是如果我使用这个命令:cypress run --browser chrome --headed --no-exit --sp
我想在每次测试之间传递/共享数据。在 Cypress 中实现它的最佳方法是什么? 例如: it('test 1'), () => { cy.wrap('one').as('a') con
柏树 clears all cookies和 local storage每次考试前。它是否也清除浏览器的文件缓存? 最佳答案 编辑: Cypress 在浏览器启动前自动清除浏览器缓存 Version
我正在尝试对 cypress 执行条件语句,以检查标题中的登录链接是登录还是帐户或类,然后单击它。 if 条件不起作用。 cy.get('header').then((header) => { if
我们正在尝试编写一个 cypress 测试来检查从页面发出的 xhr 请求之一。但是,我们发出的请求没有显示在命令日志中。然而,在运行 cypress open 后,它们确实出现在 bash 控制台中
我正在评估 Cypress(版本 3.4.1),并且在从 cypress 工具运行相同的测试和从终端运行它们之间遇到不一致,我在两种情况下都使用相同的浏览器(Electron 61)。有人经历过吗?
我有一个表单,允许用户输入日期范围,输出结果将仅来自该特定日期。 我可以使用 .type() 函数将日期输入到表单中。但是,我不确定如何检查结果是否在指定的范围内。 例如,如果输入的日期是 ('17/
我正在使用 Cypress ,并且想对XHR响应进行部分 stub 。我想捕获原始JSON,并对其进行部分编辑。 例如:cy.route('GET', `**/subjects`, 'fixture:
您好,我正在尝试通过 Jenkins 运行 cypress 测试,并且正在从我的本地 m/c 获取测试,而不是从 github 获取测试,并且正在执行 Windows 批处理命令"./node_mod
tl;dr:cypress 变量是否可以存储在某个可访问的位置(如 this 或类似的东西),或者如果我想访问所有这些变量,我是否必须进入无休止的回调循环一次使用? 长话短说: 我试图用 cypres
我有一个场景,在选择特定产品后,金额会反射(reflect)在文本字段中,当我们单击复选框时,金额会自动翻倍。这是我的代码: cy.getBySel('textfield').click().then
我正在使用 Cypress 测试数据表单,但卡在了一个在页面上显示警告的步骤上。 这是测试,但它不起作用。 describe('Alert is displayed with warning text
我有一个表格,我正在测试列标题是否正确。问题是 .contains() 只返回一个元素。 我可以为每个实例重复代码,但它看起来很冗长。感觉我一定在 Cypress 命令中遗漏了一些可以做得更好的东西。
我们有一个应用程序会定期轮询服务器,直到任务完成。我们触发了一个全局事件,以便 Cypress 可以捕捉并找出任务是否完成,但我们在使用 document.addEventListener 时遇到了问
是否可以告诉 Cypress 使用某种语言(例如德语)启动 Chrome,因为我有一个应用程序需要用多种语言进行测试。我在文档中的任何地方都看不到详细信息,这表明目前这是不可能的。 我试过添加 --l
我正在使用 Cypress作为我的 API 和 UI 测试自动化框架。我已经编写了多个正在运行和通过的 API 测试,但它们只是验证 response.status返回 200 .我想比较来自 GET
在运行 Cypress 脚本时,有些情况会失败。我只想运行那些失败的案例来再次运行。 如何在 Cypress 中仅运行失败的测试用例? 最佳答案 只要它没有直接集成到 Cypess 中,你就可以使用类
如何使用 Cypress 清除(取消选择)多选输入中的所有选项? 这里的文档似乎没有涵盖这种情况:https://docs.cypress.io/api/commands/select.html#Sy
我们正在使用 Cypress 使用 Create React App 测试应用程序构建,我们的 CRA 应用程序正在 .env – NODE_PATH=src/ – 中设置自定义导入路径,以便我们可以
我是一名优秀的程序员,十分优秀!