test.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. from seleniumbase import BaseCase
  2. from seleniumbase import config as sb_config
  3. import pytest
  4. import time
  5. class BaseFunctions(BaseCase):
  6. __test__ = False
  7. def start(self, browser, mobile=False):
  8. sb_config.browser = browser
  9. sb_config._browser_shortcut = browser
  10. sb_config.servername = "127.0.0.1"
  11. sb_config.port = 4444
  12. sb_config.settings_file = "settings.py"
  13. if mobile:
  14. sb_config.mobile = mobile
  15. super().setUp()
  16. self.set_default_timeout(10)
  17. if not mobile:
  18. self.set_window_size(1920, 1080)
  19. self.open("https://musare.dev")
  20. pass
  21. def tearDown(self):
  22. self.save_screenshot_to_logs("Final")
  23. super().tearDown()
  24. pass
  25. def login(self):
  26. self.click(".header .content-container .content .buttons .login", scroll=False)
  27. self.type(".modal .modal-card-body form .control .input[type='email']", "Test66@diffey.dev")
  28. self.type(".modal .modal-card-body form #password-visibility-container .input[type='password']", "Test66@diffey.dev")
  29. self.save_screenshot_to_logs("Login Input")
  30. self.click(".modal .modal-card-foot #actions .button.is-primary", scroll=False)
  31. self.save_screenshot_to_logs("Login Submit")
  32. self.assert_element(".nav .nav-right a[href='/settings']")
  33. pass
  34. def test_login(self):
  35. self.login()
  36. pass
  37. def test_go_to_station(self):
  38. self.login()
  39. self.click(".station-card[href='/music']", scroll=False)
  40. self.assert_element("#station-inner-container #video-container #stationPlayer")
  41. self.save_screenshot_to_logs("Go to station")
  42. pass
  43. def test_go_to_all_stations(self):
  44. self.login()
  45. self.assert_element(".group.bottom .station-card:not(.createStation)")
  46. applications = self.execute_script("""
  47. var stations = [];
  48. document.querySelectorAll(".group.bottom .station-card:not(.createStation)").forEach(function(station) {
  49. var text = station.querySelector(".card-content .media .displayName h5");
  50. if(text && text.innerText && station.hasAttribute("href")) {
  51. stations.push({
  52. "text": text.innerText,
  53. "href": station.getAttribute("href")
  54. });
  55. }
  56. });
  57. return stations;
  58. """)
  59. for el in applications:
  60. self.click(f".group.bottom .station-card[href='{el['href']}']")
  61. self.sleep(3)
  62. self.save_screenshot_to_logs(f"Station {el['text']}")
  63. self.click(".nav-item.is-brand", scroll=False)
  64. self.assert_element(".header .content-container")
  65. pass
  66. def test_go_to_station_logged_out(self):
  67. self.click(".station-card[href='/music']", scroll=False)
  68. self.assert_element("#station-inner-container #video-container #stationPlayer")
  69. self.save_screenshot_to_logs("Go to station logged out")
  70. pass
  71. def test_player_controls(self):
  72. self.login()
  73. self.click(".station-card[href='/music']", scroll=False)
  74. buttonContainer = "#station-inner-container #station-right-column #control-bar-container "
  75. self.click(f"{buttonContainer}#left-buttons button#local-pause", scroll=False)
  76. self.save_screenshot_to_logs("Local pause")
  77. self.click(f"{buttonContainer}#left-buttons button#local-resume", scroll=False)
  78. self.save_screenshot_to_logs("Local resume")
  79. self.click(f"{buttonContainer}#left-buttons button[content='Vote to Skip Song']", scroll=False)
  80. self.assert_text("Successfully voted to skip the current song.", "#toasts-container #toasts-content")
  81. self.save_screenshot_to_logs("Vote to skip song")
  82. self.click(f"{buttonContainer}#ratings button#like-song", scroll=False)
  83. self.sleep(3)
  84. self.save_screenshot_to_logs("Like song")
  85. self.click(f"{buttonContainer}#ratings.liked button#like-song", scroll=False)
  86. self.sleep(3)
  87. self.save_screenshot_to_logs("Unlike song")
  88. self.click(f"{buttonContainer}#ratings button#dislike-song", scroll=False)
  89. self.sleep(3)
  90. self.save_screenshot_to_logs("Dislike song")
  91. self.click(f"{buttonContainer}#ratings.disliked button#dislike-song", scroll=False)
  92. self.sleep(3)
  93. self.save_screenshot_to_logs("Undislike song")
  94. self.assert_element("#ratings button#dislike-song :not(.disliked)")
  95. pass
  96. def test_playlist_station(self):
  97. self.login()
  98. self.click(".station-card[href='/music']", scroll=False)
  99. self.click("#station-inner-container #station-left-column #sidebar-container #tabs-container #tab-selection .button:nth-child(3)", scroll=False)
  100. self.assert_element("#station-inner-container #station-left-column #sidebar-container #tabs-container #my-playlists")
  101. self.save_screenshot_to_logs("Open My Playlists")
  102. self.click("#station-inner-container #station-left-column #sidebar-container #tabs-container #my-playlists .create-playlist", scroll=False)
  103. self.type(".modal .modal-card-body .control .input[placeholder='Enter display name...']", f"Test - {int(time.time())}")
  104. self.sleep(5)
  105. self.save_screenshot_to_logs("Create Playlist Input")
  106. self.click(".modal .modal-card-foot .button.is-info", scroll=False)
  107. self.assert_element(".modal.is-active.edit-playlist-modal")
  108. self.assert_text("Successfully created playlist", "#toasts-container #toasts-content")
  109. pass
  110. @pytest.mark.flaky(reruns=3)
  111. class Firefox(BaseFunctions):
  112. __test__ = True
  113. def setUp(self):
  114. self.start("firefox")
  115. pass
  116. @pytest.mark.flaky(reruns=3)
  117. class Chrome(BaseFunctions):
  118. __test__ = True
  119. def setUp(self):
  120. self.start("chrome")
  121. pass
  122. @pytest.mark.flaky(reruns=3)
  123. class FirefoxMobile(BaseFunctions):
  124. __test__ = True
  125. def setUp(self):
  126. self.start("firefox", True)
  127. pass
  128. @pytest.mark.flaky(reruns=3)
  129. class ChromeMobile(BaseFunctions):
  130. __test__ = True
  131. def setUp(self):
  132. self.start("chrome", True)
  133. pass