簡體   English   中英

在 python:3.7 容器上運行 Selenium

[英]Running Selenium on python:3.7 Container

我正在嘗試使用基本 python:3.7 映像運行 Selenium 腳本,但我有點不確定如何安裝所需的依賴項。 我遇到了其他幾個關於使用不同圖像(如 selenium/standalone-chrome)的問題,但是,我有幾個其他腳本不使用 Selenium 在這個容器上運行,所以我有點猶豫要不要改變它。

我可以在這個圖像上運行 Selenium 嗎? 或者,如果我將其更改為 selenium/standalone-chrome 會影響我應用程序的其余部分。 我正在運行一個燒瓶 API。

這是我現在面臨的錯誤,

selenium.common.exceptions.WebDriverException: Message: Service <path>  unexpectedly exited. Status code was: 127

請注意,我只安裝了 pip 硒,沒有安裝其他依賴項,如 chrome。

正確的用例是讓selenium/standalone-chrome容器運行,並單獨擁有一個運行測試代碼的容器。

讓您使用docker-compose運行“集群”,並且您的測試在“RemoteWebDriver”的幫助下引用遠程 selenium 容器。

我能夠在這里找到我需要的東西, https://dev.to/nazliander/using-selenium-within-a-docker-container-ghp

可以將以下命令添加到您的 Dockerfile 以安裝 Chrome 驅動程序以運行 Selenium,

# Adding trusting keys to apt for repositories
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
# Adding Google Chrome to the repositories
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
# Updating apt to see and install Google Chrome
RUN apt-get -y update
# Install Google Chrome
RUN apt-get install -y google-chrome-stable
# Installing Unzip
RUN apt-get install -yqq unzip
# Download the Chrome Driver
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
# Unzip the Chrome Driver into /usr/local/bin directory
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
# Set display port as an environment variable
ENV DISPLAY=:99

請注意,這適用於我一直在使用的 python:3.7 基礎映像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM