gpt4 book ai didi

testng - 我在我的脚本中使用软断言但是如果失败,它不会继续其余的如果脚本并移动到下一个测试用例

转载 作者:行者123 更新时间:2023-12-01 15:35:25 31 4
gpt4 key购买 nike

这是我的代码:

@Test(priority=1)
public void verifyPageTitle () throws InterruptedException
{
String Actual_title=driver.getTitle();

String Expected_title = "Abc";

SoftAssert assertion = new SoftAssert(); //Soft Assertion
System.out.println("verifyPageTitle is started");

assertion.assertEquals(Actual_title, Expected_title, "URL doesn't n
match");
assertion.assertAll();
System.out.println("verifyPageTitle is completed");
}

这里它不打印“verifyPageTitle is completed””但是断言失败。

最佳答案

参见 How To Use Soft Assert In TestNG | TestNG Tutorial .

Soft Assert – Soft Assert collects errors during @Test. Soft Assert does not throw an exception when an assert fails and would continue with the next step after the assert statement.

If there is any exception and you want to throw it then you need to use assertAll() method as a last statement in the @Test and test suite again continue with next @Test as it is.

from the TestNG API

When an assertion fails, don't throw an exception but record the failure. Calling assertAll() will cause an exception to be thrown if at least one [soft] assertion failed.

也就是说,SoftAssert#assertAll 会在调用时将任何“软断言”变成“抛出的异常”:如果有“失败的软断言”,调用assertAll,将立即终止测试的执行,从而跳过当前测试方法中的任何剩余代码。

关于testng - 我在我的脚本中使用软断言但是如果失败,它不会继续其余的如果脚本并移动到下一个测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48175781/

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