3

We are using the logging config from here and we want to add scenario id to the pattern.

I was trying to find out the answer in the documentation or on the internet but I didn't find anything about how to pass a variable (some data) from Java to logback-test.xml

In logback-test.xml we have something like this:

<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>

And we want to have something like this:

<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg - %scenarioId %n</pattern>
cheparsky
  • 514
  • 6
  • 20

1 Answers1

0

I am not aware of any way to do that in log4j / logback. If you don't find anything I say why not print it in your test and it will show up in the HTML report.

Are you actually using the parallel runner ? Normally you never need to look at logs - because even if you run in parallel, you will get a nice HTML report for each scenario.

EDIT: an idea I haven't tried, if you see the Karate Gatling readme - it mentions how you can pass the karate object into JS or Java. If you use the ScriptBridge type, it has a log(...) method that you may be able to call from Java - which should output to the same logger as the currently executing Scenario. You may be able to come up with some custom strategy to prefix the scenario-id etc and log from your selenium code.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Yes, we are actually using the parallel runner and due to this reason print doesn't help a lot and the best solution what I came up is adding scenario id to the pattern. Yes normally we should never look at logs but a nice Cucumber report doesn`t show our all selenium logs which we run from Karate. – cheparsky Jul 18 '19 at 12:39
  • Thank you for your editing and this example. We already use this approach for adding scenario id to screenshots and selenium steps. Its add our selenium steps to the Cucumber report under Karate steps and it very helps us. But I wanted to know if there is some possibility for adding scenario id to the pattern what will be a fine feature for the log. If no one doesn't give a helpfull answer I will accept your answer :) – cheparsky Jul 18 '19 at 15:01
  • @cheparsky wow you are a power user ! you should blog about your selenium approach - many will be interested – Peter Thomas Jul 18 '19 at 15:23