Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'No BaseStepListener has been registered' while using Serenity-rest-assured #500

Closed
himukin opened this issue Aug 2, 2016 · 23 comments
Closed

Comments

@himukin
Copy link

himukin commented Aug 2, 2016

Hi,
I am trying to usering serenity-rest-assured in place of rest-assured, but i get the following exception:

java.lang.NullPointerException: No BaseStepListener has been registered

at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:226)
at net.thucydides.core.steps.StepEventBus.getBaseStepListener(StepEventBus.java:96)
at net.serenitybdd.rest.utils.RestReportingHelper.registerCall(RestReportingHelper.java:77)
at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.execute(RequestSpecificationDecorated.java:257)
at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.post(RequestSpecificationDecorated.java:72)
at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.post(RequestSpecificationDecorated.java:62)
at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.post(RequestSpecificationDecorated.java:25)
@wakaleo
Copy link
Member

wakaleo commented Aug 2, 2016

Could you provide a sample project to reproduce the issue?

@himukin
Copy link
Author

himukin commented Aug 2, 2016

Please find attached the sample project which is reproducing the issue.
serenity-rest-assured-sample.zip

@himukin
Copy link
Author

himukin commented Aug 8, 2016

were you able to reproduce the issue with the sample project?

@tunovic
Copy link

tunovic commented Oct 6, 2016

I have the similar setup as @himukin using Serenity with Serenity Rest Assured.

This the only dependencies and plugins I have in the Maven POM:

 <properties>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>

    <serenity.version>1.1.42</serenity.version>
    <serenity.cucumber.version>1.1.10</serenity.cucumber.version>
</properties>

<dependencies>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
        <version>${serenity.version}</version>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-rest-assured</artifactId>
        <version>${serenity.version}</version>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-cucumber</artifactId>
        <version>${serenity.cucumber.version}</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-json</artifactId>
        <version>2.2.2</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>net.serenity-bdd</groupId>
                        <artifactId>serenity-core</artifactId>
                        <version>${serenity.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
                <executions>
                    <execution>
                        <id>default-test</id>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

And I execute the request as following:

@Rule
private RestConfigurationRule rule = new RestConfigurationRule((RestConfigurationAction) SerenityRest::reset);

@Step
public String postOrder() {
    Response response = given().contentType("application/json")
            .when()
            .post("http://localhost:38080/order");

    return response.getHeader(HttpHeaders.LOCATION);
}

The stacktrace is also similar:

java.lang.NullPointerException: No BaseStepListener has been registered
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:228)
    at net.thucydides.core.steps.StepEventBus.getBaseStepListener(StepEventBus.java:109)
    at net.serenitybdd.rest.utils.RestReportingHelper.registerCall(RestReportingHelper.java:75)
    at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.execute(RequestSpecificationDecorated.java:257)
    at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.post(RequestSpecificationDecorated.java:72)
    at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.post(RequestSpecificationDecorated.java:25)

Any idea?

@s2oBCN
Copy link

s2oBCN commented Dec 6, 2016

I have the same issue when I'm executing the feature directly from the IDE, in my case IntelliJ. But if execute this from Gradle then it's ok.
Maybe you executed the test from the IDE?

@mszalbach
Copy link

mszalbach commented Dec 8, 2016

I have the same problem with the project at https://github.com/serenity-bdd/screenplay-pattern-todomvc. With Maven this works when running from IntelliJ it will fail because no BaseStepListener is registered. The IntelliJ runner will set Main class to cucumber.api.cli.Main and the glue to "net.serenitybdd.demos.todos.cucumber.steps net.serenitybdd.cucumber.actors". I even tried to set one manually via StepEventBus.getEventBus().registerListener() but this did not work in the IDE. Any advice what can cause this problem in the IDE?

@himukin
Copy link
Author

himukin commented Dec 8, 2016 via email

@wakaleo
Copy link
Member

wakaleo commented Dec 8, 2016

How are you running the tests in IntelliJ?

@mszalbach
Copy link

Did some more tests and seems to work when running via starting an AllRunner like this:
@RunWith(CucumberWithSerenity.class) public class AllStories {}

When starting directly from a feature file the cucumber plugin of IntelliJ will create an run config with a Cucumber Main class (cucumber.api.cli.Main). This will work for serenity tests but will fail when serenity RestAssured is involved in any step. Guess this is how the others are starting them from IntellliJ?

Exception for me is:

java.lang.NullPointerException: No BaseStepListener has been registered
java.lang.ClassCastException: net.thucydides.core.webdriver.stubs.WebDriverStub cannot be cast to org.openqa.selenium.JavascriptExecutor

I commented out all RestAssured code lines and the error is not thrown anymore. Seems the problem is always an other exception which is not correctly thrown because BaseStepListener is not correctly set when running via the IDE Cucumber Plugin. So seems to be a problem of the Cucumber Plugin since for Maven and the AllRunner everything is working. Will do some more tests tomorrow to also include screenplay but I guess this will also work as long as I start all my tests via AllStories.

@wakaleo
Copy link
Member

wakaleo commented Dec 8, 2016

Are you trying to run the tests directly from the feature files?

@mszalbach
Copy link

Yes the problems happen when running directly from the feature file.

@wakaleo
Copy link
Member

wakaleo commented Dec 8, 2016

OK, that's not supported (IntelliJ would need to know about the CucumberWithSerenity runner, which it doesn't). I don't know if there is a way to do that with IntelliJ, but it certainly won't work out of the box.

@wakaleo
Copy link
Member

wakaleo commented Dec 8, 2016

With Screenplay tests it may work better as they are more independent of instrumentation

@mszalbach
Copy link

Thanks for clarification. For me this is fine and I will go with the CucumberWithSerenity runner classes which I can be used from the IDE.

@wakaleo
Copy link
Member

wakaleo commented Dec 8, 2016

Thanks for the update.

@wakaleo wakaleo closed this as completed Dec 8, 2016
@himukin
Copy link
Author

himukin commented Dec 8, 2016 via email

@wakaleo
Copy link
Member

wakaleo commented Dec 8, 2016

@savita20
Copy link

savita20 commented Nov 7, 2018

I am also getting this same error. This is quite weird earlier I was able to run it from feature file also but not suddenly when I try to run it from feature file it is giving me this below error. I was not sure if I did something wrong in my code. I tried to debug but that didn't helped me to reach out this problem.

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)

And this is also true that if we run with CucumberWithSerenity runner classes then I can able to run it. But I am not sure if that this is the case then earlier how I was able to run it from feature file...

@wakaleo
Copy link
Member

wakaleo commented Nov 7, 2018

You cannot run a Serenity test directly from the feature file.

@letrongtanbs
Copy link

I have a same issue when run: mvn clean verify
on serenity junit webtests demo project
https://github.com/serenity-bdd/serenity-demos/tree/master/junit-webtests

@wakaleo
Copy link
Member

wakaleo commented Feb 24, 2022

I have a same issue when run: mvn clean verify on serenity junit webtests demo project https://github.com/serenity-bdd/serenity-demos/tree/master/junit-webtests

That repo is out of date and not maintained. Try with https://github.com/serenity-bdd/serenity-junit-starter.

@letrongtanbs
Copy link

but https://github.com/serenity-bdd/serenity-junit-starter. is not enough like junit-webtests

@wakaleo
Copy link
Member

wakaleo commented Feb 25, 2022

I'm not sure what you mean. Use any of the starter projects, they are up to date. The projects in the repo you mentioned are not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants