java - 打印一条消息,说明元素不存在于 catch 块中,硒
问题描述
这是我的功能文件:
@Done @ProdSmoke @KioskSmoke
Scenario Outline: Add Items to the Cart and click Cancel
Given Open the application on Tablet device
When Click on the KeyInItem button
Then Enter Item Number "<upc>"
And Click Cancel
And Item "not added" in the cart
Examples:
| upctype | upc|
| upca | 8 |
这是我的 stepdef 文件:
@And("^Item \"([^\"]*)\" in the cart$")
public void itemAddedInTheCart(String action) throws Exception {
addItem.verify_itemadded(action);
}
这是我的函数 verify_itemadded(action):
public void verify_itemadded(String action) throws Exception {
try {
if (action.equals("added") && element("ItemVerify").isDisplayed()) {
Assert.assertTrue(element("ItemVerify").isDisplayed());
logger.info("Item Added");
}
}
catch (Exception ex)
{
if(action.equals("not added") && !element("ItemVerify").isDisplayed())
logger.info("Item not added");
}
}
即使测试通过,我也无法收到“未添加项目”的消息。
有任何想法吗?
解决方案
您需要更新代码如下。如果您遇到任何问题,请告诉我。
try
{
boolean isItemVerified = element("ItemVerify").isDisplayed());
if (action.equals("added") && isItemVerified )
{
logger.info("Item Added");
}
Assert.assertTrue(isItemVerified);
}
catch(AssertionError ae)
{
logger.info("Item not added");
}
推荐阅读
- python - 尝试将列表附加到数据框,并根据 ID 进行匹配
- kubernetes - Kubernetes liveness probe 日志恢复
- android - 使用二维码应用程序进行库存管理
- html - CSS 属性“box-orient”替换
- python-3.x - 如何每天在特定时间运行 apscheduler?
- javascript - 如何通过 Django Channels 实现视频通话?
- python - Python-如何从整个数据框中的日期时间数据中删除时间戳?
- javascript - 在 javascript 中读取 json 文件中包含的设置
- firefox - 如何在 Katalon 测试执行期间设置 Firefox 以不提示下载文件?
- java - JavaFX 使用 FXML 文件构建边界窗格