@
@
@nixbox2020-10-27 22:50:07
selenium
@nixbox, 2020-10-27 22:50:07

How to run selenium from python-flask application?

Greetings!
I broke my head over the following problem:

I use Pyhon+Flask+Gunicorn+Nginx+Selenium.

If you run Selenium tests directly from the console, then everything works fine, but when trying to run testing inside the Flask application, errors begin, in particular, Selenium does not see the geckodriver if it is located directly in the tests folder inside the Flask application, I specify directly:

driver = webdriver.Firefox("/user/test/flask_app/app_files/selenuim_test", capabilities=firefox_capabilities, options=options)

But I am getting an error:
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.


If you place the geckodriver outside the Flask folder ("/user/test/") it starts to see, but other errors occur:
shutil.Error: [('/user/test/flask_app/flask_app.sock', '/tmp/tmp1vkuyshz/webdriver-py-profilecopy/run/flask_app.sock'', "[Errno 6] No such device or address: '/user/test/flask_app/flask_app.sock'")

Those. there are already errors as I understand it with Gunicorn.

Please tell me what could be the problem? With file permissions? In a virtual environment?
How can I run Selenium inside Flask? And why might the geckodriver not be visible?

I've tried everything but it doesn't work :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nixbox, 2020-10-28
_

Finally found the answer suggested on another site.
in Gunicorn .service file Environment=
must be added at the end /env/bin :/usr/bin:/bin
as shown in the example:

Environment="PATH=/home/username/env/bin:/usr/bin:/bin"

Because necessary functions like mkdir, readlink etc. are in /bin PATH

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question