gpt4 book ai didi

testing - 咖啡厅 : Unhandled Promise rejection in First test makes second test pass even when It has to be failed by throwing Unhandled Promise Rejection

转载 作者:行者123 更新时间:2023-11-28 20:35:23 30 4
gpt4 key购买 nike

我正在使用 Test Cafe 中使用 Resemble.JS 库的函数来比较实际屏幕截图和基本屏幕截图。在我的夹具中,我有两个测试,由于屏幕截图不匹配,两个测试都应该在报告中失败,但唯一的第一个测试显示为失败,而第二个测试在报告中通过

请帮助我如何处理这种情况并将两个测试标记为失败。

比较截图功能:

const peformVisualRegression = async (testFixture, testName) => {
// take actual screenshot
await t.takeScreenshot(path.join('actual', testFixture, `${testName}.png`));

const actualScreenshotAbsolutePath = getAbsolutePathForScreenshot(
'actual',
testFixture,
testName
);
const isActualScreenshotTaken = fs.existsSync(actualScreenshotAbsolutePath);

const baseScreenshotAbsolutePath = getAbsolutePathForScreenshot(
'base',
testFixture,
testName
);
const isBaseScreenshotTaken = fs.existsSync(baseScreenshotAbsolutePath);

if (isActualScreenshotTaken && isBaseScreenshotTaken) {
await resemble(baseScreenshotAbsolutePath)
.compareTo(actualScreenshotAbsolutePath)
.scaleToSameSize()
.outputSettings({
errorColor: {
blue: 255,
green: 0,
red: 255
},
errorType: 'movement',
largeImageThreshold: 1200,
outputDiff: true,
transparency: 0.3,
useCrossOrigin: false
})
.onComplete(async data => {
if (data.rawMisMatchPercentage > 0) {
logger.error(
`Mismatch percentage for ${testFixture}/${testName} between actual and base screenshot is ${
data.rawMisMatchPercentage
}`
);
// write a diff image
fs.writeFileSync(
path.join(
path.dirname(actualScreenshotAbsolutePath),
`${path.basename(
actualScreenshotAbsolutePath,
path.extname(actualScreenshotAbsolutePath)
)}-diff.png`
),
data.getBuffer()
);

// fail test
throw new Error(
`Visual mismatch detected in test: ${testFixture}/${testName}. Please investigate.`
);
}
});
}

夹具:

fixture('Test Duckduckgo search fixture 1').page('https://duckduckgo.com');

test('Testcafe case 1 | @TestrailID:1094986', async t => {
await t.expect(samplePage.searchInputField.exists).ok();
await samplePage.enterText('dog');
const location = await getWindowLocation();
await t.expect(location.href).contains('q=dog');
await peformVisualRegression(
'Test Duckduckgo search fixture 1',
'Testcafe case 1'
);
});

test('Testcafe case 2 | @TestrailID:1094987', async t => {
await t.expect(samplePage.searchInputField.exists).ok();
await peformVisualRegression(
'Test Duckduckgo search fixture 1',
'Testcafe case 2'
);
});

最佳答案

我能够重现这个问题,所以我创建了一个单独的 bug report在 TestCafe 存储库中详细研究问题。

关于testing - 咖啡厅 : Unhandled Promise rejection in First test makes second test pass even when It has to be failed by throwing Unhandled Promise Rejection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56079100/

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