8000 [dotnet] use correct devtools session id after reinitialization (#13768) · SeleniumHQ/selenium@12ed6cc · GitHub
[go: up one dir, main page]

Skip to content

Commit 12ed6cc

Browse files
[dotnet] use correct devtools session id after reinitialization (#13768)
Fix regression issue, appeared in v4.17. Closing a tab breaks the devtools session Fixes #13755
1 parent 38829c7 commit 12ed6cc

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

dotnet/src/webdriver/DevTools/DevToolsSession.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,15 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
239239
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
240240
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
241241
//[DebuggerStepThrough]
242-
public Task<JToken> SendCommand(string commandName, JToken commandParameters, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
242+
public async Task<JToken> SendCommand(string commandName, JToken commandParameters, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
243243
{
244-
return SendCommand(commandName, ActiveSessionId, commandParameters, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
244+
if (this.attachedTargetId == null)
245+
{
246+
LogTrace("Session not currently attached to a target; reattaching");
247+
await this.InitializeSession().ConfigureAwait(false);
248+
}
249+
250+
return await SendCommand(commandName, this.ActiveSessionId, commandParameters, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
245251
}
246252

247253
/// <summary>
@@ -262,12 +268,6 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
262268
millisecondsTimeout = Convert.ToInt32(CommandTimeout.TotalMilliseconds);
263269
}
264270

265-
if (this.attachedTargetId == null)
266-
{
267-
LogTrace("Session not currently attached to a target; reattaching");
268-
await this.InitializeSession().ConfigureAwait(false);
269-
}
270-
271271
var message = new DevToolsCommandData(Interlocked.Increment(ref this.currentCommandId), sessionId, commandName, commandParameters);
272272

273273
if (this.connection != null && this.connection.IsActive)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using NUnit.Framework;
2+
using System.Threading.Tasks;
3+
4+
namespace OpenQA.Selenium.DevTools
5+
{
6+
using CurrentCdpVersion = V123;
7+
8+
[TestFixture]
9+
public class DevToolsTabsTest : DevToolsTestFixture
10+
{
11+
12+
[Test]
13+
[IgnoreBrowser(Selenium.Browser.IE, "IE does not support Chrome DevTools Protocol")]
14+
[IgnoreBrowser(Selenium.Browser.Firefox, "Firefox does not support Chrome DevTools Protocol")]
15+
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
16+
public async Task ClosingTabDoesNotBreakDevToolsSession()
17+
{
18+
var domains = session.GetVersionSpecificDomains<CurrentCdpVersion.DevToolsSessionDomains>();
19+
await domains.Console.Enable();
20+
var oldWindowHandle = driver.CurrentWindowHandle;
21+
driver.SwitchTo().NewWindow(WindowType.Tab);
22+
driver.SwitchTo().Window(oldWindowHandle);
23+
driver.Close();
24+
Assert.That(
25+
async () => {
26+
await domains.Console.Enable();
27+
},
28+
Throws.Nothing
29+
);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)
0