gpt4 book ai didi

selenium - 使用 TestNG 仅重试特定的失败测试

转载 作者:行者123 更新时间:2023-12-02 04:25:05 28 4
gpt4 key购买 nike

如何仅执行特定的失败测试。通过使用“IRetryAnalyzer”,我们可以重新运行失败的测试 x 次。正如这里提到的Restart failed test case automatically 。我还实现了 iTestListener,通过遵循 Retry Only failed Tests 使测试计数更有意义。和 update test run count by implementing 'ITestListener'

有什么方法可以仅重新运行特定的失败测试。

示例:我们只需要执行因 NoSuchElementException 和 TimeoutException 而失败的测试。

请查看下面的屏幕截图,其中总共 8 个测试失败,其中有 6 个测试因 NoSuchElementException-1 和 TimeoutException-5 失败。 enter image description here

请帮忙。

最佳答案

您可以通过检查测试结果来进行尝试,例如:

@Override
public boolean retry(ITestResult result) {
try {
if (result.getThrowable().toString()
.contains("NoSuchElementException")) // Checking for specific reasons of failure
if (retryCount < maxRetryCount) {
retryCount++;
return true;
}
return false;
} catch (Exception e) {
return false;
}
}

由于每个结果都有一个属性m_throwable,以防发生异常,因此您可以使用它在 Retry 类中完成任务。

关于selenium - 使用 TestNG 仅重试特定的失败测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27677442/

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