-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbrowser.py
59 lines (40 loc) · 1.39 KB
/
browser.py
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
53
54
55
56
57
58
59
import time
import config
from playwright.sync_api import Playwright, sync_playwright, expect
def run(playwright: Playwright, progress_bar: str=None, is_headless: bool=True) -> None:
def set_progress(progress):
if progress_bar is not None:
progress_bar.set(progress)
browser = playwright.chromium.launch(headless=is_headless)
set_progress(25)
context = browser.new_context()
set_progress(30)
page = context.new_page()
set_progress(35)
page.goto(config.RENDERING_URL)
set_progress(40)
for i in range(10):
time.sleep(1)
set_progress(40 + i)
page.get_by_text("File").click()
set_progress(55)
with page.expect_file_chooser() as fc_info:
page.locator("[id=\"\\31 2\"]").click()
file_chooser = fc_info.value
file_chooser.set_files("temp/waiting_for_upload.schem")
page.get_by_text("File", exact=True).click()
set_progress(60)
page.locator("[id=\"\\32 3\"] > div:nth-child(3)").click()
with page.expect_download() as download_info:
page.locator("[id=\"\\31 8\"]").click()
set_progress(70)
download = download_info.value
download.save_as("temp/screenshot.png")
if is_headless:
page.close()
context.close()
browser.close()
set_progress(90)
if __name__ == "__main__":
with sync_playwright() as playwright:
run(playwright)