diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index 0720811caba33..d9960ea97b235 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -45,7 +45,6 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds private NetworkManager network; private WebElementFactory elementFactory; private SessionId sessionId; - private String authenticatorId; private List registeredCommands = new List(); /// @@ -1046,8 +1045,8 @@ public string AddVirtualAuthenticator(VirtualAuthenticatorOptions options) { Response commandResponse = this.Execute(DriverCommand.AddVirtualAuthenticator, options.ToDictionary()); string id = commandResponse.Value.ToString(); - this.authenticatorId = id; - return this.authenticatorId; + this.AuthenticatorId = id; + return this.AuthenticatorId; } /// @@ -1057,15 +1056,15 @@ public string AddVirtualAuthenticator(VirtualAuthenticatorOptions options) public void RemoveVirtualAuthenticator(string authenticatorId) { Dictionary parameters = new Dictionary(); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); this.Execute(DriverCommand.RemoveVirtualAuthenticator, parameters); - this.authenticatorId = null; + this.AuthenticatorId = null; } /// /// Gets the virtual authenticator ID for this WebDriver instance. /// - public string AuthenticatorId { get; } + public string AuthenticatorId { get; private set; } /// /// Add a credential to the Virtual Authenticator/ @@ -1074,7 +1073,7 @@ public void RemoveVirtualAuthenticator(string authenticatorId) public void AddCredential(Credential credential) { Dictionary parameters = new Dictionary(credential.ToDictionary()); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); this.Execute(driverCommandToExecute: DriverCommand.AddCredential, parameters); } @@ -1086,7 +1085,7 @@ public void AddCredential(Credential credential) public List GetCredentials() { Dictionary parameters = new Dictionary(); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); object[] commandResponse = (object[])this.Execute(driverCommandToExecute: DriverCommand.GetCredentials, parameters).Value; @@ -1117,7 +1116,7 @@ public void RemoveCredential(byte[] credentialId) public void RemoveCredential(string credentialId) { Dictionary parameters = new Dictionary(); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); parameters.Add("credentialId", credentialId); this.Execute(driverCommandToExecute: DriverCommand.RemoveCredential, parameters); @@ -1129,7 +1128,7 @@ public void RemoveCredential(string credentialId) public void RemoveAllCredentials() { Dictionary parameters = new Dictionary(); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); this.Execute(driverCommandToExecute: DriverCommand.RemoveAllCredentials, parameters); } @@ -1141,7 +1140,7 @@ public void RemoveAllCredentials() public void SetUserVerified(bool verified) { Dictionary parameters = new Dictionary(); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); parameters.Add("isUserVerified", verified); this.Execute(driverCommandToExecute: DriverCommand.SetUserVerified, parameters); diff --git a/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs b/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs index a5a8d53d73da4..e6c16e11b673a 100644 --- a/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs +++ b/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs @@ -71,7 +71,8 @@ public void Setup() [TearDown] public void Teardown() { - if (webDriver.AuthenticatorId != null) + if (webDriver.AuthenticatorId is not null && + webDriver.SessionId is not null) { webDriver.RemoveVirtualAuthenticator(webDriver.AuthenticatorId); } @@ -186,6 +187,8 @@ public void ShouldRemoveAuthenticator() { VirtualAuthenticatorOptions options = new VirtualAuthenticatorOptions(); string authenticatorId = webDriver.AddVirtualAuthenticator(options); + Assert.That(webDriver.AuthenticatorId, Is.EqualTo(authenticatorId)); + webDriver.RemoveVirtualAuthenticator(authenticatorId); Assert.IsNull(webDriver.AuthenticatorId);