数据驱动测试中的测试设置与数据封装
1. 测试方法中的异常处理与清理
在测试过程中,当测试方法调用页面对象方法失败,且此时有窗口或对话框处于打开状态时,需要进行异常处理和清理操作,以确保不影响后续测试运行。
以下是一个示例代码,展示了如何使用 try...catch...finally
块来捕获异常并关闭相关元素:
public class CreateUserTest {
public class UserPO <M extends WebElement> {
public UserPO() throws Exception {
}
@FindBy(id = "cancel")
protected M cancel;
public void createUser(JSONObject user) throws Exception {
}
public void verifyUser(String user) throws AssertionError {
}
public WebElement getCancel() {
return cancel;
}
}
// this test method cleans up in the method
@Test
public void tc001_createUser(String RowID,