sten
sten

Reputation: 7486

Cucumber: Initilizing and then Passing data between Step-definitions?

Trying to share information between step definitions.

The problem is that using pico-container way of doing it does not work for me ....

I need the PARENT of my "initial/base" step-definition to do the initialization and the setup the context data. Then the other step-definition should reuse those variables.

I can not change the PARENT class, which is in a jar.

Also only one StepDefinition file can extend PARENT, because it does other stuff which can not be repeated (for one I should not recreate webdriver every step-def).

here is pseudo example :

class PARENT { //... init selenium webdriver ..
  WebDriver driver = new ....;
}

class StepDef1 extends PARENT {

   StepDef1(Context ctx) {
      ctx.driver = this.driver
   }

}

class StepDef2  {
   WebDriver driver;
   StepDef2(Context ctx) {
      this.driver = ctx.driver
   }
}


class StepDef3  {
   WebDriver driver;
   StepDef3(Context ctx) {
      this.driver = ctx.driver
   }
}

How can I make this work ?

Upvotes: 0

Views: 469

Answers (1)

Rahul Solanki
Rahul Solanki

Reputation: 127

You need to set your webdriver as public and asign null value to it. In this way your can make it out.

    class PARENT { //... init selenium webdriver ..
         public WebDriver driver = null;
    }

Upvotes: 1

Related Questions