Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:SeleniumHQ Selenium HasCasting

From Leeroopedia
Revision as of 11:51, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/SeleniumHQ_Selenium_HasCasting.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

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

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment