Why Chrome driver not opening while as an NUnit project?

1,903 views
Skip to first unread message

Janani Jeeva

unread,
May 23, 2019, 10:48:08 AM5/23/19
to Selenium Users
I have created a Console App (.NET Framework) project in my Visual Studio, added all the required packages (NUnit, Test3Adapter, Selenium) and gave the local path of my chrome.exe, and the test is running.

But, if I create an NUnit Test project (.NET Core), add all Nuget packages required and try to run my tests, I get the error stating that:

OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:/

For running my script through Azure DevOps, it's advised to use NUnit project rather than having it as Console application.

Note:

I tried adding the chrome.exe path after manually downloading it and also tried adding chrome through Nuget Packets (Both Selenium.Chrome.WebDriver or Selenium.Webdriver.ChromeDriver). Nothing worked.

Irrespective of running in GUI or headless mode, I get the same error

Sample code:

IWebDriver driver;

[SetUp]
public void startBrowser()
{
    driver = new ChromeDriver(Environment.CurrentDirectory);
}

[Test]
public void test()
{
    driver.Url = "http://www.google.co.in";
}

[TearDown]
public void closeBrowser()
{
    driver.Close();
}

Specifications: 
Selenium.WebDriver (3.141.0)
Visual Studio 2017 
NUnit (3.12.0)
NUnit3TestAdapter (3.13.0)

Mike Hetzer

unread,
May 23, 2019, 1:16:56 PM5/23/19
to Selenium Users
I do not have an issue with this in my unit test projects.
You dont really need to specify a location of the chromedriver either when you download the Selenium.Webdriver.Chromedriver Nuget package.
Sharing some code:

                private IWebDriver driver = null;

[Test]
public void MyFirstTest()
{
ChromeOptions op = new ChromeOptions();
op.LeaveBrowserRunning = true;
driver = new ChromeDriver(op);
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);





}

[TearDown]
public void TearDown()
{
// 5 seconds to see what you did on the page.
Thread.Sleep(5000);

driver.Quit();
}

John Doe

unread,
May 24, 2019, 11:02:23 PM5/24/19
to Selenium Users
  • You need to pass the location of the folder where chromedriver.exe (not chrome.exe) is present to the ChromeDriver constructor. The Chrome browser must be installed on the machine 
ChromeDriver driver = new ChromeDriver(ChromeDriverService.CreateDefaultService("/path/to/the/folder/where/chromedriver/lives"));  

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions
.AddArgument("headless");
ChromeDriver driver = new ChromeDriver(ChromeDriverService.
   
CreateDefaultService("
/path/to/the/folder/where/chromedriver/lives"), chromeOptions);  


You can also check out Selenium with C Sharp article for more information regarding configuring C# project for Selenium tests execution.
Reply all
Reply to author
Forward
0 new messages