Implementation:SeleniumHQ Selenium HasVirtualAuthenticator
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, WebAuthn, VirtualAuthenticator |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
The HasVirtualAuthenticator interface defines the contract for WebDriver implementations that support the W3C Virtual Authenticator API for WebAuthn testing.
Description
HasVirtualAuthenticator is a capability interface implemented by browser drivers that support creating and managing virtual authenticators. It provides two methods: one to add a virtual authenticator with specified options, and one to remove a previously added authenticator. This interface enables automated testing of WebAuthn/FIDO2 authentication flows without requiring physical security keys.
Usage
Use HasVirtualAuthenticator by casting a WebDriver instance to this interface when you need to set up or tear down virtual authenticators for WebAuthn testing. The driver must support the Virtual Authenticator protocol extension.
Code Reference
Source Location
- Repository: SeleniumHQ_Selenium
- File: java/src/org/openqa/selenium/virtualauthenticator/HasVirtualAuthenticator.java
Signature
public interface HasVirtualAuthenticator {
VirtualAuthenticator addVirtualAuthenticator(VirtualAuthenticatorOptions options);
void removeVirtualAuthenticator(VirtualAuthenticator authenticator);
}
Import
import org.openqa.selenium.virtualauthenticator.HasVirtualAuthenticator;
I/O Contract
Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
addVirtualAuthenticator |
VirtualAuthenticatorOptions options |
VirtualAuthenticator |
Creates and registers a new virtual authenticator with the given configuration options. Returns the newly created authenticator instance. |
removeVirtualAuthenticator |
VirtualAuthenticator authenticator |
void |
Removes a previously added virtual authenticator. The authenticator becomes invalid after removal and no further methods should be called on it. |
Usage Examples
// Cast the driver to HasVirtualAuthenticator
HasVirtualAuthenticator authDriver = (HasVirtualAuthenticator) driver;
// Create options for the virtual authenticator
VirtualAuthenticatorOptions options = new VirtualAuthenticatorOptions()
.setProtocol(VirtualAuthenticatorOptions.Protocol.CTAP2)
.setTransport(VirtualAuthenticatorOptions.Transport.USB)
.setHasResidentKey(true)
.setHasUserVerification(true)
.setIsUserVerified(true);
// Add a virtual authenticator
VirtualAuthenticator authenticator = authDriver.addVirtualAuthenticator(options);
// Perform WebAuthn operations...
authenticator.addCredential(credential);
// Clean up after testing
authDriver.removeVirtualAuthenticator(authenticator);
Related Pages
- SeleniumHQ_Selenium_VirtualAuthenticator - The authenticator instance returned by
addVirtualAuthenticator - SeleniumHQ_Selenium_VirtualAuthenticatorOptions - Configuration passed to
addVirtualAuthenticator - SeleniumHQ_Selenium_WebAuthn_Credential - Credentials managed by the virtual authenticator