Renish K.R
Renish K.R

Reputation: 17

How to get current BDD step in QAF?

I'm writing a custom report in QAF and I want to pass the current BDD step with parameters into my custom report. I'm looking to implement both inside StepDefinition code and listener.

I have tried the below code inside Step Definition.

TestBaseProvider.instance().get().getContext().getProperty("current.teststep")

EDITED:

@QAFTestStep(description = "Test step")
public void testStep() {
    System.out.println("===CURRENT Test Step ===> "+ 
    getBundle().getPropertyValue("current.teststep"));
}

OUTPUT:

===CURRENT Test Step ===> current.teststep

Upvotes: 0

Views: 114

Answers (1)

user861594
user861594

Reputation: 5908

current.teststep property will return step currently under execution or last completed one if no step in execution state. You can use step listener.

If you want to create custom reporting, best way is to implement TestCaseResultUpdator interface. Here you can find few reporting examples with TestCaseResultUpdator implementation.

EDIT: similar to the example in question, below code works fine for me:

    @MetaData("{'isSetup':true}")
    @QAFTestStep(description = "Test Step-1")
    public static void step1() {
        TestStep step = (TestStep) TestBaseProvider.instance().get().getContext().getProperty("current.teststep");
        Map<String, Object> metadata = step.getMetaData();
        Reporter.log("metadata: " + metadata);
    }

In example above meta-data is optional, just added to demonstrate additional meta-data feature, available with step. Here is report: step report

Again, this is not right way for reporting. For reporting either step listener or result listener should be used.

Upvotes: 0

Related Questions