I have a test step that calls my ExecuteScript helper method which is just a wrapper around the JavaScriptExecutor ExecuteJavaScript() method:
This step works fine when I am running my test cases locally. However, it fails when sending the tests to our Selenium Grid. Unfortunately there aren't a lot of details in the failure messages and logs:
Message:
OpenQA.Selenium.WebDriverException : An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL
http://ourseleniumgrid.com:4444/session/e63d4e0ace694a095a7b9040383a651f/execute/sync. The exception message was: An error occurred while sending the request.
----> System.Net.Http.HttpRequestException : An error occurred while sending the request.
----> System.Net.WebException : The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
----> System.IO.IOException : Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
----> System.Net.Sockets.SocketException : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Stack Trace:
<ExecuteAsync>d__34.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
TaskAwaiter.ThrowForNonSuccess(Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
ConfiguredTaskAwaiter.GetResult()
<ExecuteAsync>d__63.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
TaskAwaiter.ThrowForNonSuccess(Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
TaskAwaiter`1.GetResult()
WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
WebDriver.ExecuteScriptCommand(String script, String commandName, Object[] args)
WebDriver.ExecuteScript(String script, Object[] args)
UIHelper.ExecuteScript(String script) line 230
<ExecuteTest>d__4.MoveNext() line 80
--- End of stack trace from previous location where exception was thrown ---
TaskAwaiter.ThrowForNonSuccess(Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
TaskAwaiter.GetResult()
<TestUI>d__5.MoveNext() line 83
--- End of stack trace from previous location where exception was thrown ---
TaskAwaiter.ThrowForNonSuccess(Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
GenericAdapter`1.GetResult()
AsyncToSyncAdapter.Await[TResult](Func`1 invoke)
TestMethodCommand.RunTestMethod(TestExecutionContext context)
TestMethodCommand.Execute(TestExecutionContext context)
<>c__DisplayClass1_0.<Execute>b__0()
DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
--HttpRequestException
TaskAwaiter.ThrowForNonSuccess(Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
ConfiguredTaskAwaiter.GetResult()
<MakeHttpRequest>d__37.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
TaskAwaiter.ThrowForNonSuccess(Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
ConfiguredTaskAwaiter.GetResult()
<ExecuteAsync>d__34.MoveNext()
--WebException
HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
HttpClientHandler.GetResponseCallback(IAsyncResult ar)
--IOException
NetworkStream.EndRead(IAsyncResult asyncResult)
PooledStream.EndRead(IAsyncResult asyncResult)
Connection.ReadCallback(IAsyncResult asyncResult)
--SocketException
Socket.EndReceive(IAsyncResult asyncResult)
NetworkStream.EndRead(IAsyncResult asyncResult)
I spent a lot of time trying to find answers but no luck. Spent some time with ChatGPT as well but no luck there either. I just don't know why it seems like the grid server node does not seem to want to receive that request. We have hundreds of other test cases that run fine locally and through Selenium Grid. But this one test case happens to have this ExecuteScript command to try to change a value via JavaScript. I've look at some different Chrome option arguments but haven't found anything that let's it work.