Skip to content

Commit 2f225d6

Browse files
committed
Merge branch 'main' into feat/python-tool-displays-v2
2 parents 7c569e5 + 8f5f76c commit 2f225d6

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

pkg-py/src/shinychat/playwright/_chat.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
11
from __future__ import annotations
22

3-
from typing import Literal
3+
from typing import Literal, Pattern, Union
44

55
from playwright.sync_api import Locator, Page
66
from playwright.sync_api import expect as playwright_expect
7-
from shiny.playwright._types import PatternOrStr, Timeout
8-
from shiny.playwright.controller._base import UiBase
7+
8+
PatternStr = Pattern[str]
9+
PatternOrStr = Union[str, PatternStr]
10+
Timeout = Union[float, None]
11+
12+
13+
# Avoid circular import with shiny.playwright by copy/pasting UiBase class
14+
class UiBase:
15+
"""A base class representing shiny UI components."""
16+
17+
id: str
18+
"""
19+
The browser DOM `id` of the UI element.
20+
"""
21+
loc: Locator
22+
"""
23+
Playwright `Locator` of the UI element.
24+
"""
25+
page: Page
26+
"""
27+
Playwright `Page` of the Shiny app.
28+
"""
29+
30+
def __init__(
31+
self,
32+
page: Page,
33+
*,
34+
id: str,
35+
loc: Locator | str,
36+
) -> None:
37+
self.page = page
38+
# Needed?!? This is covered by `self.loc_root` and possibly `self.loc`
39+
self.id = id
40+
if isinstance(loc, str):
41+
loc = page.locator(loc)
42+
self.loc = loc
43+
44+
@property
45+
def expect(self):
46+
"""Expectation method equivalent to `playwright.expect(self.loc)`."""
47+
return playwright_expect(self.loc)
948

1049

1150
class Chat(UiBase):

0 commit comments

Comments
 (0)