如何在catch块中assert.fail之后继续执行

uujelgoq  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(421)

我的代码块在assert.fail之后被终止。但是我需要继续执行以使登录页可用于下一个测试用例
我尝试了处理,在正常执行后使用assert.fail,但是在没有发生实际失败的地方捕获了登录页面的屏幕截图

public void getActivityApprovalPending() {
    try {
        wait.until(ExpectedConditions.visibilityOf(activity));
        assertEquals(activity.getText(),"Approval Pending");
        viewTransaction.click();
    } catch (AssertionError e) {
        executor.executeScript("arguments[0].scrollIntoView();", amp.user);
        amp.getUser();
        amp.getLogout();
        Assert.fail("Transaction not in approval pending activity");
    }
}
toe95027

toe950271#

如果要在Assert失败后继续执行,请使用软Assert而不是Assert(它称为硬Assert)。

// Create an Soft assert type object
SoftAssert softassert = new SoftAssert();

可以使用任何Assert方法:例如。

softassert.fail("I am fail")
// It will cause failure but cont. executing next lines of code.

相关问题