How to setup Splinter in a Django project with Docker ?
Closed this issue · 7 comments
I'm trying to setup Splinter for acceptance testing in a Django project using this plugin.
I'm looking for docs or examples to help me with it.
I found this repo, it's a bit old but still an example
https://github.com/mpasternak/pytest-django-pytest-splinter-test
Hi Rémy, this is my repo, I used it to demonstrate a kind of bug that was present in the codebase, but you can use it as a starting point, no problem.
First, how good is your general PyTest knowledge?
PyTest is based on a magic test runner and so-called fixtures. Have a look at this docs: https://docs.pytest.org/en/6.2.x/fixture.html#back-to-fixtures
This line is a simple test case, that uses a fixture called live_server
to spawn Django Live Server and browser
fixture, that is a pytest-splinter
browser.
https://github.com/mpasternak/pytest-django-pytest-splinter-test/blob/843577e05a91545e4ff1d687b3fd56f25e0e22d3/demo1/demo1_app/tests.py#L21
Let me know if I can assist you with anything.
I'd love to see any example usage added to the docs, if you're willing to spend some time on documenting stuff (and I'd rather like you do it than me, because I simply know about pytest-splinter
quirks too well so chances are I'd rather skip some important parts) -- if you're willing to invest some time on it, I'll gladly review and merge your documentation changes.
As of "old" example... if you plan just using pytest-splinter
, I guess not much changed from end-user point of view since 2017 :)
Take care,
Thanks for your fast and detailed answer.
You're right : I'm new to pytest. I thought pytest-splinter was a wrapper for Splinter, that installing the plugin would setup Splinter too.
Now I get it, I installed Splinter and it's working just fine.
I've been thinking to documentation improvements, and I'm not sure. Maybe a sentence in the Readme, under "Install pytest-splinter", something like "before installing pytest-splinter, make sure you installed pytest, splinter and the corresponding driver." But maybe it's useless and most people know that already. What do you think ?
I can also write a doc describing my setup, but it's quite specific : I'm using Docker and the django driver for Splinter. I don't know if a lot a people are interested in that. Thoughts ?
As far as I know, pytest-splinter does include splinter as a dependency,
Lines 33 to 39 in 1b0aa1e
How did you install pytest-splinter?
So, with these lines in my requirements.txt
:
splinter[django]==0.19.0
pytest-splinter==3.3.2
and this fixture in conftest.py
@pytest.fixture(scope='session')
def splinter_webdriver():
return 'django'
I get this test to pass :
@pytest.mark.django_db
def test_splinter_browser(self, browser):
browser.visit("/")
assert browser.is_text_present("Profiles") is True
If rebuild my docker image without the splinter
line on the requirements.txt
, I get this error :
ERROR profiles/tests/test_test_setup.py::TestTestSetup::test_splinter_browser - splinter.exceptions.DriverNotFoundError: Driver for django was not found.
I guess pytest-splinter
does not include the django driver. It was one of my problems during the install : the drivers for splinter. I could use headless firefox, but I couldn't find how to do the setup with pytest-splinter
installing pytest-splinter 3.3.2 installs splinter, selenium and a lot of different dependencies. I am not sure what is exactly your docker image setup, but this does not look like a problem with pytest-splinter but rather with your environment.
If you to plan any new documentation feel free to submit a problem report.
Thanks,
You're right, the more I look at it, the more I think it's a docker issue that blocks the Firefox driver.
I'll submit docs later,
thanks