I'm using JBehave with Serenity BDD but I've implemented log4j2 (Serenity
BDD already provides slf4j facade) so your log entries may look prettier
using {} placeholders, also log4j2 allows you to set the log level to
debug, and customize the messages, having class and method logged easily
without implementing reflection stuff.
Hope this help you.
El lunes, 31 de julio de 2017, 5:51:12 (UTC-3), SpeedMax Alice escribió:
>
> Hey,
>
> Right now I need to log some runtime info like api response body,
> selenium log in steps and bind it to the actual performed steps
> I've check all the possible way I can but got nothing.
> Anybody can give me a hint?
>
> My solution right now is ugly and only works when steps throw
> exception(commonly exception create by Assert Library).
>
>
> @Then("search '$item' on Ebay with quotes")
> public void searchItemOnEbayWithQuotes(@Named("item")String item) throws
> Exception {
> s(log -> {
> new HomePage().search(item);
> log.info("SEARCH ITEM " + item + " ON EBAY SITE.");
> log.info("SEARCH ITEM " + item + " ON EBAY SITE.");
> log.info("SEARCH ITEM " + item + " ON EBAY SITE.");
> log.info("SEARCH ITEM " + item + " ON EBAY SITE.");
> throw new Exception("test exception");
> });
> }
>
> void s(stepCallable callable) throws Exception {
> LOGGER logger = LOGGER.newLOGGER();
> try {
> callable.apply(logger);
> } catch (Exception e ) {
> throw new Exception("\n\t" + logger.toString());
> }
> }
>
> @FunctionalInterface
> public interface stepCallable {
> void apply(LOGGER logger) throws Exception;
> }
>
>
> In the demo you can see:
>
> - a callable called stepCallable
> - a step wrapper function called s to wrap step code into lambda and
> rebuild a new exception with customized log and throw it out
>
> finally the log will be stored into steps's UUIDExceptionWrapper
>
> this is the only way I found to keep runtime info into performed steps.
>
>
> If anyone have a better way to do similar thing, just comment down blow.
> Actually I need runtime info inside steps, not after or before hook.
> thanks!
>
--
You received this message because you are subscribed to the Google Groups
"JBehave User" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send an email to [email protected].
To view this discussion on the web, visit
https://groups.google.com/d/msgid/jbehave-user/acf10590-c736-457f-a1c8-24f5f1d8f9c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.