g.pickardou
g.pickardou

Reputation: 35973

Selenium WebDriver with ChromeDriver - C# Visual Studio 2012. Debugging impossible

Few lines program perfectly works if running with ctrl+F5 (not debugging) but throws exception when running with F5 (debugging):

private static void Main(string[] args)
{
    IWebDriver driver = new ChromeDriver(@"C:\Program Files (x86)\ChromeDriver");

This statement throws "No connection could be made because the target machine actively refused it" exception with no inner exception.

Again, it works perfectly with ctrl-f5

Why is this difference between debugging and running without debugging? (I know that debugger has a host process please do not explain that)

How can I run this simple program in debug mode?

Any ideas? Thx in advance

Upvotes: 1

Views: 13999

Answers (2)

leady
leady

Reputation: 11

I had this error at one point as well..and after hours of debugging..finally got the real error to show...my view for the I.E. browser was set at 125%...and when I changed it back to 100%...it worked. :)

Upvotes: 0

g.pickardou
g.pickardou

Reputation: 35973

Thanks for all who spent time with reading and thinking about this question. I've solved it. Well, it's a stupid thing but I am pretty sure that similar questions here complaining Selenium WebDriver and

"No connection could be made because the target machine actively refused it" exception

has this resolution, and other answers there missed the correlation between the issued solved and taken actions. Most of them suggest use other version of ChromeDriver.exe and talking about version incompatibility and ChromeDriver.exe bugs.

I think (at least my case) these resolutions are false.

The "error" comes from the WebDriver assembly and not about ChromeDriver.exe. I've examined the source of WebDriver, here it is:

while (!processStarted && DateTime.Now < timeout)
{
   try
   {
      request.GetResponse();
      processStarted = true;
   }
      catch (WebException)
   {
}

When the DriverService class starts the ChromeDriver.exe immediately starts polling it with requests. Because it takes time the process to start, the port is not open for the first few dozen try... (at least a Sleep(10) or Sleep(50) would be nice here, but anyway)

Now the point: If you are so unlucky, you not checked the VS 2012 Options/Debug/General 'Enable Just My Code' and you checked the Debug/Exceptions/Thrown then debugger will break by this exception, but of course you will not see the source, the exception line will be your line

IWebDriver driver = new ChromeDriver(@"C:\Program Files (x86)\ChromeDriver");

Depending on timing (process start), you can get couple repeated time, and you will think your port, firewall, ChromeDriver.exe version, etc has to do with the exception.

Upvotes: 3

Related Questions