-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
52 lines (39 loc) · 1.54 KB
/
Copy pathdemo.py
File metadata and controls
52 lines (39 loc) · 1.54 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import argparse
from typing import Optional
from dotenv import load_dotenv
from lexmount import Lexmount
from playwright.sync_api import Playwright, sync_playwright
load_dotenv(override=True)
def build_client(region: Optional[str]) -> Lexmount:
if region:
return Lexmount(region=region)
return Lexmount()
def run(playwright: Playwright, region: Optional[str] = None) -> None:
lm = build_client(region)
with lm.sessions.create() as session:
chromium = playwright.chromium
browser = chromium.connect_over_cdp(session.connect_url)
context = browser.contexts[0]
page = context.pages[0]
page.goto("https://browser.lexmount.cn/")
page_title = page.title()
assert page_title == "Lexmount Browser - AI-Powered Cloud Browser Service", (
"Page title is not 'Lexmount Browser - AI-Powered Cloud Browser Service', "
f"it is '{page_title}'"
)
page.screenshot(path="screenshot.png")
input("Press Enter to continue....")
page.close()
browser.close()
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Run the Lexmount Playwright quickstart demo.")
parser.add_argument(
"--region",
default=None,
help="Optional catalog region id, for example office-beijing. Omit to use the default region.",
)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
with sync_playwright() as playwright:
run(playwright, region=args.region)