serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
721 stars 517 forks source link

java.lang.NullPointerException: No BaseStepListener has been registered #1295

Closed kutzi closed 6 years ago

kutzi commented 6 years ago

Upgraded to serenity-core/serenity-cucumber 1.9.27/1.9.8 and got this already twice: (previous versions 1.9.17/1.9.7)


java.lang.NullPointerException: No BaseStepListener has been registered
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:900)
    at net.thucydides.core.steps.StepEventBus.getBaseStepListener(StepEventBus.java:133)
    at net.thucydides.core.steps.StepEventBus.updateCurrentStepTitle(StepEventBus.java:578)
    at cucumber.runtime.formatter.SerenityReporter.handleTestStepStarted(SerenityReporter.java:306)
    at cucumber.runtime.formatter.SerenityReporter.lambda$new$3(SerenityReporter.java:119)
    at cucumber.runner.EventBus.send(EventBus.java:28)
    at cucumber.api.TestStep.run(TestStep.java:79)
    at cucumber.api.TestCase.run(TestCase.java:58)
    at cucumber.runner.Runner.runPickle(Runner.java:80)
    at cucumber.runtime.Runtime.runFeature(Runtime.java:119)
    at cucumber.runtime.Runtime.run(Runtime.java:104)
    at cucumber.runtime.Runtime$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at SerenityMain.run(SerenityMain.groovy:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
    at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151)
    at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:197)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:217)
    at SerenityMain.main(SerenityMain.groovy:26)```
kutzi commented 6 years ago

Will downgrade and check if the error really disappears

wakaleo commented 6 years ago

Could you check with 1.9.28 and 1.9.10 to see if the error disappears? 1.9.28 is built with cucumber 3.0.0. Failing that, I will roll back the 3.0.0 upgrade.

cliviu commented 6 years ago

hi @kutzi , please provide also a small project to reproduce the issue. How are you running the tests ?

kutzi commented 6 years ago

@cliviu sorry, but that would be very much down on my priority list to provide a test project. So don't expect there anythig soon

kutzi commented 6 years ago
 private static byte run(String[] argv, ClassLoader classLoader) throws IOException {
        RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList<String>(asList(argv)))

        ResourceLoader resourceLoader = new MultiLoader(classLoader)
        Configuration systemConfiguration = Injectors.getInjector().getInstance(Configuration.class)
        Runtime runtime = CucumberWithSerenity
                .createSerenityEnabledRuntime(resourceLoader, classLoader, runtimeOptions, systemConfiguration)
        runtime.run()
        return runtime.exitStatus()
    }

That's how we start Serenity. If you have any specific question, please let me know.

To create a compehensive, small project to reproduce the issue - I currently lack the time for that. Sorry

wakaleo commented 6 years ago

@kutzi is there a reason you are not running the tests through Maven or Gradle?

cliviu commented 6 years ago

@kutzi your way of starting Serenity will not work anymore with the new version. I will take a look to see if I can find an alternative

mrcjbf commented 6 years ago

did anyone figure out this error yet? I am still running into it. I have tried everything in this thread and every link I can find online and I can't make any progress. in the class StepEventBus.class, this method, the baseStepListener is always null:

public void updateOverallResults() { this.baseStepListener.updateOverallResults(); }

java.lang.NullPointerException at net.thucydides.core.steps.StepEventBus.updateOverallResults(StepEventBus.java:686) at net.serenitybdd.screenplay.EventBusInterface.updateOverallResult(EventBusInterface.java:29) at net.serenitybdd.screenplay.Actor.perform(Actor.java:115) at net.serenitybdd.screenplay.Actor.attemptsTo(Actor.java:86) at net.serenitybdd.screenplay.Actor.has(Actor.java:73)

wakaleo commented 6 years ago

Are you running the tests with the Serenity runner?

mrcjbf commented 6 years ago

I am using a test runner file

wakaleo commented 6 years ago

Are you trying to run the tests with TestNG?

mrcjbf commented 6 years ago

yes. I'm trying to set them up to run nightly through jenkins, and I am getting some guidance from another dev at my job, and he said all I need to do is figure out how to run the features by running that testng xml file

wakaleo commented 6 years ago

Serenity doesn’t support TestNG

mrcjbf commented 6 years ago

no way really? no wonder I haven't been able to figure it out. do you know if there is a way to run the features in a similar way, from an xml file through jenkins, using junit?

wakaleo commented 6 years ago

Just don’t extend the TestNG base class and run with the JUnit runner insteas

kutzi commented 6 years ago

Back to the original issue: @cliviu did you already manage to find a new way how I could run it?

cliviu commented 6 years ago

@kutzi currently we have switched back to Cucumber 2.x.x

kutzi commented 6 years ago

That means that it should work again?

cliviu commented 6 years ago

Yes, with 1.9.30/1.9.12

kutzi commented 6 years ago

I upgraded to 1.9.30/1.9.12 and immediately encountered the issue again

wakaleo commented 6 years ago

Can you provide a sample project? We are not seeing this problem locally.

kutzi commented 6 years ago

Sorry, but I probably won't find the time to provide a sample project sometime soon

kutzi commented 6 years ago

What I don't get from the reading code: is the baseStepListener optional or not? That seems to hint that it's optional

/**
     * A reference to the base step listener, if registered.
     */
    private BaseStepListener baseStepListener;

but in the codepath from the stacktrace it's not handled as this, i.e. getBaseStepListener() is called without checking isBaseStepListenerRegistered() first

kutzi commented 6 years ago

I found out that this always, consistently happens for the same feature file. I'll share the content of the file - stripped from all potential confidential content - in case it helps:

Feature:
    Make sure that the xyz rewrite rules still work.
    Description: a
    b
    c
    d

  Scenario Outline: Test if the rewrite anchor points are still present on a Ticket Page
    Given the customer opens the <TicketPage>
    Then validate that in the bodyElement the marker attribute mainBody is present

# TODO: adapt and re-enable these tests:
#    Then ensure that the stickyPricebarDiv contains the sticky-pricebar class attribute
#    Then ensure that the countDownDiv contains the coundown class attribute

    Examples:
    |TicketPage|
    |games.APage|
    |games.BPage|
    |games.CPage|
    |games.DPage|
wakaleo commented 6 years ago

If baseStepListener is null, your test hasn't set up Serenity correctly. If you are starting Serenity using custom logic as mentioned above, you may run into problems if the internal Serenity or Cucumber APIs change. However if this is a case, this isn't a Serenity defect but rather a usage error. We could help with this as part of one of the professional support packages (https://johnfergusonsmart.com/serenity-bdd-mentoring/) if you need further help.

I don't see anything odd in the Feature file though.

cliviu commented 6 years ago

@kutzi, the problem is that after "Feature:" you need to start with the feature description. The problem is that you start with the feature description on the next line.

cliviu commented 6 years ago

see here the gherkin doc https://docs.cucumber.io/gherkin/reference/

kutzi commented 6 years ago

Thanks @cliviu, that did the trick! Note that this did work before (in 1.9.17), but as you pointed out, this syntax was never allowed, so I wouldn't call it a regression.

erdelyizsolt commented 4 years ago

I don`t know if it is late, but try to write your feature description right after Feature: keyword...not with an Enter below...yes it is odd, but I countered with the same issue, and that was the solution...

wakaleo commented 4 years ago

That's the Gherkin syntax