Is there a way to inject dependencies in steps class?

1,015 views
Skip to first unread message

Kyoungwook Park

unread,
Apr 3, 2017, 3:13:27 AM4/3/17
to Serenity BDD Users Group
Hi, all.

AFAIK, we can automatically inject steps class with @Steps. I want to inject some other dependencies for each Steps object. I was wondering if there's a way to do it, or I can pass a dependency with constructors in Steps class. The final goal is to inject dependency like @Autowired like Spring. 

Any ideas?

John Smart

unread,
Apr 3, 2017, 3:14:55 AM4/3/17
to Kyoungwook Park, Serenity BDD Users Group
Serenity will honour the Spring @Autowired annotation - check the documentation regarding Spring integration.

--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-users+unsubscribe@googlegroups.com.
To post to this group, send email to thucydides-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
___________________________________________________
John Smart | Wakaleo Consulting  |  +44 7398 832273
Making smart teams collaborate better
http://johnfergusonsmart.com  |  john....@wakaleo.com
___________________________________________________

We love breaking down silos and helping smart teams collaborate better! Ask about our tailored on-site workshops in Agile Product Planning, BDD Requirements Discovery,  BDD, TDD and Clean Coding, and Advanced BDD Test Automation.

Need some help with Serenity BDD? Check out our Serenity BDD training and support packages here.
___________________________________________________

Kyoungwook Park

unread,
Apr 3, 2017, 11:10:25 AM4/3/17
to Serenity BDD Users Group, siri...@gmail.com


There's something wrong when I reply this mailing. I've attached the rest of the messages.

___________________________________________________

Thanks, John. I've already integrated Spring and injected a Steps object with @Autowired instead of using @Steps. In this case, Report didn't display each steps when an error occurred. For example,


class TestDefinition {

   @Autowired

   private TestSteps testSteps;


   @When("...")

   public when() {

      testSteps.step1();

      testSteps.step2(); // <- Exceptions?

   }

}


class TestSteps extends ScenarioSteps {

   @Step

   public step1() {

        // call REST API with RestAssured

   }


   @Step

   public step2() {

       // call REST API with RestAssured

   }

}


If exception occurred testSteps.step2() in when(), Report will not display result of testSteps.step1(). Just I want to know the result of sub steps.



___________________________________________________


Sorry, I misunderstood


@Autowired and @Steps are not interchangable, but you can use @Autowired inside a steps library if you set up the Spring configuration appropriately.


See More from 박경욱


-- 

___________________________________________________

John Smart | Wakaleo Consulting  |  +44 7398 832273

Making smart teams collaborate better

http://johnfergusonsmart.com  |  john....@wakaleo.com

___________________________________________________


We love breaking down silos and helping smart teams collaborate better! Ask about our tailored on-site workshops in Agile Product Planning, BDD Requirements Discovery,  BDD, TDD and Clean Coding, and Advanced BDD Test Automation.


Need some help with Serenity BDD? Check out our Serenity BDD training and support packages here.


___________________________________________________


I found the example here.


https://groups.google.com/forum/#!searchin/thucydides-users/spring%7Csort:relevance/thucydides-users/0rYgTvXuRyQ/TNbhThmAEAAJ


It have to annotate with @ContextConfiguration both parent and nested Steps.


Thanks,

Kyoungwook



___________________________________________________


On Monday, April 3, 2017 at 4:14:55 PM UTC+9, John Smart wrote:
Serenity will honour the Spring @Autowired annotation - check the documentation regarding Spring integration.
On 3 April 2017 at 08:13, Kyoungwook Park <siri...@gmail.com> wrote:
Hi, all.

AFAIK, we can automatically inject steps class with @Steps. I want to inject some other dependencies for each Steps object. I was wondering if there's a way to do it, or I can pass a dependency with constructors in Steps class. The final goal is to inject dependency like @Autowired like Spring. 

Any ideas?

--
You received this message because you are subscribed to the Google Groups "Serenity BDD Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages