Issue
1,setup jenkins on ubuntu 2,setup selenium on ubuntu 3,create selenium test script code as below:
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, success execute script locally 5, trying to use jenkins to run script, under jenkins build execute shell, cd /home/test python test.py 6, Jenkins build failure console output:
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
seems webdriver couldn't start, not sure how can i fix this issue and run selenium on jeninks. new to automation, pls advise thanks!
Solution
Try adding the below on your selenium test script :
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument('--headless')
Answered By - r10
Answer Checked By - Clifford M. (JavaFixing Volunteer)