Owen Diffey 3 жил өмнө
parent
commit
8af5f477d2
8 өөрчлөгдсөн 327 нэмэгдсэн , 0 устгасан
  1. 101 0
      .gitignore
  2. 0 0
      __init__.py
  3. 30 0
      pytest.ini
  4. 1 0
      requirements.txt
  5. 46 0
      settings.py
  6. 9 0
      setup.cfg
  7. 107 0
      test.py
  8. 33 0
      test.sh

+ 101 - 0
.gitignore

@@ -0,0 +1,101 @@
+*.py[cod]
+*.egg
+*.egg-info
+dist
+build
+ghostdriver.log
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+lib
+lib64
+__pycache__
+.env
+.venv
+env/
+venv/
+ENV/
+VENV/
+env.bak/
+venv.bak/
+.sbase
+.sbase*
+seleniumbase_env
+seleniumbase_venv
+sbase_env
+sbase_venv
+pyvenv.cfg
+.Python
+include
+pip-delete-this-directory.txt
+pip-selfcheck.json
+ipython.1.gz
+nosetests.1
+pip-log.txt
+.swp
+.coverage
+.tox
+coverage.xml
+nosetests.xml
+.cache/*
+.pytest_cache/*
+.pytest_config
+junit
+test-results.xml
+.idea
+.project
+.pydevproject
+.vscode
+chromedriver
+geckodriver
+msedgedriver
+operadriver
+MicrosoftWebDriver.exe
+IEDriverServer.exe
+chromedriver.exe
+geckodriver.exe
+msedgedriver.exe
+operadriver.exe
+logs
+latest_logs
+log_archives
+archived_logs
+geckodriver.log
+pytestdebug.log
+latest_report
+report_archives
+archived_reports
+html_report.html
+report.html
+report.xml
+dashboard.html
+dashboard.json
+dash_pie.json
+dashboard.lock
+allure_report
+allure-report
+allure_results
+allure-results
+saved_charts
+saved_presentations
+tours_exported
+images_exported
+saved_cookies
+recordings
+visual_baseline
+selenium-server-standalone.jar
+proxy.zip
+proxy.lock
+verbose_hub_server.dat
+verbose_node_server.dat
+ip_of_grid_hub.dat
+downloaded_files
+archived_files
+assets
+temp
+temp_*/
+node_modules

+ 0 - 0
__init__.py


+ 30 - 0
pytest.ini

@@ -0,0 +1,30 @@
+[pytest]
+addopts = --capture=no -p no:cacheprovider --pdbcls=IPython.terminal.debugger:TerminalPdb
+filterwarnings =
+    ignore::pytest.PytestWarning
+    ignore:.*U.*mode is deprecated:DeprecationWarning
+junit_family = legacy
+python_files = test_*.py *_test.py *_tests.py *_suite.py
+python_classes = Test* *Test* *Test *Tests *Suite
+python_functions = test_*
+markers =
+    marker1: custom marker
+    marker2: custom marker
+    marker3: custom marker
+    marker_test_suite: custom marker
+    expected_failure: custom marker
+    local: custom marker
+    remote: custom marker
+    offline: custom marker
+    develop: custom marker
+    qa: custom marker
+    ci: custom marker
+    e2e: custom marker
+    ready: custom marker
+    smoke: custom marker
+    deploy: custom marker
+    active: custom marker
+    master: custom marker
+    release: custom marker
+    staging: custom marker
+    production: custom marker

+ 1 - 0
requirements.txt

@@ -0,0 +1 @@
+seleniumbase

+ 46 - 0
settings.py

@@ -0,0 +1,46 @@
+"""
+You'll probably want to customize this to your own environment and needs.
+For changes to take effect immediately, use Python's Develop Mode.
+Develop Mode Install: "pip install -e ."  (from the top-level directory)
+"""
+
+
+# #####>>>>>----- REQUIRED/IMPORTANT SETTINGS -----<<<<<#####
+
+# Default maximum time (in seconds) to wait for page elements to appear.
+# Different methods/actions in base_case.py use different timeouts.
+# If the element to be acted on does not appear in time, the test fails.
+MINI_TIMEOUT = 2
+SMALL_TIMEOUT = 6
+LARGE_TIMEOUT = 10
+EXTREME_TIMEOUT = 30
+
+# If True, existing logs from past test runs will be saved and take up space.
+# If False, only the logs from the most recent test run will be saved locally.
+# You can also archive existing logs on the command line with: "--archive_logs"
+ARCHIVE_EXISTING_LOGS = True
+
+# If True, existing downloads from past runs will be saved and take up space.
+# If False, only the downloads from the most recent run will be saved locally.
+ARCHIVE_EXISTING_DOWNLOADS = False
+
+# Default names for files saved during test failures.
+# (These files will get saved to the "latest_logs/" folder.)
+SCREENSHOT_NAME = "error.png"
+BASIC_INFO_NAME = "basic_test_info.txt"
+PAGE_SOURCE_NAME = "page_source.html"
+
+# Default names for files and folders saved when using nosetests reports.
+# Usage: "--report". (NOSETESTS only)
+LATEST_REPORT_DIR = "latest_report"
+REPORT_ARCHIVE_DIR = "archived_reports"
+HTML_REPORT = "report.html"
+RESULTS_TABLE = "results_table.csv"
+
+# Default browser resolutions when opening new windows for tests.
+# (Headless resolutions take priority, and include all browsers.)
+# (Firefox starts maximized by default when running in GUI Mode.)
+CHROME_START_WIDTH = 1920
+CHROME_START_HEIGHT = 1080
+HEADLESS_START_WIDTH = 1920
+HEADLESS_START_HEIGHT = 1080

+ 9 - 0
setup.cfg

@@ -0,0 +1,9 @@
+[flake8]
+exclude=recordings,temp
+
+[nosetests]
+nocapture=1
+logging-level=INFO
+
+[bdist_wheel]
+universal=1

+ 107 - 0
test.py

@@ -0,0 +1,107 @@
+from seleniumbase import BaseCase    
+from seleniumbase import config as sb_config
+import pytest
+import time
+
+class BaseFunctions(BaseCase):
+    __test__ = False
+
+    def start(self, browser):
+        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"
+        super().setUp()
+        self.set_default_timeout(10)
+        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_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
+

+ 33 - 0
test.sh

@@ -0,0 +1,33 @@
+#!/bin/bash
+
+export PATH=$PATH:/opt/WebDriver/bin
+
+if [[ ${1} == "install" ]]; then
+    /usr/bin/python3.8 -m venv sbase_env
+    source sbase_env/bin/activate
+    python --version
+    python -m pip install --upgrade pip
+    python -m pip install --upgrade -r requirements.txt
+    seleniumbase download server
+    deactivate
+    exit
+elif [[ ${1} == "rmvm" ]]; then
+    rm -rf sbase_env
+    exit
+elif [[ ${1} == "grid-start" ]]; then
+    source sbase_env/bin/activate
+    seleniumbase grid-hub start
+    seleniumbase grid-node start
+    exit
+elif [[ ${1} == "grid-stop" ]]; then
+    source sbase_env/bin/activate
+    seleniumbase grid-hub stop
+    seleniumbase grid-node stop
+    exit
+fi
+
+source sbase_env/bin/activate
+
+python -m pytest test.py --dashboard --html=report.html --headless ${@}
+
+deactivate