当试图通过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 Python:3.6.2 Geckodriver:0.19.0 硒:3.6.0
(尝试打开chrome而不是firefox - 同样的行为。)
答案 0 :(得分:0)
我认为您需要使用配置为以标准Windows用户帐户登录的jenkins slave运行您的python脚本(例如&#34; kipod&#34;)?确保为用户帐户的从属计算机设置了自动登录,以便允许selenium在桌面上启动Firefox。
这里有一些文件:Step by step guide to set up master and slave machines on Windows