-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_login.py
More file actions
27 lines (24 loc) · 956 Bytes
/
test_login.py
File metadata and controls
27 lines (24 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from playwright.sync_api import sync_playwright
class MyViewTests(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
super().setUpClass()
cls.playwright = sync_playwright().start()
cls.browser = cls.playwright.chromium.launch()
@classmethod
def tearDownClass(cls):
super().tearDownClass()
cls.browser.close()
cls.playwright.stop()
def test_login(self):
page = self.browser.new_page()
page.goto(f"{self.live_server_url}/admin/")
page.wait_for_selector('text=Django administration')
page.fill('[name=username]', 'myuser')
page.fill('[name=password]', 'secret')
page.click('text=Log in')
assert len(page.eval_on_selector(".errornote", "el => el.innerText")) > 0
page.close()