Chrome missing Widevine CDM on AWS Device Farm (testing with Selenium in Python)

71 Views Asked by At

I am running the test below that attempts to play Widevine protected video on Shaka Player demo page.

It passes when ran on local Chrome, but on AWS Device Farm the Chrome browser misses the Google Widevine Windows CDM component.

import datetime
import os
import subprocess
import boto3
import pytest

import warnings

with warnings.catch_warnings():
    warnings.filterwarnings("ignore",category=DeprecationWarning)
    import urllib3

from selenium import webdriver
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

class wait_for_the_attribute_value(object):
    def __init__(self, locator, attribute, value):
        self.locator = locator
        self.attribute = attribute
        self.value = value

    def __call__(self, driver):
        try:
            element = driver.find_element(*self.locator)
            element_attribute = element.get_attribute(self.attribute)
            return element_attribute == self.value
        except StaleElementReferenceException:
            return False

class TestGo:
    def setup_method(self, method):
        # devicefarm_client = boto3.client("devicefarm")        
        # ... here comes setup code...

        options = webdriver.ChromeOptions()
        # Note: see https://sites.google.com/chromium.org/driver/capabilities
        options.add_argument("--enable-widevine")
        options.add_experimental_option("excludeSwitches", ["disable-component-update","ignore-certificate-errors"])

        desired_cap = DesiredCapabilities.CHROME
        desired_cap["platform"] = "windows"
        desired_cap["BrowserVersion"] = "latest"
        desired_cap.update(options.to_capabilities())

        # Configure the webdriver with the appropriate remote endpoint.
        self.driver = webdriver.Remote(command_executor=testgrid_url_response["url"], desired_capabilities=desired_cap)

    def test_go_page(self):
        url = "https://harmonicinc-com.github.io/shaka-player/latest/demo/#audiolang=en-US;textlang=en-US;uilang=en-US;asset=https://storage.googleapis.com/shaka-demo-assets/angel-one-widevine/dash.mpd;panel=ALL_CONTENT;panelData=source:SHAKA,drm:WIDEVINE,MP4,DASH,VOD;build=debug_compiled"
        self.driver.get(url)

        WebDriverWait(self.driver, 5).until(
            EC.visibility_of_element_located((By.CLASS_NAME, "shaka-small-play-button"))
        )
        play_button = self.driver.find_element(By.CLASS_NAME, "shaka-small-play-button")
        play_button.click()

        video_element = self.driver.find_element(By.ID, "video")
        print("playing src: " + video_element.get_attribute("src"))
        print("readyState: " + video_element.get_attribute("readyState"))

        WebDriverWait(self.driver, 5).until(
            wait_for_the_attribute_value((By.ID, "video"), "readyState", "4")
        )

    def teardown_method(self, method):
        self.driver.quit()

I ran the next small test that simply opens "chrome://components/" scrolls down and looks for the CDM entries, and I can see that Google Widevine Windows CDM is missing

self.driver.find_element(By.XPATH, "//span[text()='Google Widevine Windows CDM']")
self.driver.find_element(By.XPATH, "//span[text()='Widevine Content Decryption Module']")

Is there a way to test Protected DRM playback on Device farm?

0

There are 0 best solutions below