java - 如何在 catch 块中的 Assert.fail 后继续执行
问题描述
我的代码块在 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");
}
}
解决方案
如果您想在断言失败后继续执行,请使用软断言而不是断言(它称为硬断言)。
// Create an Soft assert type object
SoftAssert softassert = new SoftAssert();
可以使用任何断言方法:例如
softassert.fail("I am fail")
// It will cause failure but cont. executing next lines of code.
推荐阅读
- bash - 查找一段时间后修改的目录中所有文件的总大小
- node.js - 请求值未定义
- python - 从多列创建组
- c - 为什么我们不能在单链表的追加/插入函数的函数参数中使用单个指针?
- python - Python - 阅读 docx 维护项目符号
- accessibility - 将元素与屏幕阅读器的特定部分相关联,但在另一个部分中可见/结构上
- python - 空切片算子查询
- python - 带有for循环的dict理解中的“未正确调用DataFrame构造函数”
- django - Django 按最旧或最新的下拉菜单排序
- typescript - 在 jasmine 中调用 http get 并没有超时