详细报告 Cypress/Mochawesome
Detailed Reporting Cypress/Mochawesome
有没有人有使用 Mochawesome 作为报告引擎从 Cypress 测试中生成详细报告的丰富经验?
我已经关注了 Mochawesome GIT 页面上的信息,但我得到的信息相当乏味!!
我希望能够包括奇怪的屏幕截图和断言的输出 - 这是当前的 cypress.json
文件......
{
"projectId": "haw8v6",
"baseUrl": "https://obmng.dbm.guestline.net/",
"chromeWebSecurity": false,
"reporter" : "mochawesome",
"reporterOptions" : {
"reportFilename" : "DBM Smoke-Test",
"overwrite": true,
"inline": true
}
}
我一直在玩弄var addContext = require('mochawesome/addContext');
,但没有什么快乐。
非常感谢收到建议。
谢谢
根据以下要求 - addContext
的非常基本的示例
var addContext = require('mochawesome/addContext');
describe('DBM Smoketests', function() {
it('E2E Hotel2 WorldPay System', function() {
cy.visit('https://obmng.dbm.guestline.net/');
cy.url().should('include','/obmng.dbm');
addContext(this,'URL is correct');
//loads hotel 2
cy.get('.jss189 > div > .jss69 > .jss230').click();
经过大量研究,我找到了一种在 Cypress 中使用 Mochawesome addContext
的方法。
注意,每次测试只能进行一次 addContext 调用(这是 Mochawesome 的限制)。
describe('DBM Smoketests', function() {
it('E2E Hotel2 WorldPay System', function() {
cy.visit('https://obmng.dbm.guestline.net/');
cy.url().should('include','/obmng.dbm');
Cypress.on('test:after:run', (test) => {
addContext({ test }, {
title: 'This is my context title',
value: 'This is my context value'
})
});
});
});
第二个参数是要附加到测试的上下文,它必须具有非空 title
和 value
属性。
您在 mochawesome.json
输出中得到的是
...
"suites": [
{
...
"tests": [
{
"title": "E2E Hotel2 WorldPay System",
...
"context": "{\n \"title\": \"This is my context title\",\n \"value\": \"This is my context value\"\n}",
"code": "...",
...
}
],
在 mochawesome.html
中,点击测试你会得到
Additional Test Context
This is my context title:
This is my context value
我还没有用字符串以外的值类型尝试过。
注意 对于在赛普拉斯开始使用 Mochawesome 的任何人,看起来您只能使用 运行 cypress run
获得 Mochawesome 报告,而不是 cypress open
- 尽管使用 mocha 的多个报告器功能可能有解决此问题的方法。
是确认工作!可以像这样在每个测试中调用一次:
it('Should shine the test report!!!', () => {
cy.get('li').should('have.length.greaterThan', 0);
addTestContext('String','giphy');
addTestContext('Link','https://giphy.com');
addTestContext('Image','https://media.giphy.com/media/tIIdsiWAaBNYY/giphy.gif');
addTestContext('Image','https://media.giphy.com/media/tIIdsiWAaBNYY/giphy.gif');
});
function addTestContext(title, value) {
cy.once('test:after:run', test => addContext({ test }, { title, value }));
}
有没有人有使用 Mochawesome 作为报告引擎从 Cypress 测试中生成详细报告的丰富经验?
我已经关注了 Mochawesome GIT 页面上的信息,但我得到的信息相当乏味!!
我希望能够包括奇怪的屏幕截图和断言的输出 - 这是当前的 cypress.json
文件......
{
"projectId": "haw8v6",
"baseUrl": "https://obmng.dbm.guestline.net/",
"chromeWebSecurity": false,
"reporter" : "mochawesome",
"reporterOptions" : {
"reportFilename" : "DBM Smoke-Test",
"overwrite": true,
"inline": true
}
}
我一直在玩弄var addContext = require('mochawesome/addContext');
,但没有什么快乐。
非常感谢收到建议。
谢谢
根据以下要求 - addContext
var addContext = require('mochawesome/addContext');
describe('DBM Smoketests', function() {
it('E2E Hotel2 WorldPay System', function() {
cy.visit('https://obmng.dbm.guestline.net/');
cy.url().should('include','/obmng.dbm');
addContext(this,'URL is correct');
//loads hotel 2
cy.get('.jss189 > div > .jss69 > .jss230').click();
经过大量研究,我找到了一种在 Cypress 中使用 Mochawesome addContext
的方法。
注意,每次测试只能进行一次 addContext 调用(这是 Mochawesome 的限制)。
describe('DBM Smoketests', function() {
it('E2E Hotel2 WorldPay System', function() {
cy.visit('https://obmng.dbm.guestline.net/');
cy.url().should('include','/obmng.dbm');
Cypress.on('test:after:run', (test) => {
addContext({ test }, {
title: 'This is my context title',
value: 'This is my context value'
})
});
});
});
第二个参数是要附加到测试的上下文,它必须具有非空 title
和 value
属性。
您在 mochawesome.json
输出中得到的是
...
"suites": [
{
...
"tests": [
{
"title": "E2E Hotel2 WorldPay System",
...
"context": "{\n \"title\": \"This is my context title\",\n \"value\": \"This is my context value\"\n}",
"code": "...",
...
}
],
在 mochawesome.html
中,点击测试你会得到
Additional Test Context
This is my context title:
This is my context value
我还没有用字符串以外的值类型尝试过。
注意 对于在赛普拉斯开始使用 Mochawesome 的任何人,看起来您只能使用 运行 cypress run
获得 Mochawesome 报告,而不是 cypress open
- 尽管使用 mocha 的多个报告器功能可能有解决此问题的方法。
是确认工作!可以像这样在每个测试中调用一次:
it('Should shine the test report!!!', () => {
cy.get('li').should('have.length.greaterThan', 0);
addTestContext('String','giphy');
addTestContext('Link','https://giphy.com');
addTestContext('Image','https://media.giphy.com/media/tIIdsiWAaBNYY/giphy.gif');
addTestContext('Image','https://media.giphy.com/media/tIIdsiWAaBNYY/giphy.gif');
});
function addTestContext(title, value) {
cy.once('test:after:run', test => addContext({ test }, { title, value }));
}