from seleniumbase import BaseCase from seleniumbase import config as sb_config import pytest import time class BaseFunctions(BaseCase): __test__ = False def start(self, browser, mobile=False): sb_config.browser = browser sb_config._browser_shortcut = browser sb_config.servername = "127.0.0.1" sb_config.port = 4444 sb_config.settings_file = "settings.py" if mobile: sb_config.mobile = mobile super().setUp() self.set_default_timeout(10) if not mobile: self.set_window_size(1920, 1080) self.open("https://musare.dev") pass def tearDown(self): self.save_screenshot_to_logs("Final") super().tearDown() pass def login(self): self.click(".header .content-container .content .buttons .login", scroll=False) self.type(".modal .modal-card-body form .control .input[type='email']", "Test66@diffey.dev") self.type(".modal .modal-card-body form #password-visibility-container .input[type='password']", "Test66@diffey.dev") self.save_screenshot_to_logs("Login Input") self.click(".modal .modal-card-foot #actions .button.is-primary", scroll=False) self.save_screenshot_to_logs("Login Submit") self.assert_element(".nav .nav-right a[href='/settings']") pass def test_login(self): self.login() pass def test_go_to_station(self): self.login() self.click(".station-card[href='/music']", scroll=False) self.assert_element("#station-inner-container #video-container #stationPlayer") self.save_screenshot_to_logs("Go to station") pass def test_go_to_all_stations(self): self.login() self.assert_element(".group.bottom .station-card:not(.createStation)") applications = self.execute_script(""" var stations = []; document.querySelectorAll(".group.bottom .station-card:not(.createStation)").forEach(function(station) { var text = station.querySelector(".card-content .media .displayName h5"); if(text && text.innerText && station.hasAttribute("href")) { stations.push({ "text": text.innerText, "href": station.getAttribute("href") }); } }); return stations; """) for el in applications: self.click(f".group.bottom .station-card[href='{el['href']}']") self.sleep(3) self.save_screenshot_to_logs(f"Station {el['text']}") self.click(".nav-item.is-brand", scroll=False) self.assert_element(".header .content-container") pass def test_go_to_station_logged_out(self): self.click(".station-card[href='/music']", scroll=False) self.assert_element("#station-inner-container #video-container #stationPlayer") self.save_screenshot_to_logs("Go to station logged out") pass def test_player_controls(self): self.login() self.click(".station-card[href='/music']", scroll=False) buttonContainer = "#station-inner-container #station-right-column #control-bar-container " self.click(f"{buttonContainer}#left-buttons button#local-pause", scroll=False) self.save_screenshot_to_logs("Local pause") self.click(f"{buttonContainer}#left-buttons button#local-resume", scroll=False) self.save_screenshot_to_logs("Local resume") self.click(f"{buttonContainer}#left-buttons button[content='Vote to Skip Song']", scroll=False) self.assert_text("Successfully voted to skip the current song.", "#toasts-container #toasts-content") self.save_screenshot_to_logs("Vote to skip song") self.click(f"{buttonContainer}#ratings button#like-song", scroll=False) self.sleep(3) self.save_screenshot_to_logs("Like song") self.click(f"{buttonContainer}#ratings.liked button#like-song", scroll=False) self.sleep(3) self.save_screenshot_to_logs("Unlike song") self.click(f"{buttonContainer}#ratings button#dislike-song", scroll=False) self.sleep(3) self.save_screenshot_to_logs("Dislike song") self.click(f"{buttonContainer}#ratings.disliked button#dislike-song", scroll=False) self.sleep(3) self.save_screenshot_to_logs("Undislike song") self.assert_element("#ratings button#dislike-song :not(.disliked)") pass def test_playlist_station(self): self.login() self.click(".station-card[href='/music']", scroll=False) self.click("#station-inner-container #station-left-column #sidebar-container #tabs-container #tab-selection .button:nth-child(3)", scroll=False) self.assert_element("#station-inner-container #station-left-column #sidebar-container #tabs-container #my-playlists") self.save_screenshot_to_logs("Open My Playlists") self.click("#station-inner-container #station-left-column #sidebar-container #tabs-container #my-playlists .create-playlist", scroll=False) self.type(".modal .modal-card-body .control .input[placeholder='Enter display name...']", f"Test - {int(time.time())}") self.sleep(5) self.save_screenshot_to_logs("Create Playlist Input") self.click(".modal .modal-card-foot .button.is-info", scroll=False) self.assert_element(".modal.is-active.edit-playlist-modal") self.assert_text("Successfully created playlist", "#toasts-container #toasts-content") pass @pytest.mark.flaky(reruns=3) class Firefox(BaseFunctions): __test__ = True def setUp(self): self.start("firefox") pass @pytest.mark.flaky(reruns=3) class Chrome(BaseFunctions): __test__ = True def setUp(self): self.start("chrome") pass @pytest.mark.flaky(reruns=3) class FirefoxMobile(BaseFunctions): __test__ = True def setUp(self): self.start("firefox", True) pass @pytest.mark.flaky(reruns=3) class ChromeMobile(BaseFunctions): __test__ = True def setUp(self): self.start("chrome", True) pass