c# - Is it good approach to use Singleton for Driver instance? -
please consider approach:
public class driver { public static iwebdriver instance; public static ijavascriptexecutor ijavascriptexecutor; public static iwebdriver getinstance() { if (instance == null) { instance = new chromedriver(getgooglechromedriverpath()); ijavascriptexecutor = instance ijavascriptexecutor; } return instance; } static string getgooglechromedriverpath() { return path.getdirectoryname(assembly.getentryassembly().location);
is approach use singleton driver instance ?
edit:
public sealed class driver { private driver() { } public static iwebdriver instance { { return nested.instance; } } private class nested { // explicit static constructor tell c# compiler // not mark type beforefieldinit static nested() { } internal static readonly iwebdriver instance = new chromedriver(getgooglechromedriverpath()); } static string getgooglechromedriverpath() { return path.getdirectoryname(assembly.getentryassembly().location); } }
so zohar peled
suggested change version. how can add ijavascriptexecutor
instance class ?
Comments
Post a Comment