set driver variable didn’t invoke

hallo,

I try implement  below

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System;
using System.Collections.Generic;

namespace FavoWeb_AutomationTests.WrapperFactory
{
public class BrowserFactory
{
private static readonly IDictionary<string, IWebDriver> Drivers = new Dictionary<string, IWebDriver>();
private static IWebDriver driver;

public static IWebDriver Driver
{
get
{
if (driver == null)
throw new NullReferenceException(“The WebDriver browser instance was not initialized. You should first call the method InitBrowser.”);
return driver;
}
private set
{
driver = value;
}
}

public static void InitBrowser(string browserName)
{
switch (browserName)
{
case “Firefox”:
if (Driver == null)
{
driver = new FirefoxDriver();
Drivers.Add(“Firefox”, Driver);
}
break;

case “IE”:
if (Driver == null)
{
driver = new InternetExplorerDriver(@”C:\PathTo\IEDriverServer”);
Drivers.Add(“IE”, Driver);
}
break;

case “Chrome”:
if (Driver == null)
{
driver = new ChromeDriver();//@”C:\PathTo\CHDriverServer”
Drivers.Add(“Chrome”, Driver);
}
break;
}
}

public static void LoadApplication(string url)
{
Driver.Url = url;
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(“javascript:document.getElementById(‘overridelink’).click()”);
}

public static void CloseAllDrivers()
{
foreach (var key in Drivers.Keys)
{
Drivers[key].Close();
Drivers[key].Quit();
}
}
}
}

code (source from: http://toolsqa.com/selenium-webdriver/c-sharp/browser-factory-or-webdriver-factory/   )

It seems that the SET function of the driver variable is never turned on
And when I run my test case, I get the following error:
Can anyone help me with this?

Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.