I have a cod.
@pytest.fixture(scope="function") def browser(): selenium_grid_url = os.getenv('SELENIUM_HOST', "not_found") + "/wd/hub" chrome_options = webdriver.ChromeOptions() chrome_options.add_experimental_option('prefs', {'intl.accept_languages': 'ru-RU', 'download.default_directory': f'{directory}', "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": True } ) print(f"nStart Chrome browser.. {selenium_grid_url}") capabilities = DesiredCapabilities.CHROME browser = webdriver.Remote(desired_capabilities=capabilities, command_executor=selenium_grid_url, options=chrome_options) yield browser print("nClose Chrome..") browser.quit()
I have a docker + python + pytest + selenium + Chrome + selenium host and prefs But it doesn’t work. I want save to file without dialog window. But test don`t save files. How can I understand the reason? And… Downloading files works on Windows, but not docker on linux. P.S I have this path in docker env for chrome download and python DOWNLOAD_FOLDER=/app/download_files FOLDER_FOR_TEST_FILES=/app/test_files
My cod for check files
new_list_download_files = next(os.walk(f'{directory}'))[2] first_doc = new_list_download_files[0] second_doc = new_list_download_files[1]
Dockerfile
FROM python:3.8.12-buster ENV PYTHONUNBUFFERED 1 ARG REQUIREMENTS=${REQUIREMENTS:-requirements.txt} COPY ./${REQUIREMENTS} /requirements.txt RUN pip install -r requirements.txt RUN mkdir /app COPY . /app WORKDIR /app ENTRYPOINT ["python"]
Advertisement
Answer
After 5 days. In the end, all you had to do was use docker-volumes. In docker-compose.yml
volumes: data-volume: download-volume: external: true name: selenium_downloads