#!/usr/bin/env python3 # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at https://mozilla.org/MPL/2.0/. import os import random import tempfile import time from basic_tests import SnapTestsBase from selenium.common.exceptions import TimeoutException from selenium.webdriver.common.action_chains import ActionChains 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.select import Select class QATests(SnapTestsBase): def __init__(self): self._dir = "qa_tests" super().__init__( exp=os.path.join( self._dir, f"qa_expectations_{self._distro_release()}.json" ) ) def _distro_release(self): with open("/etc/lsb-release") as lsb_release: f = list( filter( lambda x: x.startswith("DISTRIB_RELEASE"), lsb_release.read().split(), ) ) return f[0].split("=")[1].replace(".", "") def _test_audio_playback( self, url, iframe_selector=None, click_to_play=False, video_selector=None ): self._logger.info(f"open url {url}") if url: self.open_tab(url) if iframe_selector: self._logger.info("find iframe") iframe = self._wait.until( EC.visibility_of_element_located((By.CSS_SELECTOR, iframe_selector)) ) self._driver.switch_to.frame(iframe) self._logger.info("find video") video = self._wait.until( EC.visibility_of_element_located( (By.CSS_SELECTOR, video_selector or "video") ) ) self._wait.until(lambda d: type(video.get_property("duration")) is float) assert video.get_property("duration") > 0.0, "