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
717 stars 514 forks source link

StepInitialisationException after upgrading to serenity version 4.0.15 from 2.6.x #3385

Open jackpaul24 opened 7 months ago

jackpaul24 commented 7 months ago

What happened?

I was trying upgrade serenity version in the Test framework from 2.6.x to 4.0.15 and followed the migiration steps as outlined in https://serenity-bdd.github.io/docs/tutorials/migrating_to_serenity_4

After upgrade when i try to run a test encontered with Step InitialisationExcetion

Error message: Step failed net.serenitybdd.core.exceptions.StepInitialisationException: Failed to create step library for ConnectionSteps:Failed to create step library for EnvironmentVariables:Could not create type

ConnectionSteps.java

import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import net.serenitybdd.annotations.Step; import net.serenitybdd.annotations.Steps; import net.serenitybdd.model.environment.EnvironmentSpecificConfiguration; import net.thucydides.model.util.EnvironmentVariables;

public class ConnectionSteps extends BaseSteps {

@Steps
EnvironmentVariables environmentVariables;

@Step
public void testConnection(EnvironmentVariables environmentVariablesIn) {
    reachHost(environmentVariablesIn);
}

@Step
public void testConnection() {
    reachHost(environmentVariables);
}

private void reachHost(EnvironmentVariables environmentVariables) {
    String driverConfig = EnvironmentSpecificConfiguration.from(environmentVariables).getProperty("webdriver.driver");
    assertThat(driverConfig).isNotNull();
    logger.info("Testing connection with driver config: {}", driverConfig);
}

}

What did you expect to happen?

@wakaleo All my test are running find in the older version 2.6.x but in the 4.0.15 it started to faile due to StepInitialisationException

Serenity BDD version

4.0.15

JDK version

11

Execution environment

Local

How to reproduce the bug.

Create project with Page class extends BasePage Steps extends BaseSteps Create feature file and runner class Execute test

How can we make it happen?

Add it to the Serenity BDD backlog and wait for a volunteer to pick it up

wakaleo commented 7 months ago

You need to fetch the environment variables by calling SerenityInfrastructure.getEnvironmentVariables().

jackpaul24 commented 6 months ago

You need to fetch the environment variables by calling SerenityInfrastructure.getEnvironmentVariables().

Thanks @wakaleo , tried SerenityInfrastructure but still getting the same error 👎

`import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import net.serenitybdd.annotations.Step; import net.serenitybdd.annotations.Steps; import net.serenitybdd.model.environment.EnvironmentSpecificConfiguration; import net.serenitybdd.core.di.SerenityInfrastructure;

public class ConnectionSteps extends BaseSteps {

@Steps SerenityInfrastructure environmentVariables;

@Step public void testConnection(EnvironmentVariables environmentVariablesIn) { reachHost(environmentVariablesIn); }

@Step public void testConnection() { reachHost(environmentVariables); }

private void reachHost(EnvironmentVariables environmentVariables) { String driverConfig = EnvironmentSpecificConfiguration.from(environmentVariables).getProperty("webdriver.driver"); assertThat(driverConfig).isNotNull(); logger.info("Testing connection with driver config: {}", driverConfig); } }`

wakaleo commented 6 months ago

You shouldn't have the @Steps annotation for the EnvironmentVariable field - just use SerenityInfrastructure.getEnvironmentVariables() whenever you need the environment variables.

VaishnaviAnup commented 1 month ago

Hi, is there a resolution for this? I am also getting the same error but its not related to environment variables

Deepak3991 commented 1 week ago

I am getting NoClassDefFoundError : net/thucydides/core/ThucydidesSystemProperty error while upgrading serenity version from 2.2.2 to 4.x.x with Java 17. Any suggestions?