【问题标题】:Opening Firefox via Selenium in Jenkins在 Jenkins 中通过 Selenium 打开 Firefox
【发布时间】:2017-10-26 09:34:05
【问题描述】:

当尝试通过 Jenkins 运行 Python Selenium 脚本时,它会崩溃,并出现一个非常无用的异常 - “selenium.common.exceptions.WebDriverException:消息:进程意外关闭,状态为:0” 相同的 Python 脚本在 Python 外部运行得非常好。

我已将脚本简化为一个非常非常基本的脚本,只需启动 Firefox -

from selenium import webdriver

if __name__ == "__main__":
    print("Hello World")
    driver = webdriver.Firefox()
    driver.get("http://www.google.com")
    driver.maximize_window()
    driver.quit()
    print("Goodbye World")

cmd 提示符的输出:

>C:\Users\kipod>C:\python_projects\Ranger\_just_open_browser.py

>Hello World

>Goodbye World

工作正常。

作为 Jenkins 工作运行:

>##Started by user anonymous
>Building in workspace C:\Program Files (x86)\Jenkins\workspace\Second Test
>[Second Test] $ cmd /c call >C:\Users\kipod\AppData\Local\Temp\jenkins3557827225974274191.bat
>
>C:\Program Files (x86)\Jenkins\workspace\Second Test>python >C:\python_projects\Ranger\_just_open_browser.py 
>Hello World
>Traceback (most recent call last):
>  File "C:\python_projects\Ranger\_just_open_browser.py", line 8, in <module>
>    driver = webdriver.Firefox()
>  File "C:\Python\Python36-32\lib\site->packages\selenium\webdriver\firefox\webdriver.py", line 154, in __init__
>    keep_alive=True)
>  File "C:\Python\Python36-32\lib\site->packages\selenium\webdriver\remote\webdriver.py", line 151, in __init__
>    self.start_session(desired_capabilities, browser_profile)
>  File "C:\Python\Python36-32\lib\site->packages\selenium\webdriver\remote\webdriver.py", line 240, in start_session
>    response = self.execute(Command.NEW_SESSION, parameters)
>  File "C:\Python\Python36-32\lib\site->packages\selenium\webdriver\remote\webdriver.py", line 308, in execute
>    self.error_handler.check_response(response)
>  File "C:\Python\Python36-32\lib\site->packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
>    **raise exception_class(message, screen, stacktrace)
>selenium.common.exceptions.WebDriverException: Message: Process unexpectedly >closed with status: 0**


>C:\Program Files (x86)\Jenkins\workspace\Second Test>exit 1 
>Build step 'Execute Windows batch command' marked build as failure
>Finished: FAILURE

我怀疑 Jenkins 的环境变量有问题,但我不知道要检查什么。而且这个例外是如此不具体(“我崩溃了。哈哈”),我发现在谷歌上没有任何帮助。而且我一直在寻找。

版本: 詹金斯:2.73.1 蟒蛇:3.6.2 壁虎司机:0.19.0 硒:3.6.0

(尝试打开 chrome 而不是 firefox - 行为相同。)

【问题讨论】:

  • 本地怎么样,是否有效。上次我检查 python 3.6 时对 webdriver 没有那么好的支持,如果可以的话,你能试试 python 2.7
  • 谢谢。卸载 3.6 和安装 2.7 时的行为相同。
  • 您使用的是哪个版本的硒?
  • C:\Users\kipod>pip freeze selenium==3.6.0

标签: python-3.x selenium jenkins selenium-webdriver geckodriver


【解决方案1】:

我认为您需要使用配置为以标准 Windows 用户帐户(例如“kipod”)登录的 jenkins slave 运行您的 python 脚本?确保为用户帐户的从机设置了自动登录,以允许 selenium 在桌面启动 Firefox。

这里有一些文档:Step by step guide to set up master and slave machines on Windows

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-12
    • 2017-10-23
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    相关资源
    最近更新 更多