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

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
Windows 7 x64
VS 2012
Using Selenium WebDriver NuGet Packcge 2.35 (latest)
Using ChromeDriver.exe (v2.4.226107) (latest)
All firewalls and antivrus etc was killed.
Running VS as admin and UAC turned off
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

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.

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. :)

Related

Unable to start program, Access is denied C# net6.0

I have this issue where some of the projects I created for.Net6 throws the error shown in the image attached
In this instance the project was running fine, suddenly, the error started to pop up. I have tried to find a solution by myself and on the internet.
I have used different IDEs VS 2022, ReSharper, VS Code, and the error persists.
This started when I installed VS 2022 and .Net6 SDK. Was formally using VS 2019.
Any help?
So, what I have done so far was to do a system reset. Everything was working well until a couple of hours now. I tried to use CMD as admin to run. I would like to point out that I have a couple of projects on the solution, but one keeps throwing this error.
System.ComponentModel.Win32Exception (5): An error occurred trying to start process 'C:\Users\xxxxxxxxxxxxx\source\repos\ProjectTemplate2022v3\src\Skoruba.Duende.IdentityServer.Admin\bin\Debug\net6.0\Skoruba.Duende.IdentityServer.Admin.exe' with working directory 'C:\Users\xxxxxxxxxxxxx\source\repos\ProjectTemplate2022v3\src\Skoruba.Duende.IdentityServer.Admin'. Access is denied.
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at Microsoft.DotNet.Cli.Utils.Command.Execute(Action`1 processStarted)
at Microsoft.DotNet.Cli.Utils.Command.Execute()
at Microsoft.DotNet.Tools.Run.RunCommand.Execute()
at Microsoft.DotNet.Tools.Run.RunCommand.Run(String[] args)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)
at Microsoft.DotNet.Cli.Program.Main(String[] args)
I had the same problem and later figured out that Windows Security (Defender) was blocking the executable.
Go to Windows Security -> Virus and Threat protection settings -> Exclusions and add your exe to the exclusion list.
I just had the same problem. Quick fix for me to get it to run is to run using "IISExpress".. See below picture.

Chrome failed to start: crashed in Selenium testing

I am using C# Selenium for automated testing, and after the most recent chromedriver update 89.0.4389.2300, Google chrome starts and crashes right away. The weirdest thing is that when I am running it on my local, everything works fine, but I am also using Azure pipelines to run my tests on a server. The server one gives me this:
OpenQA.Selenium.WebDriverException : unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
I have googled around and tried things like adding chromeOptions.AddArgument("--no-sandbox") and chromeOptions.AddArguments("disable-dev-shm-usage") but nothing helps. Chrome on my server is updated to the correct version too. The tests run headless.
Anyone else is having this issue?
The error mentions that chromedriver could not bind to open debug port on running Chrome.
Possible cases I met with:
old version of Chrome browser or chromedriver - since some version the port has changed
wrong Chrome binary location (chromedriver is looking for C:\Program Files (x86)\Google\Chrome\Application\chrome.exe)

Selenium protect ports [duplicate]

My Chrome browser is updated to version 78 and when I tried to execute any code of automation, it shows the error
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1573451703.668][WARNING]: Timed out connecting to Chrome, retrying...
Nov 11, 2019 11:25:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[1573451709.039][WARNING]: Timed out connecting to Chrome, retrying...
How can I fix it?
This error message...
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1573451703.668][WARNING]: Timed out connecting to Chrome, retrying...
Nov 11, 2019 11:25:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[1573451709.039][WARNING]: Timed out connecting to Chrome, retrying...
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Analysis
The first log message:
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
is part of the startup log when using ChromeDriver and is informative in nature.
You can find a detailed discussion in How do I protect the ports that chromedriver use?
The following log message:
[1573451703.668][WARNING]: Timed out connecting to Chrome, retrying...
indicates there are some incompatibility between the version of the binaries you are using.
Solution
Ensure that:
JDK is upgraded to current levels JDK 8u222.
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v78.0 level.
Chrome is updated to current Chrome Version 78.0 level. (as per ChromeDriver v78.0 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
(WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
(LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
I have fixed this issue of timeout / Connection reset by changing my code from:
public void AfterScenario(Scenario sc) {
driver.close();
driver.quit();
driver = null;
}
to:
public void AfterScenario(Scenario sc) {
driver.quit();
driver = null;
}
So basically I removed the driver.close() and this fixed my issue. I do not know why this is happening, but experts can explain more...
I had to update to the dev version of chrome 79 and the latest dev version of chromedriver to make it work. Although I've run against other issues with this version, so I don't know if its a good solution.

SystemUnathorizedAccessException: Access to the path is denied in Visual Studio Code on Mac

I am working on building a Discord bot for a class using C#, but for whatever reason when I try to run my group's code after cloning it, I keep getting:
System.UnauthorizedAccessException' occurred in
System.Private.CoreLib.dll: 'Access to the path
'/Users/ajgoddu/Desktop/Projects/CS3141/Scrum-Bot/ScrumBot/ScrumBot/bin/Debug/netcoreapp2.1'
is denied.
The lines causing the exception:
static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
I'm using a Macbook Pro, on OSX Mojave 10.14.1.
I am running the latest version of VS Code, as well as .NET and mono, and have made sure that the folders in questions are not read-only. I have even tried running VS code with sudo, to no avail.
Anyone able to help? I've tried many different fixes as well as reinstalled .NET, mono, and VS multiple times.
Use this Process Explorer to identify which process is blocking that DLL to be used and throwing unauthorized exception; you can kill that process and then running; or may be you'll get to know the problem.

Is MonoDevelop remote debugging works on Windows

I'm using mono-2.6.7 and monodevelop-2.4, my OS is Windows 7.
I'm trying to implement a remote debugger for my own runtime (based on mono, mono is embedded in it, used lang - C#) in a way it's done by Novell for Moonlight.
Unfortunately, no success...
After clicking "Debug" in MonoDevelop:
IDE is put into debug state,
my runtime starts,
successfully sends DWP-Handshake to listening IDE
and then connection terminates and Debugging ends.
For some reasons (absolutely not clear for me) IDE doesn't send a handshake after recieving it from my runtime but simply terminates a connection.
The code i use is in another question: Can't use Mono Soft Debugger Remote Debugging because 'debugger-agent: DWP handshake failed' error
Does smb know if it can be done the save way it's done for Moonlight? Or it's it's impossible? Maybe there is another solution?
Prooved! It works. The problem was in unhandled exception thrown by VirtualMachineManager.ListenInternal(2) method in Mono.Debugger.Soft. More details here - Can't use Mono Soft Debugger Remote Debugging because 'debugger-agent: DWP handshake failed' error

Categories

Resources