-
Notifications
You must be signed in to change notification settings - Fork 1
395 selenium #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
395 selenium #436
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f8053a3
errno 111
PeeachPie 49b32a5
merge with master
PeeachPie 13c445f
task_attempt_id error
PeeachPie 69db029
no mediaDevices
PeeachPie 7927bfa
assertion failed: презентация не обработалась
PeeachPie 8203e99
Исправлены selenium тесты
PeeachPie b950b60
Добавлены селениум тесты
PeeachPie c467d56
Добавлены селениум тесты
PeeachPie eee9bca
Новая организация селениум тестов
PeeachPie b3d0aca
Новая организация селениум тестов
PeeachPie 373f8ea
Новая организация селениум тестов
PeeachPie ef9eea4
Новая структура селениум тестов
PeeachPie 05b341f
Новая структура селениум тестов
PeeachPie 71c133d
Добавлена документация по запуску тестов
PeeachPie 9c7e47e
Обновленый ридми для тестирования
PeeachPie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,3 @@ venv | |
| __pycache__ | ||
| Dockerfile* | ||
| app/playground | ||
| tests/selenium | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| .venv | ||
| venv | ||
| .venv | ||
| .idea | ||
| ssl | ||
| __pycache__ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| FROM selenium/standalone-chrome:137.0-chromedriver-137.0-grid-4.33.0-20250606 | ||
|
|
||
| WORKDIR /usr/src/project | ||
|
|
||
| USER root | ||
| RUN apt-get update && \ | ||
| apt-get install -y python3 python3-pip && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| COPY tests/requirements.txt requirements.txt | ||
| RUN pip install -r requirements.txt | ||
|
|
||
| COPY tests/selenium selenium | ||
| COPY tests/test_data test_data | ||
| COPY tests/simple_phrases_russian.wav simple_phrases_russian.wav | ||
|
|
||
| COPY app/config.py app/config.py | ||
| COPY app_conf/testing.ini app_conf/testing.ini | ||
|
|
||
| ENV PYTHONPATH='/usr/src/project/:/usr/src/project/app/' | ||
|
|
||
| # CMD ["pytest", "-s", "."] |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| version: '2' | ||
|
|
||
| services: | ||
| selenium-tests: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile_selenium | ||
| shm_size: 2g | ||
| depends_on: | ||
| - web | ||
| networks: | ||
| - default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| ### Юнит тесты | ||
| #### Сборка и запуск проекта | ||
| Собираем и запускаем проект с конфигом `config.ini` или `testing.ini` | ||
| ```bash | ||
| $ docker compose build | ||
|
|
||
| $ APP_CONF=../app_conf/testing.ini docker compose up | ||
| ``` | ||
|
|
||
| #### Запуск тестов | ||
| Запускаем тесты следующей командой | ||
| ```bash | ||
| $ docker exec web_speech_trainer-web-1 bash -c 'cd /project/tests && pytest --ignore=selenium' | ||
| ``` | ||
|
|
||
| `--ignore=selenium` необходим (`pytest -s . -k 'not selenium'` не сработает), чтобы pytest не смотрел на selenium тесты, которые будут собраны в другом контейнере, иначе будут ошибки (selenium тесты будут ссылаться на отсутствующие в текущем контейнере зависимости) | ||
| ### Selenium тесты | ||
|
|
||
| #### Сборка и запуск проекта | ||
| Сборка и запуск проекта с selenium тестами осуществляется c конфигом `testing.ini` следующим образом | ||
| ```bash | ||
| $ docker compose -f docker-compose.yml -f docker-compose-selenium.yml build | ||
|
|
||
| $ APP_CONF=../app_conf/testing.ini docker compose -f docker-compose.yml -f docker-compose-selenium.yml up | ||
| ``` | ||
| #### Запуск тестов | ||
| Чтобы запустить selenium тесты необходимо выполнить следующую команду | ||
| ```bash | ||
| $ docker exec web_speech_trainer-selenium-tests-1 bash -c 'pytest .' | ||
| ``` | ||
| От сюда же можно запустить и юнит тесты, описанным в разделе юнит тестов способом | ||
| #### Структура selenium тестов | ||
| ##### Selenium session | ||
| Запускаемые тесты используют фикстуру `selenium_session` со `scope="module"`, объявленную в `conftest.py`. Она регистрируется в системе и возвращает экземпляр класса `SeleniumSession` с запущенным и настроенным драйвером. В нашем случае `scope="module"` значит, что для всех тестов в одном модуле будет использоваться один экземпляр `SeleniumSession` (не будет пересоздаваться от теста к тесту в одном модуле). | ||
|
|
||
| При необходимости можно объявлять другие фикстуры с другими настройками драйвера, например убрать симуляцию аудиопотока. | ||
| ##### Training session | ||
| Класс `TrainingSession` является надстройкой над `SeleniumSession`. Можно сказать, что это API взаимодействия с любой тренировкой. Причем `SeleniumSession` может передаваться между такими надстройками, что позволяет создавать различные сценарии для тестирования. | ||
|
|
||
| Например, после завершения тренировки, использовать API для другой странички, чтобы полистать страничку со всеми тренировками и убедиться в наличии новой тренировки. | ||
| ##### Test Main | ||
| `test_main.py` - входная точка тестирования, содержащая класс `TestMain`, который назовем сценарием тестирования. Данный класс может наследоваться от других сценариев тестирования, которые в данном контексте уже будут подсценариями. Например в `TestMain` используется подсценарий `SimpleTraining` проверяющий простую тренировку, но после тренировки можно использовать и другие подсценарии. | ||
|
|
||
| Исполнение тестов будет идти в порядке наследования, причем названия наследуемых классов не должны иметь префикс `Test`, иначе тесты могут дублироваться (вроде как принято использовать префикс `Base` для таких классов). | ||
|
|
||
| Наследование позволяет создавать различные сценарии тестирования. Каждый сценарий лучше описывать в отдельном файле вида `test_<название модуля с тестами>.py`, а их подсценарии либо в этом же файле, либо в файле без префикса `test_`, если планируется использование в других сценариях. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,2 @@ | ||
| pytest==8.0.2 | ||
| selenium==4.16.0 | ||
| webdriver-manager==4.0.1 | ||
| selenium==4.33.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import pytest | ||
|
|
||
| from selenium_session import SeleniumSession, ROOT_DIR, chrome_options | ||
| from app.config import Config | ||
|
|
||
| CONFIG_PATH = f'{ROOT_DIR}/app_conf/testing.ini' | ||
| AUDIO_FILE = f"{ROOT_DIR}/simple_phrases_russian.wav" | ||
|
|
||
| @pytest.fixture(scope="module") | ||
| def selenium_session(): | ||
| Config.init_config(CONFIG_PATH) | ||
| session = SeleniumSession(Config.c, chrome_options(AUDIO_FILE)) | ||
|
|
||
| yield session | ||
|
|
||
| session.end_session() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import requests | ||
| from time import sleep | ||
|
|
||
| from selenium.webdriver import Chrome | ||
|
|
||
| HOST = 'http://web:5000' | ||
| ROOT_DIR = '/usr/src/project' | ||
|
|
||
| from selenium.webdriver.chrome.options import Options | ||
|
|
||
| def chrome_options(audio_file=None): | ||
| chrome_options = Options() | ||
|
|
||
| chrome_options.add_argument('--no-sandbox') | ||
| chrome_options.add_argument('--headless') | ||
| chrome_options.add_argument(f'--unsafely-treat-insecure-origin-as-secure={HOST}') | ||
|
|
||
| if audio_file is not None: | ||
| chrome_options.add_argument("--disable-user-media-security") | ||
| chrome_options.add_argument("--use-fake-device-for-media-stream") | ||
| chrome_options.add_argument("--use-fake-ui-for-media-stream") | ||
| chrome_options.add_argument(f'--use-file-for-fake-audio-capture={audio_file}') | ||
|
|
||
| return chrome_options | ||
|
|
||
| class SeleniumSession: | ||
| def __init__(self, config, chrome_options, requires_init=True): | ||
| self.__prepare_session(HOST, config, chrome_options, requires_init) | ||
|
|
||
| def __init_driver(self, chrome_options): | ||
| self.driver = Chrome(options=chrome_options) | ||
| self.session = requests.Session() | ||
|
|
||
| sleep(5) | ||
|
|
||
| def __registrate(self, config): | ||
| self.session.request('POST',f'{self.host}/lti', data={ | ||
| 'lis_person_name_full': config.testing.lis_person_name_full, | ||
| 'ext_user_username': config.testing.session_id, | ||
| 'custom_task_id': config.testing.custom_task_id, | ||
| 'custom_task_description': config.testing.custom_task_description, | ||
| 'custom_attempt_count': config.testing.custom_attempt_count, | ||
| 'custom_required_points': config.testing.custom_required_points, | ||
| 'custom_criteria_pack_id': config.testing.custom_criteria_pack_id, | ||
| 'roles': config.testing.roles, | ||
| 'lis_outcome_service_url': config.testing.lis_outcome_service_url, | ||
| 'lis_result_sourcedid': config.testing.lis_result_source_did, | ||
| 'oauth_consumer_key': config.testing.oauth_consumer_key, | ||
| }) | ||
|
|
||
| def __prepare_session(self, host, config, chrome_options, requires_init): | ||
| self.host = host | ||
|
|
||
| self.__init_driver(chrome_options) | ||
|
|
||
| if requires_init: | ||
| self.driver.get(f'{self.host}/init/') | ||
|
|
||
| self.__registrate(config) | ||
|
|
||
| def end_session(self): | ||
| self.driver.quit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from time import sleep | ||
|
|
||
| from selenium_session import ROOT_DIR | ||
| from training_session import Training | ||
|
|
||
| PRESENTATION_FILE = f"{ROOT_DIR}/test_data/test_presentation_file_0.pdf" | ||
| ESTIMATED_PROCESSING_TIME_IN_SECONDS = 100 | ||
|
|
||
| class SimpleTraining: | ||
| def test_presentation_upload(self, selenium_session): | ||
| Training(selenium_session).upload_presentation(PRESENTATION_FILE) | ||
|
|
||
| def test_record_preparation(self, selenium_session): | ||
| Training(selenium_session).prepare_record() | ||
| sleep(5) | ||
|
|
||
| def test_button_next(self, selenium_session): | ||
| Training(selenium_session).next_slide() | ||
| sleep(5) | ||
|
|
||
| def test_training_session_end(self, selenium_session): | ||
| Training(selenium_session).end_training() | ||
| sleep(5) | ||
|
|
||
| def test_training_feedback(self, selenium_session): | ||
| got_feedback = Training(selenium_session).wait_for_feedback(ESTIMATED_PROCESSING_TIME_IN_SECONDS) | ||
| assert got_feedback, f"Проверка тренировки заняла более {ESTIMATED_PROCESSING_TIME_IN_SECONDS} секунд" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from simple_training import SimpleTraining | ||
|
|
||
| class TestMain(SimpleTraining): | ||
| pass |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для информации (исправлять не нужно) - для разных образов (точнее Dockerfile'ов) можно указывать свои .dockerignore (ссылка)