Can't get selenium to work from docker container

91 views
Skip to first unread message

dev_noob

unread,
Aug 28, 2023, 4:06:46 AM8/28/23
to Selenium Users
Hi all

I understand there is a pre-built docker image for selenium but had figured it should be fairly straightforward to implement myself in my container, but now I'm not so sure.

I'm out of ideas with below and would appreciate if anyone has any suggestions? I can provide a sample script if it helps.

1. My architecture:

 - I have a lubuntu VM, hosting 2 Apache virtual hosts and Docker.
 - Within Docker, I host a container instantiated from the 'Jenkins Blue Ocean' image.
 - In this container, I pull down my Jenkinsfile from GitHub then run a simple >Build >Test >Deploy pipeline for my Apache virtual host content.
 - As part of its Test stage, I run a pytest (using selenium) script to assert if the newly-built website contains a specific string in its title.
 - I have python3, pytest, selenium (4.11.2), firefox, chrome installed in both host and container.


2. My problem:

 - This pipeline runs successfully if I do not include the pytest script..
 - This pytest script runs successfully if I run it from my lubuntu host terminal..
 - But execution fails when Jenkins (i.e. running in Docker container) tries to run my pytest script for any browser, e.g. driver = webdriver.Firefox(service=service, options=opts)
 - Error message follows (noting that I've exhausted all its suggested fixes):

E           selenium.common.exceptions.NoSuchDriverException: Message: Unable to locate or obtain driver for firefox; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

/usr/lib/python3.10/site-packages/selenium/webdriver/common/driver_finder.py:44: NoSuchDriverException


 - Should I have python3 / pytest / selenium / browsers installed on the host or the container?
 - Am I doing this all wrong? Are there extra things I would need to consider when calling the selenium library from within a docker container?

Thanks for any thoughts.
Reply all
Reply to author
Forward
0 new messages