-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Description
What happened?
Hi dear developers.
So what I currently struggle with is a problem with C# Selenium with SocketException for ChromeDriver:
[09:30:07 ] OpenQA.Selenium.WebDriverException : An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL http://localhost:23391/session/9e1b9a2ff8740b399050adc85714d15d/element. The exception message was: No connection could be made because the target machine actively refused it. (localhost:23391)
09:30:07 ----> System.Net.Http.HttpRequestException : No connection could be made because the target machine actively refused it. (localhost:23391)
[09:30:07 ] ----> System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it.
I've done some digging into this to actually find what's wrong.
Setup of the test is pretty straightforward, driver is being initialized with ChromeOptions:
"--start-maximized",
"--no-sandbox",
"--proxy-server='direct://'",
"--proxy-bypass-list=*",
This error occurs not only on CI/CD but my local machine also, what's worth mentioning is that for 60+ automated test cases, the error comes usually once per run.
Configuration setup looks like this:
- ChromeDriver is being run from the package Selenium.WebDriver.ChromeDriver 113.0.5672.6300
- Test are runnig by local chromedriver -> local test, no grid, docker, or cloud is being used.
- CI/CD are running by the TeamCity agent, tests are being invoked by the usage of CommandLine with the command "dotnet test"
- All packages are up to date
- Chrome is up to date 113.0.5672.127 (64-bit)
- .NET SDK 5.0.408
- No proxy is set on the machine, on the server or the ChromeOptions
- No VPN is set on any of the machines
I've tried all the solutions I could find by searching all across the internet by found no good.
What's even funnier, the downgrade from .NET 6.0 to .NET 5.0 project reduced this error by a lot (From 3-4 crashes to 1 or none)
How can we reproduce the issue?
I cannot share the source code of my repo due to the fact that it's unallowed by my contract but I'll try to do my best to describe it.
Crash of the webdriver happens mostly at random. There's no part of the code which triggers it at the same place currently. For example, if test consists of 20 steps to do, it can fail at 1 step, 15, or even the last one.
But what I think a hint may be is one NuGet Package & few methods used.
- I'm using DotNetSeleniumExtras.WaitHelpers package in ver 3.11.0 which catches most of the time StaleElementReference exceptions, one test was waiting for an angular overlay to drop with method ExpectedConditions.InvisibilityOfElementLocated which was crashing quite often, deleting it and using Thread.Sleep(XAmmountOfTime) solved the problem.
Same thing goes for the method ExpectedConditions.UrlContains("some string of an url")
- The method that also crashes from time to time is driver.Navigate().GoToUrl("some url")
The more tests are there, the higher chance of the error to occurRelevant log output
09:30:07 Error Message:
09:30:07 OpenQA.Selenium.WebDriverException : An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL http://localhost:23391/session/9e1b9a2ff8740b399050adc85714d15d/element. The exception message was: No connection could be made because the target machine actively refused it. (localhost:23391)
09:30:07 ----> System.Net.Http.HttpRequestException : No connection could be made because the target machine actively refused it. (localhost:23391)
09:30:07 ----> System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it.
09:30:07 TearDown : OpenQA.Selenium.WebDriverException : An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL http://localhost:23391/session/9e1b9a2ff8740b399050adc85714d15d/screenshot. The exception message was: No connection could be made because the target machine actively refused it. (localhost:23391)
09:30:07 ----> System.Net.Http.HttpRequestException : No connection could be made because the target machine actively refused it. (localhost:23391)
09:30:07 ----> System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it.
09:30:07 Stack Trace:
09:30:07 at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
09:30:07 at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
09:30:07 at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
09:30:07 at OpenQA.Selenium.WebDriver.FindElement(String mechanism, String value)
09:30:07 at OpenQA.Selenium.By.<.ctor>b__11_0(ISearchContext context)
09:30:07 at OpenQA.Selenium.By.FindElement(ISearchContext context)
09:30:07 at OpenQA.Selenium.WebDriver.FindElement(By by)
09:30:07 at SeleniumExtras.WaitHelpers.ExpectedConditions.<>c__DisplayClass17_0.<InvisibilityOfElementLocated>b__0(IWebDriver driver)
09:30:07 at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition, CancellationToken token)
09:30:07 at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
09:30:07 at Eagle.Framework.Models.E2E.Wait.Until(Func`2 condition) in C:\BuildAgent\work\d20cd7016e022376\Eagle.Framework\Models\E2E\Wait.cs:line 30
09:30:07 at Eagle.Framework.PageObjects.mCalendar.mCalendar.SaveConference() in C:\BuildAgent\work\d20cd7016e022376\Eagle.Framework\PageObjects\mCalendar\mCalendar.cs:line 303
09:30:07 at Eagle.E2E.Test.StepDefinitions.mCalendarStepDefinitions.ThenKonferencjaZostajeZapisana() in C:\BuildAgent\work\d20cd7016e022376\Eagle.E2E.Test\StepDefinitions\mCalendarStepDefinitions.cs:line 302
09:30:07 at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
09:30:07 at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments, TimeSpan& duration)
09:30:07 at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance)
09:30:07 at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
09:30:07 at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
09:30:07 at Eagle.E2E.Test.Features.MKalendarz_KonferencjeFeature.ScenarioCleanup()
09:30:07 at Eagle.E2E.Test.Features.MKalendarz_KonferencjeFeature.Sale_Edycja() in C:\BuildAgent\work\d20cd7016e022376\Eagle.E2E.Test\Features\mCalendarConferences.feature:line 178
09:30:07 --HttpRequestExceptionOperating System
Windows 10, Windows Server 2016 Standard
Selenium version
C# Selenium.WebDriver 4.9.1, NUnit 3.13.3, NUnit3TestAdapter 4.4.2
What are the browser(s) and version(s) where you see this issue?
GoogleChrome 113.0.5672.127 (64-bit)
What are the browser driver(s) and version(s) where you see this issue?
Selenium.WebDriver.ChromeDriver 113.0.5672.6300
Are you using Selenium Grid?
No