inheritance - Static methods called with base class property in specflow step from definition file refer to property as null -
i have global base class in solution of tests inherit from, class contain public iwebdriver property. project base class inherit solution base class , initialize iwebdriver property. stepdeffinition class inherit project base class , beforescenario property call project base class testinitialize initialize iwebdriver.
the global base class have testcleanup tag close iwebdriver session uses static method 1 of properties of method iwebdriver, when static method called iwebdriver value null (inside method), although when passed it wasn't.
why static method sees null??
[testclass] public class solutiontestbase { public iwebdriver webdriver { get; protected set; } [testcleanup] public void subbasetestcleanup() { if (webdriver != null) { webdriverfactory.quitfromwebdriver(webdriver, testsettings); } } } [testclass] public class projectbasetest : solutiontestbase { public void initialize() { webdriver = webdriverfactory.getdriverfromconfig(currbrowser.name, testcontext); } } [binding] public class stepdefinitions : projectbasetest { [beforescenario("consoleanalytics"), datasource(browsersref)] public void beforeanalyticsscenario() { initialize(); } } public class webdriverfactory { public static void quitfromwebdriver(iwebdriver webdrivers, testsettings testsettings, int milliseconds = 200) { if (/*some code*/) { /* * * code * */ } else if (testsettings == testsettings.local) { webdrivers.quit(); } } }
you shouldn't mix test setup/cleanup infrastructure between specflow , mstest. specflow test generation tool. generate [test]
, [testcleanup]
methods , classes should not use them.
if want things happen after tests should use specflow infrastructure ie use [afterscenario]
tag in specflow
Comments
Post a Comment