Implementation:SeleniumHQ Selenium HasCasting
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, Chromium_Browser |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
HasCasting is a Java interface that provides methods for discovering, connecting to, and controlling Cast devices (such as Chromecast) from Chromium-based browsers via the Chrome media router.
Description
The HasCasting interface, annotated with @Beta, defines six methods for Cast device interaction: getCastSinks() retrieves the list of available Cast devices as ID/Name pairs, selectCastSink(String) selects a target device for media routing, startDesktopMirroring(String) initiates full desktop mirroring to a device, startTabMirroring(String) mirrors only the current browser tab, getCastIssueMessage() returns any error message from an active Cast session, and stopCasting(String) disconnects from a specified device. This interface is implemented by Chromium-based driver classes such as ChromeDriver and EdgeDriver.
Usage
Use HasCasting when automating tests that involve Cast functionality, such as verifying that a web application can discover and stream to Cast-enabled devices. Cast the driver to HasCasting to access these methods.
Code Reference
Source Location
- Repository: SeleniumHQ_Selenium
- File: java/src/org/openqa/selenium/chromium/HasCasting.java
Signature
@Beta
public interface HasCasting {
List<Map<String, String>> getCastSinks();
void selectCastSink(String deviceName);
void startDesktopMirroring(String deviceName);
void startTabMirroring(String deviceName);
String getCastIssueMessage();
void stopCasting(String deviceName);
}
Import
import org.openqa.selenium.chromium.HasCasting;
I/O Contract
Methods
| Method | Parameters | Return Type | Description |
|---|---|---|---|
getCastSinks() |
none | List<Map<String, String>> |
Returns the list of available Cast sink targets. Each entry is a map containing ID and Name keys for the device. |
selectCastSink(String) |
deviceName -- name of the target Cast device |
void |
Selects a Cast sink as the recipient of media router intents (connect or play). |
startDesktopMirroring(String) |
deviceName -- name of the target Cast device |
void |
Initiates full desktop mirroring for the current browser tab on the specified device. |
startTabMirroring(String) |
deviceName -- name of the target Cast device |
void |
Initiates tab-only mirroring for the current browser tab on the specified device. |
getCastIssueMessage() |
none | String |
Returns an error message if there is any issue in the current Cast session. |
stopCasting(String) |
deviceName -- name of the target Cast device |
void |
Stops casting from the media router to the specified device, if connected. |
Usage Examples
ChromeDriver driver = new ChromeDriver();
// Cast the driver to HasCasting
HasCasting castingDriver = (HasCasting) driver;
// Discover available Cast devices
List<Map<String, String>> sinks = castingDriver.getCastSinks();
for (Map<String, String> sink : sinks) {
System.out.println("Device: " + sink.get("name") + " (ID: " + sink.get("id") + ")");
}
// Select a device and start tab mirroring
if (!sinks.isEmpty()) {
String deviceName = sinks.get(0).get("name");
castingDriver.selectCastSink(deviceName);
castingDriver.startTabMirroring(deviceName);
// Check for any casting issues
String issue = castingDriver.getCastIssueMessage();
if (issue != null && !issue.isEmpty()) {
System.err.println("Cast issue: " + issue);
}
// Stop casting when done
castingDriver.stopCasting(deviceName);
}
driver.quit();
Related Pages
- SeleniumHQ_Selenium_HasCdp -- Interface for executing Chrome DevTools Protocol commands
- SeleniumHQ_Selenium_HasNetworkConditions -- Interface for simulating network conditions
- SeleniumHQ_Selenium_HasLaunchApp -- Interface for launching Chromium apps
- Selenium Chrome Documentation