Skip to content

Commit 967d977

Browse files
committed
Update MaterialLogin tests
1 parent 73dfeef commit 967d977

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed
Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from pathlib import Path
22

33
import pytest
4-
5-
from playwright.sync_api import Page, expect
6-
74
from e2e_utils import StreamlitRunner
5+
from playwright.sync_api import Page, expect
86

97
ROOT_DIRECTORY = Path(__file__).parent.parent.absolute()
108
BASIC_EXAMPLE_FILE = ROOT_DIRECTORY / "material_login" / "example.py"
119

10+
1211
@pytest.fixture(autouse=True, scope="module")
1312
def streamlit_app():
1413
with StreamlitRunner(BASIC_EXAMPLE_FILE) as runner:
@@ -22,41 +21,53 @@ def go_to_app(page: Page, streamlit_app: StreamlitRunner):
2221
page.get_by_role("img", name="Running...").is_hidden()
2322

2423

24+
def _get_username_error_text(frame: Page):
25+
return frame.get_by_text("username must be a valid email")
26+
27+
28+
def _get_password_error_text(frame: Page):
29+
return frame.get_by_text("password is a required field")
30+
31+
2532
def test_should_render_material_login(page: Page):
26-
frame = page.frame_locator(
27-
'iframe[title="material_login\\.material_login"]'
28-
)
29-
component_return_value = page.get_by_test_id('stMarkdownContainer')
30-
component_return_value_json = page.get_by_test_id('stJson')
33+
frame = page.frame_locator('iframe[title="material_login\\.material_login"]')
34+
component_return_value = page.get_by_test_id("stMarkdownContainer")
35+
component_return_value_json = page.get_by_test_id("stJson")
3136

3237
email_field = frame.get_by_placeholder("username@domain.com")
3338
password_field = frame.get_by_placeholder("your password")
34-
invalid_username_text = frame.get_by_text("username must be a valid email")
35-
invalid_password_text = frame.get_by_text("password is a required field")
3639
login_button = frame.get_by_role("button", name="Login")
3740
cancel_button = frame.get_by_role("button", name="Cancel")
3841

42+
expect(_get_username_error_text(frame)).not_to_be_attached()
43+
expect(_get_password_error_text(frame)).not_to_be_attached()
44+
3945
email_field.click()
4046
email_field.fill("hello")
47+
# blur the email field to trigger validation
48+
email_field.blur()
4149

42-
expect(invalid_username_text).to_be_visible()
43-
expect(invalid_password_text).to_be_visible()
50+
expect(_get_username_error_text(frame)).to_be_visible()
51+
expect(_get_password_error_text(frame)).not_to_be_attached()
4452
expect(login_button).to_be_disabled()
4553

4654
email_field.click()
4755
email_field.fill("hello@hello.com")
4856
password_field.click()
4957
password_field.fill("password")
50-
expect(invalid_username_text).to_be_hidden()
51-
expect(invalid_password_text).to_be_hidden()
52-
expect(component_return_value).to_have_text('None')
58+
# blur the password field to trigger validation
59+
password_field.blur()
60+
61+
expect(_get_username_error_text(frame)).not_to_be_attached()
62+
expect(_get_password_error_text(frame)).not_to_be_attached()
63+
expect(component_return_value).to_have_text("None")
5364
login_button.click()
5465

55-
expect(component_return_value_json).to_contain_text("\"username\":\"hello@hello.com\"")
56-
expect(component_return_value_json).to_contain_text("\"password\":\"password\"")
66+
expect(component_return_value_json).to_contain_text('"username":"hello@hello.com"')
67+
expect(component_return_value_json).to_contain_text('"password":"password"')
5768
cancel_button.click()
5869
expect(email_field).to_be_empty()
5970
expect(password_field).to_be_empty()
60-
expect(invalid_username_text).to_be_hidden()
61-
expect(invalid_password_text).to_be_hidden()
62-
expect(component_return_value_json).to_have_text('{}')
71+
expect(_get_username_error_text(frame)).not_to_be_attached()
72+
expect(_get_password_error_text(frame)).not_to_be_attached()
73+
expect(component_return_value_json).to_have_text("{}")

0 commit comments

Comments
 (0)