Hello,

That is the issue :) It seems like the driver is null at that point. But have 
no clue why and how to solve it.

Any help is very much appreciated!
Roy

From: louis gueye [mailto:[email protected]]
Sent: woensdag 20 februari 2013 10:38
To: [email protected]
Subject: Re: [jbehave-user] Configure Custom reporter by Spring config XML file

Hi Roy,

When I checkout the project I get a NullPointerException at at 
org.google.web.common.MyWebDriverScreenshotOnFailure.saveScreenshotTo(MyWebDriverScreenshotOnFailure.java:81)

Is it the expected behaviour?

2013/2/20 Roy de Kleijn 
<[email protected]<mailto:[email protected]>>
Sure,

I can't put the actual code online, because it's confidential. But I made a 
small project with exactly the same components and dependencies.

https://github.com/roydekleijn/Spring-Jbehave-WebDriver-Example

You can actually execute the code if you establish a Selenium grid on your 
localhost. You can then execute the following Maven command: mvn 
integration-test -Dgroup=google
It contains failing tests (on purpose), because on failure a screenshot should 
be made and included in the report.

This is what I like to achieve:

-          I like to run my tests in multiple threads (this already works)

-          I like to have reports including screenshots of the failing tests. 
(this doesn't work yet)

Any help is much appreciated!

Best regards,
Roy


From: Mauro Talevi 
[mailto:[email protected]<mailto:[email protected]>]
Sent: dinsdag 19 februari 2013 21:48
To: [email protected]<mailto:[email protected]>
Subject: Re: [jbehave-user] Configure Custom reporter by Spring config XML file

Can you please put your project somewhere on github so it can be cloned and 
debugged?

On 19/02/2013 19:15, Roy de Kleijn wrote:
I appreciate your help,

But there were no reports generated:
this is the output message [INFO] Generating reports view to <projectname>' 
using formats '[]' and view properties


This is how the runner looks like:
public class RunWebStories extends JUnitStories {
  private WebDriverProvider driverProvider = new SeleniumWebDriverProvider();
  private static final Logger LOG = Logger.getLogger(RunWebStories.class);
  private Configuration configuration;

  public RunWebStories() {
    Embedder embedder = configuredEmbedder();

    embedder.embedderControls().doGenerateViewAfterStories(true)
        .doIgnoreFailureInStories(true).doIgnoreFailureInView(true)
        .doVerboseFiltering(true);
    //embedder.useExecutorService(MoreExecutors.sameThreadExecutor());
  }

  @Override
  public Configuration configuration() {
    configuration = makeConfiguration(this.getClass(),
        driverProvider);
    return configuration;
  }

  public static Configuration makeConfiguration(Class<?> embeddableClass,
      WebDriverProvider driverProvider) {
    Properties viewResources = new Properties();
    viewResources.put("decorateNonHtml", "true");

    ParameterConverters parameterConverters = new ParameterConverters();

    ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(
        new LocalizedKeywords(),
        new LoadFromClasspath(embeddableClass), parameterConverters);
    parameterConverters.addConverters(new DateConverter(
        new SimpleDateFormat("yyyy-MM-dd")),
        new ExamplesTableConverter(examplesTableFactory));

    SeleniumConfiguration seleniumConfig = new SeleniumConfiguration();

    seleniumConfig.useWebDriverProvider(driverProvider);
    seleniumConfig.useStoryLoader(new 
LoadFromClasspath(embeddableClass.getClassLoader()));

    StoryReporterBuilder reporter = new StoryReporterBuilder();
    reporter.withCodeLocation(
        CodeLocations
            .codeLocationFromClass(embeddableClass));
        //.withDefaultFormats()
        //.withFormats(new ScreenshootingHtmlFormat(driverProvider), XML, 
CONSOLE, TXT);
    reporter.withRelativeDirectory(
        "jbehave/"
          + System.getProperty("conceptName")
          + "/"
          + System.getProperty("siteId")
        );
    seleniumConfig
        .useFailureStrategy(new FailingUponPendingStep())
        // .useStepMonitor(new SeleniumStepMonitor(contextView,
        // seleniumContext, new SilentStepMonitor()))
        .useStoryReporterBuilder(reporter)
        .useParameterConverters(parameterConverters);// new
    // SeleniumContextOutput(seleniumContext),
    return seleniumConfig;
  }

  @Override
  public InjectableStepsFactory stepsFactory() {
    ApplicationContext context = new SpringApplicationContextFactory(
        "org/spilgames/" + System.getProperty("conceptName")
          + "/config/config.xml").createApplicationContext();
    return new SpringStepsFactory(configuration(), context);
  }

  @Override
  protected List<String> storyPaths() {

      return new StoryFinder().findPaths(
          codeLocationFromClass(this.getClass()),
          "**/" + System.getProperty("conceptName")
            + "/newStories/*.story", "**/excluded*.story");

  }
}


and this is how the Spring Configuration looks like:
 <bean id="screenshot" class="org.spilgames.ScreenshootingHtmlFormat">
    <constructor-arg ref="provider" />
    <constructor-arg value="SCREENSHOT" />
  </bean>

  <bean
    class="org.jbehave.core.configuration.spring.SpringStoryReporterBuilder"
    init-method="withDefaultFormats">
    <property name="formats">
      <list>
        <ref bean="screenshot" />
        <value>CONSOLE</value>
        <value>TXT</value>
        <value>XML</value>
      </list>
    </property>
  </bean>


Any strange thing here ?
________________________________
Van: louis gueye [[email protected]<mailto:[email protected]>]
Verzonden: dinsdag 19 februari 2013 18:21
Aan: [email protected]<mailto:[email protected]>
Onderwerp: Re: [jbehave-user] Configure Custom reporter by Spring config XML 
file
Hi Roy,

It should run out-of-the-box if your org.spilgames.ScreenshootingHtmlFormat 
extends org.jbehave.core.reporters.Format


Something like this should work.
class org.spilgames.ScreenshootingHtmlFormat extends 
org.jbehave.core.reporters.Format {
private
                WebDriver driverProvider;
ScreenshootingHtmlFormat (WebDriver driverProvider, String name) {
        super(name);
        this.driverProvider = driverProvider;
    }
}
<bean id="screenshot" class="org.spilgames.ScreenshootingHtmlFormat">
                      <constructor-arg ref="provider" />
                      <constructor-arg value="SCREENSHOT" />
                    </bean>


<bean
    class="org.jbehave.core.configuration.spring.SpringStoryReporterBuilder"
    init-method="withDefaultFormats">
    <property name="formats">
      <list>
        <ref bean="screenshot"/>

        <value>CONSOLE</value>
        <value>TXT</value>
        <value>XML</value>
      </list>
    </property>
  </bean>



2013/2/19 Roy de Kleijn 
<[email protected]<mailto:[email protected]>>
Thanks for your quick feedback ?

Where should I do that ? inside the spring configuration file ?
Can it also be done outside of spring config XML file ? and How should that 
look like ?


In some way the tests are running again, but I still get an error when a 
screenshot is made. driver = null


<bean id="screenshot" class="org.spilgames.ScreenshootingHtmlFormat">
    <constructor-arg ref="provider" />
  </bean>
  <bean
    class="org.jbehave.core.configuration.spring.SpringStoryReporterBuilder"
    init-method="withDefaultFormats">
    <property name="formats">
      <list>
        <ref bean="screenshot"/>

        <value>CONSOLE</value>
        <value>TXT</value>
        <value>XML</value>
      </list>
    </property>
  </bean>
This will let the test run, but gives me the driver = null error;

________________________________
Van: louis gueye [[email protected]<mailto:[email protected]>]
Verzonden: dinsdag 19 februari 2013 14:12
Aan: [email protected]<mailto:[email protected]>
Onderwerp: Re: [jbehave-user] Configure Custom reporter by Spring config XML 
file
Hi Roy,

Spring supports implicit conversion from string to Enum.
Other formats are Enum.
I guess you won't be able to inject non Enum value unless your init-method (i.e 
withDefaultFormats) supports it.
I would pass a list of String as parameter to withDefaultFormat method and then 
convert each string into the right formatter instance then store it.


--
Cordialement/Regards,

Louis GUEYE
linkedin<http://fr.linkedin.com/in/louisgueye> | 
blog<http://deepintojee.wordpress.com/> | 
twitter<http://twitter.com/#%21/lgueye>


2013/2/19 Roy de Kleijn 
<[email protected]<mailto:[email protected]>>
Hello,

I have the following question.

I implemented a custom reporter format 
(http://jaroslav-sedlacek.blogspot.nl/2011/05/screenshots-in-jbehave-reports.html)
 which creates a screenshot on failure and add a link to the reports. Which 
works fine when using a single thread.

This is how I configured it in a class which extends from JUnitStories:

    StoryReporterBuilder reporter = new StoryReporterBuilder();
    reporter.withCodeLocation(
        CodeLocations
            .codeLocationFromClass(embeddableClass))
        .withFormats(new ScreenshootingHtmlFormat(driverProvider), XML, 
CONSOLE, TXT);

This doesn't work when using multiple threads. Which seems to be logical since 
the driverProvider is null.

So I added this custom reporter to the spring configuration xml file. This is 
actually the place where I distribute the driverProvider. I see that the 
screenshots are being made (file are stored in a folder). However the HTML 
reports are not generated properly.

So I tried to move the StoryReporterBuilder to the spring configuration file is 
well: so it looks like this:

  <bean id="screenshot" class="org.spilgames.ScreenshootingHtmlFormat">
    <constructor-arg ref="provider" />
  </bean>

  <bean
    class="org.jbehave.core.configuration.spring.SpringStoryReporterBuilder"
    init-method="withDefaultFormats">
    <property name="formats">
      <list>
        <value>CONSOLE</value>
        <value>TXT</value>
        <value>screenshot</value>
        <value>XML</value>
      </list>
    </property>
  </bean>

However this doesn't work for customformats. Is there a workaround? or is there 
another to do this ? How can I define the custom format in the Spring 
Configuration XML file?

The first bean in the above example is working (screenshots are being made)
The second bean needs some modification, because it gets stuck at the third 
parameter.


Any help is appreciated!

Thanks,
Roy









--
Cordialement/Regards,

Louis GUEYE
linkedin<http://fr.linkedin.com/in/louisgueye> | 
blog<http://deepintojee.wordpress.com/> | 
twitter<http://twitter.com/#%21/lgueye>




--
Cordialement/Regards,

Louis GUEYE
linkedin<http://fr.linkedin.com/in/louisgueye> | 
blog<http://deepintojee.wordpress.com/> | 
twitter<http://twitter.com/#%21/lgueye>

Reply via email to