在詹金斯身上运行selenium时出现问题



1,在ubuntu上设置jenkins2、在ubuntu上设置硒3、创建硒测试脚本代码如下:

from selenium import webdriver
import time
driver=webdriver.Chrome(executable_path='/home/test/chromedriver')
driver.get('https://www.yahoo.com')
time.sleep(2)
screenshot=driver.save_screenshot("yahoo.png")
driver.quit()

4、成功在本地执行脚本5、尝试使用jenkins来运行脚本,在jenkinsbuildexecuteshell下,cd/home/testpython测试.py6、Jenkins构建失败控制台输出:

Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/test
[test] $ /bin/sh -xe /tmp/jenkins127263638261616263.sh
+ cd /home/test
+ python test.py
Traceback (most recent call last):
File "test.py", line 5, in <module>
driver=webdriver.Chrome(executable_path='/home/test/chromedriver')
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build step 'Execute shell' marked build as failure
Finished: FAILURE

webdriver似乎无法启动,不知道如何解决这个问题并在jeninks上运行selenium。自动化新手,请告知,谢谢!

尝试在硒测试脚本中添加以下内容:

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument('--headless')

我认为问题出在chromedriver路径上。这个路径存在于jenkins节点上吗;executable_path="/home/test/cromedriver"?

提供在jenkins节点中可访问的chromediver的正确路径。

相关内容

  • 没有找到相关文章

最新更新