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

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

Open
jackpaul24 opened this issue Jan 29, 2024 · 3 comments

Comments

@jackpaul24
Copy link

jackpaul24 commented Jan 29, 2024

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
Copy link
Member

wakaleo commented Feb 6, 2024

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

@jackpaul24
Copy link
Author

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
Copy link
Member

wakaleo commented Feb 14, 2024

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

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

No branches or pull requests

2 participants