gpt4 book ai didi

java - Allure:如果子步骤失败,如何使父步骤失败?

转载 作者:行者123 更新时间:2023-12-01 23:42:39 25 4
gpt4 key购买 nike

我有诱惑监听器,它报告所有 Selenium 化物断言,但在失败的情况下,只有子步骤被标记为失败。报告中尚不清楚

监听者:

@Override
public void beforeEvent(final LogEvent event) {
lifecycle.getCurrentTestCaseOrStep().ifPresent(parentUuid -> {
final String uuid = UUID.randomUUID().toString();
lifecycle.startStep(parentUuid, uuid, new StepResult().setName(event.toString()));
});
}

@Override
public void afterEvent(final LogEvent event) {
lifecycle.getCurrentTestCaseOrStep().ifPresent(parentUuid -> {
switch (event.getStatus()) {
case PASS:
lifecycle.updateStep(step -> step.setStatus(Status.PASSED));
break;
case FAIL:
if (saveScreenshots) {
getScreenshotBytes()
.ifPresent(bytes -> lifecycle.addAttachment("Screenshot", "image/png", "png", bytes));
}
if (savePageHtml) {
getPageSourceBytes()
.ifPresent(bytes -> lifecycle.addAttachment("Page source", "text/html", "html", bytes));
}
if (!logTypesToSave.isEmpty()) {
logTypesToSave
.forEach((logType, level) -> {
final byte[] content = getBrowserLogs(logType, level).getBytes(UTF_8);
lifecycle.addAttachment("Logs from: " + logType, "application/json", ".txt", content);
});
}
lifecycle.updateStep(stepResult -> {
stepResult.setStatus(getStatus(event.getError()).orElse(Status.BROKEN));
stepResult.setStatusDetails(getStatusDetails(event.getError()).orElse(new StatusDetails()));
});
break;
default:
LOGGER.warn("Step finished with unsupported status {}", event.getStatus());
break;
}
lifecycle.stopStep();
});
}

}

报告截图:

enter image description here正如您所看到的,父步骤被标记为已通过。

最佳答案

通过多次失败当前步骤解决了此问题

Allure.getLifecycle().updateStep(stepResult -> stepResult.setStatus(Status.FAILED));
Allure.getLifecycle().stopStep();
Allure.getLifecycle().updateStep(stepResult -> stepResult.setStatus(Status.FAILED));
Allure.getLifecycle().stopStep();
Allure.getLifecycle().updateStep(stepResult -> stepResult.setStatus(Status.FAILED));
Allure.getLifecycle().stopStep();

这不是完成这项工作的好方法,但对我来说效果很好

有用的视频https://www.youtube.com/watch?v=d5gjK6hZHE4&feature=youtu.be如果你懂俄语

关于java - Allure:如果子步骤失败,如何使父步骤失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59837210/

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