I have been wondering for a while, if there was a way to get all my BDD steps in one place to so that I can do a search on the existing steps. As the Library of steps grows gradually often finding existing steps becomes a lazy and tedious activity. And then we end up with multiple steps doing same things.

Jbehave reports can be ebabled to show something which is called Storynavigator. Its a client side javascript library which enabled browser to read meta data generated by cross referencing in Jbehave. Cross referencing can be enabled very easily from the configuration and it then generated the meta data which can be used by this story navigator.

How to enable cross referencing in Jbehave configuration?

 @Override
    public Configuration configuration() {
    	CrossReference xref = new CrossReference();
 
        Class embeddableClass = this.getClass();
        // Start from default ParameterConverters instance
        ParameterConverters parameterConverters = new ParameterConverters();
        // factory to allow parameter conversion and loading from external resources (used by StoryParser too)
        ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), new LoadFromClasspath(embeddableClass), parameterConverters);
        // add custom coverters
        parameterConverters.addConverters(new DateConverter(new SimpleDateFormat("yyyy-MM-dd")),
                new ExamplesTableConverter(examplesTableFactory));
        parameterConverters.addConverters(new MyConverter());
        parameterConverters.addConverters(new StudentConverter(new ExamplesTableFactory()));
 
		return new MostUsefulConfiguration()
            .useStoryLoader(new LoadFromClasspath(embeddableClass))
            .useStoryParser(new RegexStoryParser(examplesTableFactory)) 
            .useStoryReporterBuilder(new StoryReporterBuilder()
                .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass))
                .withDefaultFormats()
                .withFormats(CONSOLE, TXT, HTML, XML)
                .withCrossReference(xref))
            .useParameterConverters(parameterConverters)    
            .useStepMonitor(xref.getStepMonitor());
    }

Now the next step is to copy the JS libraries in your project and make sure they are copied in the view directory. Download the all the files and folder from here https://github.com/jbehave/jbehave-core/tree/master/jbehave-navigator/src/main/resources. Copy them under src/main/storynavigator folder in your source.

Add this confif in your POM files, so that these files are copied in the Jbehave view directory

        ${basedir}/src/main/storynavigator
        ${project.build.directory}/jbehave/view
        false

Now every run will generate a file called navigator.html inside /target/jbehave/view.

First tab is Stories, it will allow searching on story description, narrative and meta tag. Second tab is the Steps Tab, this will allow searching all the steps in your step classes.

Bit of learning – You will not see data in Stories tab for you story if no meta tags are used in the report.

 

,
Trackback

14 comments untill now

  1. Christian @ 2012-04-13 13:49

    Hello there!

    Thanks for your post; I have one problem though: I can’t get the generated page to work; Chrome rejects loading a file:// xref.json and IE9… doesn’t work for a reason not yet found out (The browser from within Eclipse isn’t helpful either).
    I do have meta tags and the .json file contains data.

    What could I be missing?

    Also, to give a little: At the download repository of JBehave there is also a jbehave-navigator JAR which can be put into the pom.xml and be extracted at e.g. generate-resources. No more need for manually putting foreign files into your project structure.

    See you!

  2. Christian @ 2012-04-13 14:24

    …sorry, to clarify: I know Chrome wont allow it because of access restrictions. And debugging the script with IE9 brings me to the same result.

    So, how can I view the report if not as a local file and Hudson/Jenkins not providing a link to the output directory?

  3. Hi,

    Thanks you for your entry. I have a problem too. Once I execute my project, I get a “NPE story not setup for CrossReference”. I do not know what I am doing wrong. Could you help me?

  4. If you want more information, my xref.json and xref.xml files have their “stepMatches” entries empty.

  5. Hi,

    Can you please share your configuration file where you can enabled the xref ? Please email me at pnakhat@gmail.com

  6. Issue resolved. I’m a noob :) . I added as a resource the “navigator” directory and then I added a directory which was called “navigation” :D

  7. I am getting this eerror while using story navigator.
    Please suggest what to do

    [WARNING] Failed to run story org/storynavigator/stories/my.story
    java.lang.NullPointerException: story not setup for CrossReference
    at org.jbehave.core.reporters.CrossReference$XRefStepMonitor.stepMatchesPattern(CrossReference.java:258)
    at org.jbehave.core.steps.StepCandidate.matches(StepCandidate.java:135)
    at org.jbehave.core.steps.StepCandidate.matches(StepCandidate.java:118)
    at org.jbehave.core.steps.MarkUnmatchedStepsAsPending.matchesCandidate(MarkUnmatchedStepsAsPending.java:148)
    at org.jbehave.core.steps.MarkUnmatchedStepsAsPending.addMatchedScenarioSteps(MarkUnmatchedStepsAsPending.java:119)
    at org.jbehave.core.steps.MarkUnmatchedStepsAsPending.collectScenarioSteps(MarkUnmatchedStepsAsPending.java:89)
    at org.jbehave.core.embedder.StoryRunner$RunContext.collectScenarioSteps(StoryRunner.java:597)
    at org.jbehave.core.embedder.StoryRunner.runScenarioSteps(StoryRunner.java:416)
    at org.jbehave.core.embedder.StoryRunner.runCancellable(StoryRunner.java:293)
    at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:211)
    at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:172)
    at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:229)
    at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:201)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

  8. Thanks for your suggestions, worked great for me! Is it just me or is your pom snippet missing some parts? Also how can I get the story runner to work with other browser except Firefox?

    Thanks for your help!

  9. On, POM it is missing the tags, for some reasons CSS is eating the XML. I will try fixing it later.

    I think these JS library dont behave vert well on other browsers. I never got time to look in to these honestly.

  10. Getting the below stack trace when I am trying to set up the navigator using crossReference.

    Failed to run story org/testframework/stories/LoginStory.story
    java.lang.NullPointerException: story not setup for CrossReference
    at org.jbehave.core.reporters.CrossReference$XRefStepMonitor.stepMatchesPattern(CrossReference.java:258)
    at org.jbehave.core.steps.StepCandidate.matches(StepCandidate.java:135)
    at org.jbehave.core.steps.StepCandidate.matches(StepCandidate.java:118)
    at org.jbehave.core.steps.MarkUnmatchedStepsAsPending.matchesCandidate(MarkUnmatchedStepsAsPending.java:148)
    at org.jbehave.core.steps.MarkUnmatchedStepsAsPending.addMatchedScenarioSteps(MarkUnmatchedStepsAsPending.java:119)
    at org.jbehave.core.steps.MarkUnmatchedStepsAsPending.collectScenarioSteps(MarkUnmatchedStepsAsPending.java:89)
    at org.jbehave.core.embedder.StoryRunner$RunContext.collectScenarioSteps(StoryRunner.java:617)
    at org.jbehave.core.embedder.StoryRunner.runScenarioSteps(StoryRunner.java:434)
    at org.jbehave.core.embedder.StoryRunner.runCancellable(StoryRunner.java:298)
    at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:212)
    at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:173)
    at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:229)
    at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:201)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

    Am using JBehave 3.7.3 and JBehave JUnit Runner from codecentric. Any suggestions?

  11. Story navigator has been broken in recent Jbehave version. I reckon it should be fixed now,

    Please see the Jbehave defect which I logged a while back

    https://jira.codehaus.org/browse/JBEHAVE-825

  12. Hi guys
    This report template ( like image) is beautiful!
    How to do create it?
    When I generate story report, is is very bad, no border table.

  13. Hi Pankaj,

    Thanks for some awesome stuff. Would be great if you can add the project into github ?

    Can you please do that

  14. Please see this guthub project its has a working example https://github.com/pnakhat/nav

Add your comment now

*

Spam protection by WP Captcha-Free