gpt4 book ai didi

exception - 如何在 Test Cafe 错误中获取完整的堆栈跟踪

转载 作者:行者123 更新时间:2023-12-01 03:08:30 25 4
gpt4 key购买 nike

我一直在使用 Test Cafe 编写一个内部测试框架,其中操作(t.click)和断言(t.expect)不是直接写在规范中,而是在其他文件中定义和聚合。

一切都很酷,直到测试不失败:在这种情况下,Test Cafe 记者在控制台中写入断言/操作失败和相关代码片段,但我没有找到理解测试中函数调用的完整堆栈跟踪的方法归结为失败的断言。

我如何确保在报告器中提供完整的堆栈跟踪,记录堆栈跟踪以及所有导致我的测试失败的函数调用?

我明白,原因应该是如何联系async/await is transpiled into generators :错误的堆栈跟踪仅显示最后一次执行的等待,而不是所有先前的调用。

<section> ... </section>
<section class="section--modifier">
<h1> ... </h1>
<div>
...
<button class="section__button">
<div class="button__label">
<span class="label__text">Hello!</span> <-- Target of my test
</div>
</button>
...
</div>
</section>
<section> ... </section>
// 
// My spec file
//
import { Selector } from 'testcafe';

import {
verifyButtonColor
} from './button';

fixture`My Fixture`
.page`....`;

test('Test my section', async (t) => {
const MySection = Selector('.section--modifier');
const MyButton1 = MySection.find('.section__button');

const MySection2 = Selector('.section--modifier2');
const MyButton2 = MySection2.find('.section__button');

....
await verifyButtonColor(t, MyButton1, 'green'); // it will fail!
....
....
....
await verifyButtonColor(t, MyButton2, 'green');
});
//
// Definition of assertion verifyButtonColor (button.js)
//
import { Selector } from 'testcafe';

import {
verifyLabelColor
} from './label';

export async function verifyButtonColor(t, node, expectedColor) {
const MyLabel = node.find('.button__label');
await verifyLabelColor(t, MyLabel, expectedColor);
}
// 
// Definition of assertion verifyLabelColor (label.js)
//
export async function verifyLabelColor(t, node, expectedColor) {
const MyText= node.find('.label__text');
const color = await MyText.getStyleProperty('color');

await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`); // <-- it will FAIL!
}

我在记者中没有得到的是,我的测试失败了,因为“verifyLabelColor”中定义的断言失败(颜色不是绿色:(),
...
await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`);
...

但在记者中,我没有证据表明由于以下调用堆栈而失败
- await verifyButtonColor(t, MyButton1, 'green');
- await verifyLabelColor(t, MyLabel, expectedColor);
- await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`);

任何机构都面临类似的问题?

另一种方法是记录导致失败的选择器的“路径”,但查看 Test Cafe 文档我没有找到这样做的可能性:知道以下路径的元素上的断言失败至少可以帮助明白出了什么问题
.section--modifier .section__button .button__label .label__text

最佳答案

此主题与 TestCafe 提案相关:Have a multiple stacktrace reporter for fast analysis when a test fails

同时你可以试试这个记者:/testcafe-reporter-cucumber-json或者您可以开发自己的 reporter

关于exception - 如何在 Test Cafe 错误中获取完整的堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54239586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com