Search code examples
selenium-webdrivertestngbddselenium-gridjbehave

JBehave + TestNG + Selenium Grid - generate jbehave index.html report file for each seperate selenium node when using single jbehave story file


I have a JBehave project in which need to integrate with TestNG and Selenium grid which using this, this and this code in github (sorry since i cant past the entire code so only showing the reference) i have done the JBehave + TestNG + Selenium Grid.

But my problem is when using single Story file to execute in different Selenium node the jbehave report index.html file is shown for any one node only. I want to have separate report for each node in a single or more jbehave report index.html file. I should not run with two story files and all, how can i show separate report for each and every Selenium node in a single jbehave report html file.

I know the jbehave use freemarker for their report generation but i have no clue on how to override this and show report for each selenium nodes. Any idea please share.

Thanks in Advance.


Solution

  • Finally tried a way and found it to be an temporary solution for it now.

    1. Create a String variable that gets the details in Story Runner Class.
    RemoteWebDriver driver = (RemoteWebDriver) DriverManager.getDriver();
            String hostname = hng.getHostName(driver.getSessionId());
            String browserName = driver.getCapabilities().getBrowserName();
            String browserVersion = driver.getCapabilities().getVersion();
    
    1. Then pass that value to the Story Embedded class as shown below.
    Embedder storyEmbedder = new StoryEmbedder(driver, browserName + "v" + browserVersion);
    
    1. In the Story Embedded class assign that String value as shown below
    private WebDriver driver;
        private static String name;
        public StoryEmbedder(WebDriver driver, String hostname) {
                this.driver = driver;
                this.name = hostname;
            }
    
    1. Then in the Configuration method inside the useStoryReporterBuilder function add the following code.
    .withRelativeDirectory(name) //where 'name' is the String variable refer above step.
    
    1. like the return will be as follows
    return new MostUsefulConfiguration()
                        .useStoryControls(new StoryControls().doDryRun(false).doSkipScenariosAfterFailure(false))
                        .useStoryLoader(
                                new LoadFromClasspath(embedderClass))
                        .useStoryParser(
                                new RegexStoryParser(
                                        examplesTableFactory))
                        .useStoryPathResolver(new UnderscoredCamelCaseResolver())
                        .useStoryReporterBuilder(
                                new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(embedderClass))
                                        .withDefaultFormats().withPathResolver(new ResolveToPackagedName())
                                        .withViewResources(viewResources).withReporters(new MyStoryReporter())
                                        .withFormats(Format.CONSOLE, Format.TXT, Format.HTML, Format.XML).withFailureTrace(true)
                                        .withFailureTraceCompression(true).withCrossReference(xref).withRelativeDirectory(name)).useParameterConverters(parameterConverters)
                        // use '%' instead of '$' to identify parameters
                        .useStepPatternParser(new RegexPrefixCapturingPatternParser("%"));
    

    Now i can have two folders based on browser and browser version.

    If you guys have any better answer please do help by posting it. Thanks in Advance.