cucumber / cucumber-jvm

Cucumber for the JVM
https://cucumber.io
MIT License
2.7k stars 2.02k forks source link

Need help to handle Cucumber Test Steps #1474

Closed Sourabh25 closed 6 years ago

Sourabh25 commented 6 years ago

Hi,

I have a requirement to handle the cucumber steps . Now in the implementation, the TestCase class in the cucumber.runner package is private.

I want to do something like below:

void run(EventBus bus) {
        boolean skipNextStep = this.dryRun;
        Long startTime = bus.getTime();
        bus.send(new TestCaseStarted(startTime, this));
        ScenarioImpl scenarioResult = new ScenarioImpl(bus, pickleEvent);

        for (HookTestStep before : beforeHooks) {
            Result stepResult = before.run(bus, pickleEvent.pickle.getLanguage(), scenarioResult, dryRun);
            skipNextStep |= !stepResult.is(Result.Type.PASSED);
            scenarioResult.add(stepResult);
        }

        for (TemplatePickleStepTestStep step : testSteps) {
            **System.out.println("Step Text+"+step.getStepText());**
            Result stepResult = step.run(bus, pickleEvent.pickle.getLanguage(), scenarioResult, skipNextStep);
            skipNextStep |= !stepResult.is(Result.Type.PASSED);
            scenarioResult.add(stepResult);
        }

        for (HookTestStep after : afterHooks) {
            Result stepResult = after.run(bus, pickleEvent.pickle.getLanguage(), scenarioResult, dryRun);
            scenarioResult.add(stepResult);
        }

        Long stopTime = bus.getTime();
        bus.send(new TestCaseFinished(stopTime, this, new Result(scenarioResult.getStatus(), stopTime - startTime, scenarioResult.getError())));
    }

Please let me know is there a way I can achieve it.

Thanks, Sourabh

mpkorstanje commented 6 years ago

I am guessing you are trying to make a report of the executed steps. Check out the existing implementations of the Plugin interface.

Sourabh25 commented 6 years ago

Thanks for your response. @mpkorstanje Yes you are right. I am trying to make a report of the executed steps.

I don't follow what you mean by implementations of Plugin Interface. Could you please elaborate a bit.

Thanks, Sourabh

mpkorstanje commented 6 years ago

For example https://github.com/cucumber/cucumber-jvm/blob/master/core/src/main/java/cucumber/runtime/formatter/PrettyFormatter.java

It's what prints the pretty output when you use --plugin pretty or the equivalent in @CucumberOptions.

Sourabh25 commented 6 years ago

My code in the runner is testNGCucumberRunner.runScenario(pe); where pe is the PickleEvent. Now this will run the entire scenario.

While executing the scenario how can i handle the steps even using PrettyFormatter. Kindly advise @mpkorstanje

mpkorstanje commented 6 years ago

When you create the testNGCucumberRunner you provide it with a class argument. The @CucumberOptions annotation from this class are used to configure cucumber.

Have a look at the testng example: https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator-testng

For the right usage of testNGCucumberRunner have a look at the class the runner extends: https://github.com/cucumber/cucumber-jvm/blos b/master/testng/src/main/java/cucumber/api/testng/AbstractTestNGCucumberTests.java

But this isn't really the right place to get help for using Cucumber.

Sourabh25 commented 6 years ago

@mpkorstanje So as per the link https://github.com/cucumber/cucumber-jvm/blob/master/testng/src/main/java/cucumber/api/testng/AbstractTestNGCucumberTests.java

we have the below code @Test(groups = "cucumber", description = "Runs Cucumber Scenarios", dataProvider = "scenarios") public void runScenario(PickleEventWrapper pickleWrapper, CucumberFeatureWrapper featureWrapper) throws Throwable { // the 'featureWrapper' parameter solely exists to display the feature file in a test report testNGCucumberRunner.runScenario(pickleWrapper.getPickleEvent()); }

so in this step, testNGCucumberRunner.runScenario(pickleWrapper.getPickleEvent()); is there any way , i can handle the steps in the scenario. If not can I get an api to access these step.

Please let me know if my question or requirement is not clear

aslakhellesoy commented 6 years ago

Please use the support forums for questions and discussions. We use GitHub issues to track bugs and contributions exclusively.

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.