Git Product home page Git Product logo

cucumber-samples's People

Contributors

bcarun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cucumber-samples's Issues

Run as application

Thanks for providing sample code. This works fine as "mvn test".

Can this be run as an application? i.e.
java -jar target\hello-springboot-cucumber-1.0.0.jar
(it starts as a normal spring-boot application with embedded tomcat, and doesn't run the test)

Passing TestContext from @ScenarioScope bean to a method in another Spring component fails

Great example of sharing test context between steps (sharing-state-between-stepdefs).

I'm using this example, which works great as long as you are within the stepdefs class, but when I pass the TestContext from the @ScenarioScope bean to another spring component, and try to access the TestContext, I'm getting an error (Cucumber version 7.2.3):

 org.springframework.beans.factory.support.ScopeNotActiveException: Error creating bean with name 'scopedTarget.myTestContext': Scope 'cucumber-glue' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: Scenario scoped beans can only be created while Cucumber is executing a scenario

So let's say I have the following @ScenarioScope class:

@ScenarioScope
@Component
public class MyTestContext {

	public TestContext getTestContext() {
		return TestContext.CONTEXT;
	}
}

An Integration test with the glue configuration:

 
/**
 * @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.mycompany.e2e.cucumber")
 * @ConfigurationParameter(key = FEATURES_PROPERTY_NAME, value = "src/test/resources/com/mycompany/e2e/cucumber")
 */
@Suite
@SuiteDisplayName("e2e test")
@SelectClasspathResource("com/mycompany/e2e/cucumber")
@ConfigurationParameter(
		key = PLUGIN_PROPERTY_NAME,
		value="pretty, html:target/cucumber-reports/myproject-e2e.html, json:target/cucumber-reports/myproject-e2e.json")
public class MyIntegrationTest {
}

My stepdefs class:

@Slf4j
@RequiredArgsConstructor
public class MyStepDefs {

    private final MyTestContext testContext;

    // a class which contains some methods to do assertions; to some of these methods I pass the testContext;
    // accessing testContext in these methods fail with the aforementioned exception.
    private final MyStepDefAsserter asserter;
    private final TestConfiguration testConfiguration;

    @Given("a message with")
    public void givenAMessageWith(Input myInput) {
        testContext.getTestContext().set("myJsonMessage", myInput.toString());
    }

    @Then("I expect a json message")
    public void thenIExcpectAJsonMessage() {
        asserter.assertMyJsonMessage(testContext);
    }
}

And the MyStepDefAsserter class:

@Slf4j
@Component
@RequiredArgsConstructor
public class MyStepDefAsserter {

    private final MyStepDefsHelper helper;
    private final TestConfiguration testConfiguration;

   public void assertMyJsonMessage(MyTestContext testContext) {
        final var myJsonMessage = testContext.getTestContext().get("myJsonMessage"); // this is where it fails with aforementioned exception
        // assertions here
    }
}

Any idea why this fails? Am I missing some configuration here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.