JBehave
  1. JBehave
  2. JBEHAVE-790

When using PerScenarioWebDriverSteps.java and GivenStories then occurs DelegateWebDriverNotFound exception

    Details

    • Type: Bug Bug
    • Status: In Progress In Progress
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: web-3.x
    • Component/s: Web Selenium
    • Labels:
      None
    • Environment:
      Apache Maven 3.0.4
      Java version: 1.6.0_26
    • Number of attachments :
      3

      Description

      When I use as life cycle steps PerScenarioWebDriverSteps and try to execute scenario which has GivenStories section then occurs DelegateWebDriverNotFound.

      What happens during executions:
      1. Firefox blank window is opened (for top level scenario?)
      2. Another firefox windows is opened and executes scenario from GivenStories section then this window is closed.
      3. Exceptions occurs.

      How to reproduce:
      1. Checkout examples etsy-selenium/java-spring
      2. Updated etsy-selenium/java-spring/src/main/resources/etsy-steps.xml with file provided in attachment.
      3. Add stories provided in attachment.
      4. Run stories with:
      mvn clean install -Dmeta.filter="+givenstories"

      Expected:
      Each scenario successfully executed in new firefox window.
      Actual:
      Failing top-level scenario.

      Console output:
      Given I am on etsy.com (FAILED)
      (org.jbehave.web.selenium.DelegatingWebDriverProvider$DelegateWebDriverNotFound: WebDriver has not been found for this thread.
      Please verify you are using the correct WebDriverProvider, with the appropriate credentials if using remote access, e.g. to SauceLabs: -DSAUCE_USERNAME=xxxxxx -DSAUCE_ACCESS_KEY=xxx-xxxx-xxxx-xxxx-xxx )
      When I want to browse through a treasury gallery (NOT PERFORMED)
      When I want to buy something from etsy.com (NOT PERFORMED)
      When I want to browse the treasury (NOT PERFORMED)
      When I choose the first treasury gallery (NOT PERFORMED)
      !-- We don't care for the results, just the gallery
      Then results will be displayed in the gallery (NOT PERFORMED)
      org.jbehave.web.selenium.PerScenarioWebDriverSteps.afterScenario() (FAILED)
      (org.jbehave.core.failures.BeforeOrAfterFailed: Method afterScenario (annotated with @AfterScenario in class org.jbehave.web.selenium.PerScenarioWebDriverSteps) failed: java.lang.NullPointerException)

      org.jbehave.core.failures.BeforeOrAfterFailed: Method afterScenario (annotated with @AfterScenario in class org.jbehave.web.selenium.PerScenarioWebDriverSteps) failed: java.lang.NullPointerException
      at org.jbehave.core.steps.StepCreator$BeforeOrAfterStep.perform(StepCreator.java:447)
      at org.jbehave.core.steps.StepCreator$BeforeOrAfterStep.doNotPerform(StepCreator.java:460)
      at org.jbehave.core.embedder.StoryRunner$SomethingHappened.run(StoryRunner.java:509)

      [WARNING] Failed to run story etsy_browse_with_givenStories.story
      org.jbehave.web.selenium.DelegatingWebDriverProvider$DelegateWebDriverNotFound: WebDriver has not been found for this thread.
      Please verify you are using the correct WebDriverProvider, with the appropriate credentials if using remote access, e.g. to SauceLabs: -DSAUCE_USERNAME=xxxxxx -DSAUCE_ACCESS_KEY=xxx-xxxx-xxxx-xxxx-xxx
      at org.jbehave.web.selenium.DelegatingWebDriverProvider.get(DelegatingWebDriverProvider.java:24)
      at org.jbehave.web.selenium.WebDriverPage.get(WebDriverPage.java:36)
      at org.jbehave.tutorials.etsy.pages.Home.go(Home.java:18)
      at org.jbehave.tutorials.etsy.steps.EtsyDotComSteps.homepageOnEtsyDotCom(EtsyDotComSteps.java:52)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jbehave.core.steps.StepCreator$ParameterisedStep.perform(StepCreator.java:537)
      at org.jbehave.core.embedder.StoryRunner$FineSoFar.run(StoryRunner.java:474)
      at org.jbehave.core.embedder.StoryRunner.runStepsWhileKeepingState(StoryRunner.java:454)
      at org.jbehave.core.embedder.StoryRunner.runScenarioSteps(StoryRunner.java:418)
      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 com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
      at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:56)
      at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:41)
      at org.jbehave.core.embedder.StoryManager.submit(StoryManager.java:198)
      at org.jbehave.core.embedder.StoryManager.runningStory(StoryManager.java:132)
      at org.jbehave.core.embedder.StoryManager.filterRunning(StoryManager.java:116)
      at org.jbehave.core.embedder.StoryManager.runningStoriesAsPaths(StoryManager.java:101)
      at org.jbehave.core.embedder.StoryManager.runStories(StoryManager.java:78)
      at org.jbehave.core.embedder.Embedder.runStoriesAsPaths(Embedder.java:202)
      at org.jbehave.core.junit.JUnitStories.run(JUnitStories.java:20)
      at org.jbehave.core.embedder.Embedder.runAsEmbeddables(Embedder.java:122)
      at org.jbehave.mojo.RunStoriesAsEmbeddables.execute(RunStoriesAsEmbeddables.java:18)
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
      at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
      at org.codehaus.plexus.classworlds

      Additional info:
      Double execution of scenario included in GivenStories is connected to JBEHAVE-789

      1. etsy_browse_with_givenStories.story
        0.4 kB
        Zbigniew Zabost
      2. etsy_browse.story
        0.4 kB
        Zbigniew Zabost
      3. etsy-steps.xml
        1 kB
        Zbigniew Zabost

        Activity

        Mauro Talevi made changes -
        Field Original Value New Value
        Assignee Mauro Talevi [ maurotalevi ]
        Fix Version/s web-3.6 [ 18388 ]
        Affects Version/s 3.6.7 [ 18494 ]
        Component/s Web Selenium [ 14124 ]
        Component/s Core [ 11086 ]
        Mauro Talevi made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Mauro Talevi added a comment -

        Let's try to decouple the two issues:

        • does it work if you use PerStoryWebDriverSteps with GivenStories?
        • does it work if you use PerScenarioWebDriverSteps without GivenStories?

        Would it be possible for you to clone the jbehave-tutorial in github and provide your modifications in different branches?

        In this way, it's much easier to see what changing wrt to a working scenario.

        Thanks

        Show
        Mauro Talevi added a comment - Let's try to decouple the two issues: does it work if you use PerStoryWebDriverSteps with GivenStories? does it work if you use PerScenarioWebDriverSteps without GivenStories? Would it be possible for you to clone the jbehave-tutorial in github and provide your modifications in different branches? In this way, it's much easier to see what changing wrt to a working scenario. Thanks
        Mauro Talevi made changes -
        Fix Version/s web-3.x [ 17273 ]
        Fix Version/s web-3.6 [ 18388 ]
        Hide
        Zbigniew Zabost added a comment -

        I have followed your advice and forked jbehave tutorial adding branches with changes.
        Looks like now error message is different but bug is similar or even the same. Anyway here are branches:

        1 "Clean state" (https://github.com/zbigniewz/jbehave-tutorial/tree/JBEHAVE-790-setup) - branch with small fixes to make etsy tests running. This branch is base every next branch. It contains 2 exactly the same stories.
        Result: when stories are executed separately they are passing, but if they are executed all together 2nd in order is failing due to

         
        org.seleniumhq.selenium.fluent.FluentExecutionStopped: remote.SessionNotFoundException during invocation of: ?.a(By.linkText: Etsy)
        

        [...]

        Caused by: org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called.
        

        2. "PerStoryWebDriverSteps with GivenStories" (https://github.com/zbigniewz/jbehave-tutorial/tree/JBEHAVE-790-PerStoryWebDriverSteps)
        Compering to 1st branch: added GivenStories
        Here there is no error, both stories are executed properly in correct order.

        3. "PerScenarioWebDriverSteps with GivenStories" (https://github.com/zbigniewz/jbehave-tutorial/tree/JBEHAVE-790-PerScenarioWebDriverSteps)
        Compering to 1st branch: added GivenStories, changed webDriverProvider to PerScenarioWebDriverSteps.
        As a result story listed in section "GivenStories" is executed properly, but then next, the main story, is failing with the same exception like for 1st branch.

        4. "PerScenarioWebDriverSteps without GivenStories" (https://github.com/zbigniewz/jbehave-tutorial/tree/JBEHAVE-790-PerScenarioWebDriverSteps-noGivens)
        Compering to 1st branch: changed webDriverProvider to PerScenarioWebDriverSteps.
        Result is the same as in 1) - 1st story executed properly, 2nd failed with the same reason.

        All tests executed with "mvn clean install -Pstable"

        Versions:
        Apache Maven 3.0.5
        Java version: 1.8.0, vendor: Oracle Corporation
        OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"
        Firefox 28.0

        Show
        Zbigniew Zabost added a comment - I have followed your advice and forked jbehave tutorial adding branches with changes. Looks like now error message is different but bug is similar or even the same. Anyway here are branches: 1 "Clean state" ( https://github.com/zbigniewz/jbehave-tutorial/tree/JBEHAVE-790-setup ) - branch with small fixes to make etsy tests running. This branch is base every next branch. It contains 2 exactly the same stories. Result: when stories are executed separately they are passing, but if they are executed all together 2nd in order is failing due to org.seleniumhq.selenium.fluent.FluentExecutionStopped: remote.SessionNotFoundException during invocation of: ?.a(By.linkText: Etsy) [...] Caused by: org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called. 2. "PerStoryWebDriverSteps with GivenStories" ( https://github.com/zbigniewz/jbehave-tutorial/tree/JBEHAVE-790-PerStoryWebDriverSteps ) Compering to 1st branch: added GivenStories Here there is no error, both stories are executed properly in correct order. 3. "PerScenarioWebDriverSteps with GivenStories" ( https://github.com/zbigniewz/jbehave-tutorial/tree/JBEHAVE-790-PerScenarioWebDriverSteps ) Compering to 1st branch: added GivenStories, changed webDriverProvider to PerScenarioWebDriverSteps. As a result story listed in section "GivenStories" is executed properly, but then next, the main story, is failing with the same exception like for 1st branch. 4. "PerScenarioWebDriverSteps without GivenStories" ( https://github.com/zbigniewz/jbehave-tutorial/tree/JBEHAVE-790-PerScenarioWebDriverSteps-noGivens ) Compering to 1st branch: changed webDriverProvider to PerScenarioWebDriverSteps. Result is the same as in 1) - 1st story executed properly, 2nd failed with the same reason. — All tests executed with "mvn clean install -Pstable" — Versions: Apache Maven 3.0.5 Java version: 1.8.0, vendor: Oracle Corporation OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac" Firefox 28.0
        Hide
        Rodrigo Machado added a comment - - edited

        Hey guys, just trying to help about that:

        I was using the version 4.0-beta9, and I didnt get this issue. After update to version 4.0-beta10, the error start happening as the same in version 3.9.4.

        Maybe you can check what were the changes from beta9 to beta10. I am trying to debug it here to find the solution, but no success so far.

        Show
        Rodrigo Machado added a comment - - edited Hey guys, just trying to help about that: I was using the version 4.0-beta9, and I didnt get this issue. After update to version 4.0-beta10, the error start happening as the same in version 3.9.4. Maybe you can check what were the changes from beta9 to beta10. I am trying to debug it here to find the solution, but no success so far.
        Hide
        Rodrigo Machado added a comment - - edited

        Hello again!

        I found the root of the problem:

        BeforeStories and AfterStories, runs in a different thread than the BeforeScenario/AfterScenario/Stories. As the implementation of the webdriver is ThreadLocal, when you try to get the webDriverProvider inside the stories it didnt find.

        A proper solution would be run all the conditions inside the same thread, then the webDriver will not generate any kind of trouble.
        .
        In my project, we overrided the webDriver, avoiding it to be ThreadLocal, and everything worked after that. But I consider this a workaround..

        Show
        Rodrigo Machado added a comment - - edited Hello again! I found the root of the problem: BeforeStories and AfterStories, runs in a different thread than the BeforeScenario/AfterScenario/Stories. As the implementation of the webdriver is ThreadLocal, when you try to get the webDriverProvider inside the stories it didnt find. A proper solution would be run all the conditions inside the same thread, then the webDriver will not generate any kind of trouble. . In my project, we overrided the webDriver, avoiding it to be ThreadLocal, and everything worked after that. But I consider this a workaround..
        Hide
        Mauro Talevi added a comment -

        The Before/AfterStories are treated as a "story" in itself, so as to allow the other stories to run in multi-threaded mode.

        What do you mean by "running all the conditions in the same thread"?

        Show
        Mauro Talevi added a comment - The Before/AfterStories are treated as a "story" in itself, so as to allow the other stories to run in multi-threaded mode. What do you mean by "running all the conditions in the same thread"?
        Hide
        Rodrigo Machado added a comment - - edited

        Let me try to explain better, sorry about the delay to answer you.

        Debugging the code, I've detected that the @BeforeStories and @AfterStories were executed in main thread. This would be fine if the WebDriver implementation was not thread local.
        On my @BeforeStories, I start my webDriver to use the browser instance in all my stories. So, the main thread creates the webDriver.

        After that the code start running the stories in the configurable thread pool, so, when the stories try to get the Webdriver, the ThreadLocal Design returns null, and then we start seeing NPE's in any WebDriver call.

        This is why we can see the failures on the PerStoriesWebDriverSteps and not in PerStoryWebDriverSteps.

        This issue was not happening on 4.0-beta-9 and start happening on 4.0-beta-10. Any thoughts?

        Show
        Rodrigo Machado added a comment - - edited Let me try to explain better, sorry about the delay to answer you. Debugging the code, I've detected that the @BeforeStories and @AfterStories were executed in main thread. This would be fine if the WebDriver implementation was not thread local. On my @BeforeStories, I start my webDriver to use the browser instance in all my stories. So, the main thread creates the webDriver. After that the code start running the stories in the configurable thread pool, so, when the stories try to get the Webdriver, the ThreadLocal Design returns null, and then we start seeing NPE's in any WebDriver call. This is why we can see the failures on the PerStoriesWebDriverSteps and not in PerStoryWebDriverSteps. This issue was not happening on 4.0-beta-9 and start happening on 4.0-beta-10. Any thoughts?

          People

          • Assignee:
            Mauro Talevi
            Reporter:
            Zbigniew Zabost
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: