Logging before or after an action?



  • I am developing web test scripts with Selenium WebDriver + Java, following the POM design pattern, and using Log4j2 for logging purposes.

    Currently, my page methods are set up like so:

    public void clickButton(){
       Log.debug("Clicking button...");
       btn.click();
       Log.info("Clicked button");
    }
    

    with a log line generated at the debug level before the action is performed, and an entry logged at the info level afterwards.

    However, after thinking about it, I am not sure that there is much point to the debug log beforehand, because if an action were to fail, I would immediately be able to pinpoint the issue by the info logs even without going to the debug level. Am I gaining much by including it or am I safe to remove it?



  • Two things can go wrong in this scenario:

    1. Button is not found (and thus you would have NullPointerException on method click()) so it will break before with NoSuchElementException.
    2. Button is not clickable (for some reasons) - and then you will have ElementNotClickableException.

    I'm not logging each step. I'm logging Exceptions on Framework level + doing screenshots on Exception or failing assertion).

    So you are safe with removing it and not gaining much (you wouldn't analyze 10000 lines of logs to check if something was logged).



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2