Im trying to run UI tests using selenium in headless mode. I see the chrome is browser is crashing whenever i try to load the driver. Here are the traceback.
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/behave/model.py", line 1456, in run
match.run(runner.context)
File "/usr/local/lib/python3.5/dist-packages/behave/model.py", line 1903, in run
self.func(context, *args, **kwargs)
File "steps/collectorUi.py", line 35, in step_impl
assert context.ndpUt.driverInit(title="Pegasus Portal") is not False, 'Initial page title didnt match'
File "../collectorSanity/libs/ndpUi.py", line 91, in driverInit
browser=self.browser)
File "../runner/testutils/seleniumutils.py", line 70, in __init__
executable_path=self.browserPath+self.browserDriver)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 90, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 177, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 4.2.0-16-generic x86_64)
I have installed xvfb and google-chrome on ubuntu. The following are environment variables I tried to set before running the tests.
Env:
export DISPLAY=:10
nohup sudo Xvfb :10 -ac -screen 0 1900x980x24 &
When i run in docker container, Im get the following errors.
jenkins@26cccde068c0:~/e2e$ nohup sudo Xvfb :10 -ac -screen 0 1900x980x24 &
_XSERVTransmkdir: Owner of /tmp/.X11-unix should be set to root
(EE)
Fatal server error:
(EE) Server is already active for display 10
If this server is no longer running, remove /tmp/.X10-lock
and start again.
(EE)
In the selenium library, the following are display and parameters of chrome driver.
from pyvirtualdisplay import Display
from selenium import webdriver
class SeleniumUi(object):
def __init__(self, ....):
if isHeadless:
self.display = Display(visible=0, size=(1900, 980))
self.display.start()
# secure
if secure:
self.webpage = 'https://{}{}'.format(self.hostname, webpageUri)
else:
self.webpage = 'http://{}{}'.format(self.hostname, webpageUri)
# firefox options
if self.browser.lower() == 'firefox':
if ignoreCert:
# ignoring the certs
self.profile = webdriver.FirefoxProfile()
self.profile.accept_untrusted_certs = True
self.driver = webdriver.Firefox(firefox_profile=self.profile)
else:
self.driver = webdriver.Firefox()
# chrome options
elif self.browser.lower() == 'chrome':
#os.system('killall -9 chromedriver')
self.options = webdriver.ChromeOptions()
self.options.add_argument('--dns-prefetch-disable')
#self.options.add_argument("--disable-extensions") # don't delete this
self.options.add_argument('--disable-web-security')
self.options.add_argument('--window-size=1400,900')
#self.options.add_argument('--allow-file-access-from-files')
#self.options.add_argument('--allow-file-access')
#self.options.add_argument('--allow-cross-origin-auth-prompt')
#self.options.add_argument('--allow-control-allow-origin')
#self.options.add_argument('--allow-control-allow-methods')
#self.options.add_argument('--allow-control-allow-headers')
#self.options.add_argument('--disable-default-apps')
if ignoreCert:
# ignoring the certs
self.options.add_argument('--ignore-certificate-errors')
log.debug('browserPath:{} browserDriver:{}'.format(self.browserPath, self.browserDriver))
self.driver = webdriver.Chrome(chrome_options=self.options,
executable_path=self.browserPath+self.browserDriver)
Kindly let me know what could be the issue. Thanks in advance.