【问题标题】:How can I install selenium chrome driver in jenkins?如何在 jenkins 中安装 selenium chrome 驱动程序?
【发布时间】:2017-12-24 16:39:00
【问题描述】:

我已经拉取了 jenkins 容器,它在我的本地主机的 8080 端口公开了 jenkins。

我可以看到詹金斯运行良好。 我已经安装了点子 我已经用 pip 安装了 selenium 当我运行测试时出现错误:

+ python /var/jenkins_home/workspace/My_Job/slenium_login.py
12:02:06 Traceback (most recent call last):

12:02:06   File "/var/jenkins_home/workspace/My_Job/slenium_login.py", line 6, in <module>

12:02:06     driver = webdriver.Chrome(cd)

12:02:06   File "/var/jenkins_home/shiningpanda/jobs/5db0e2cb/virtualenvs/d41d8cd9/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__

12:02:06     self.service.start()

12:02:06   File "/var/jenkins_home/shiningpanda/jobs/5db0e2cb/virtualenvs/d41d8cd9/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 81, in start

12:02:06     os.path.basename(self.path), self.start_error_message)

12:02:06 selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

如何在我的 jenkins 环境中安装 selenium chrome 驱动程序?

【问题讨论】:

  • 只需下载 chromdriver 可执行文件并将其放在某处。如果是 linux,请确保可以使用 jenkins 用户访问它。
  • @GaurangShah 我是詹金斯的新手。我将 jenkins 作为一个 docker 容器运行,我使用 docker pull jenkins 从 docker hub 拉出,而我的 jenkins 用户不是 root。如何从作业可执行脚本安装 chromedriver?

标签: selenium docker jenkins containers selenium-chromedriver


【解决方案1】:

一种简单的方法是在官方镜像的基础上构建您的自定义 Jenkins docker 镜像。

结构是这样的:

# Dockerfile
FROM jenkins

# Set user root to allow us to install the rest of what's needed
USER root

# <install your stuff here>

# Go back to non-sudo user
USER jenkins

我已经推送了一张图片docker pull elgalu/jenkins,其中安装了 Chrome、chromedriver 和带有 Selenium 绑定的 Python3。如您所愿。

您可以使用我的图像或查看源代码并自己构建它:

https://github.com/elgalu/jenkins-chrome

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-16
    • 2021-08-14
    • 1970-01-01
    • 2017-03-10
    • 2022-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多