Microdot UI Testing with Selenium #184
-
Has anybody experience with testing the webinterface with pytest and selenium? from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from tests.microdot_asyncio_test_client import TestClient
import pytest
driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
# https://pypi.org/project/webdriver-manager/
@pytest.fixture
def client(stub):
stub.apply({
'rp2': '[mock]',
'neopixel': '[mock]',
'machine': '[mock]',
'network': '[mock]'
})
import settings
client = TestClient(app=settings.app)
return client
@pytest.mark.asyncio
async def test_mainpage(client):
await client.get("/")
driver.get("http://127.0.0.1") fails with
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
I think this is a misunderstanding on your part. Selenium cannot work through the test client. You have to run the real app for it to be able to connect. Try starting the app manually to begin. For the final solution you will need to start the app on a separate thread or process, and stop it when the tests end. |
Beta Was this translation helpful? Give feedback.
-
I figured it out and published my sample repo. If anyone stumbles across end to end testing with this, feel free to head over to my sample repository on running click tests using the latest Microdot version. @miguelgrinberg feel free to mention this in your documentation 😊 |
Beta Was this translation helpful? Give feedback.
I think this is a misunderstanding on your part. Selenium cannot work through the test client. You have to run the real app for it to be able to connect. Try starting the app manually to begin. For the final solution you will need to start the app on a separate thread or process, and stop it when the tests end.