Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] use correct devtools session id after reinitialization #13768

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions dotnet/src/webdriver/DevTools/DevToolsSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,15 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
/// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
//[DebuggerStepThrough]
public Task<JToken> SendCommand(string commandName, JToken commandParameters, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
public async Task<JToken> SendCommand(string commandName, JToken commandParameters, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
{
return SendCommand(commandName, ActiveSessionId, commandParameters, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
if (this.attachedTargetId == null)
{
LogTrace("Session not currently attached to a target; reattaching");
await this.InitializeSession().ConfigureAwait(false);
}

return await SendCommand(commandName, this.ActiveSessionId, commandParameters, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
}

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

if (this.attachedTargetId == null)
nvborisenko marked this conversation as resolved.
Show resolved Hide resolved
{
LogTrace("Session not currently attached to a target; reattaching");
await this.InitializeSession().ConfigureAwait(false);
}

var message = new DevToolsCommandData(Interlocked.Increment(ref this.currentCommandId), sessionId, commandName, commandParameters);

if (this.connection != null && this.connection.IsActive)
Expand Down
32 changes: 32 additions & 0 deletions dotnet/test/common/DevTools/DevToolsTabsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using NUnit.Framework;
using System.Threading.Tasks;

namespace OpenQA.Selenium.DevTools
{
using CurrentCdpVersion = V123;

[TestFixture]
public class DevToolsTabsTest : DevToolsTestFixture
{

[Test]
[IgnoreBrowser(Selenium.Browser.IE, "IE does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Firefox does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
public async Task ClosingTabDoesNotBreakDevToolsSession()
{
var domains = session.GetVersionSpecificDomains<CurrentCdpVersion.DevToolsSessionDomains>();
await domains.Console.Enable();
var oldWindowHandle = driver.CurrentWindowHandle;
driver.SwitchTo().NewWindow(WindowType.Tab);
driver.SwitchTo().Window(oldWindowHandle);
driver.Close();
Assert.That(
async () => {
await domains.Console.Enable();
},
Throws.Nothing
);
}
}
}
Loading