java - Shared WebDriver becomes null on second scenario using PicoContainer -


i have used accepted solution here , came following code:

referenced libraries:

pico_ref_libs

feature:

feature: featurea    scenario: scenarioa     given      when         scenario: scenariob     given      when      

basestep:

public class basestep {     protected webdriver driver = null;     private static boolean isinitialized = false;      @before     public void setup() throws exception {         if (!isinitialized) {             driver = seleniumutil.getwebdriver(configutil.readkey("browser"));             isinitialized = true;         }     }      @after     public void teardown() {         driver.quit();     }  } 

stepa:

public class stepa {     private basestep basestep = null;     private webdriver driver = null;      // picocontainer injects basestep class     public stepa(basestep basestep) {         this.basestep = basestep;     }      @given("^i @ login page$")     public void giveniamattheloginpage() throws exception {         driver = basestep.driver;         driver.get(configutil.readkey("base_url"));     }      @when     @when     @then     @then  } 

however, driver "dies" after teardown() of scenarioa , becomes null on given step of scenariob (both scenarios use same given). not using maven.

it's because of line:

private static boolean isinitialized = false; 

for each scenario, cucumber creates new instance every step file involved. hence, driver in basestep null when scenario starts.

the static isinitialized boolean not part of instance, it's bound class lives in , it's alive until jvm shuts down. first scenario sets true, meaning when second scenario starts it's still true , not reinitialize driver in setup() method.

you want make driver static share same instance both scenarios.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -