NullpointerException when using multiple @Before in Cucumber-jvm -
i using cucumber-jvm.
i have init method initialize necessary stuff, such browser dimensions, application url etc. have put init method under @before (cucumber.api) tag.
@before public void initloginpage() throws exception { getbrowserdimension(); setbrowsercapabilities(); init(getapplicationurl()); }
my life fine running smoothly. now, wanted use @before tags @ scenario levels. scenario looks like:
@mytag when blah should blah-blah
and wanted use like:
@before(@mytag) public void beforescenario(){ blah = true; }
but moment give @before, starts giving nullpointerexception. tracked runbeforehooks , runhookiftagsmatch methods in cucumber's runtime class. throwing exception @before (for initloginpage()) itself. there conflict getting created multiple @before's? how can resolve this?
i found solution working. problem of @before codes getting picked in random order. wasn't based on assumption @before without parameters executed before @before("mytag").
so trick assign order parameter (in @before) value. default order gets assigned @before 10000. so, if define order value explicitly, should work.
so basically, code initializer like:
@before(order=1) public void initloginpage() throws exception { getbrowserdimension(); setbrowsercapabilities(); init(getapplicationurl()); }
that solved problem
Comments
Post a Comment