Please consider this 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 as IJavaScriptExecutor;
}
return Instance;
}
static string GetGoogleChromeDriverPath()
{
return Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Is it good approach to use Singleton for Driver instance ?
Edit:
public sealed class Driver
{
private Driver() { }
public static IWebDriver Instance { get { return Nested.instance; } }
private class Nested
{
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Nested() { }
internal static readonly IWebDriver instance = new ChromeDriver(GetGoogleChromeDriverPath());
}
static string GetGoogleChromeDriverPath()
{
return Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
}
}
So as Zohar Peled
suggested i change it to this version.
How can i add IJavaScriptExecutor
instance to my class ?