Reputation: 169
My problem is - I can't launch selenium tests inside container.
my docker file looks like:
FROM selenium/node-chrome
EXPOSE 9090
USER root
RUN mkdir /code
WORKDIR /code
ADD requirements_tests.txt /code/
RUN apt-get update
RUN apt-get install -y python python-dev python-distribute python-pip
RUN pip install -r requirements_tests.txt
ADD /selenium_tests HTMLTestRunner.py launch_selenium_tests.py chromedriver /code/
/selenium_tests
contain all my tests, launch_selenium_tests.py
- its my launcher for tests.
import time
from pyvirtualdisplay import Display
import os
class SeleniumTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
"""
todo add validation for arguments
:param args:
:param kwargs:
"""
super(SeleniumTestCase, self).__init__(args[0])
self.base_url = args[1]
def setUp(self):
chromedriver = "./chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
self.driver = webdriver.Chrome(executable_path='./chromedriver')
self.display = Display(visible=0, size=(800, 800))
self.display.start()
this is my test_case
file
So, when i start docker container with -it /bin/bash (interactive mode with terminal) and launch tests i get this error msg:
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Linux 4.2.0-35-generic x86_64)
I already try to switch container with selenium, rewrite some lines of code, but nothing worked for me.
Any idea how i can fix this?
Upvotes: 2
Views: 346
Reputation: 1895
I would suggest two things:
Quick - start the display
before starting the driver so the code:
def setUp(self):
chromedriver = "./chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
self.display = Display(visible=0, size=(800, 800))
self.display.start()
self.driver = webdriver.Chrome(executable_path='./chromedriver')
Second I would strongly suggest to use the service_log_path
and service_args
arguments to the selenium webdriver to see output from the chromedriver:
service_log_path = "{}/chromedriver.log".format(outputdir)
service_args = ['--verbose']
driver = webdriver.Chrome('/path/to/chromedriver',
service_args=service_args,
service_log_path=service_log_path)
This may provide missing info why the driver failed to start
Upvotes: 2