我将 log4j(apache 软件)作为记录器添加到我的 webdriver 测试中。
我想知道 log.error 语句是否应该放在 catch block 中作为良好实践?
我们不是应该使用异常 e 对象并像这样使用 e 吗: e.printStackTrace()?
将 log.error 添加到 catch block 中是否是正确的做法?
public static WebElement destinationTextBox(WebDdriver driver){
try{
element = driver.findElement(by...) ; //this can raise exception if no element found
}
//it will be caught here
catch(NoSuchElementException e){
log.error( "no element found") ;
}
// if element found and no exception, just log 'element found'
log.info(Destination text box element found) ;
最佳答案
为什么不呢?但最好随消息一起提供原始异常,例如log.error("消息", e);
关于java - 在 webdriver 中使用 log.error 捕获没有此类元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29101416/