mirror of
https://github.com/nextcloud/docker.git
synced 2025-04-19 18:36:09 +02:00
Page.content() is now with timeout
This commit is contained in:
parent
de34aafdfb
commit
0d18fb122a
5 changed files with 52 additions and 4 deletions
|
@ -1,9 +1,13 @@
|
|||
import contextlib
|
||||
import sys
|
||||
from time import sleep, time_ns
|
||||
import signal
|
||||
|
||||
from playwright.sync_api import Playwright, sync_playwright, TimeoutError
|
||||
|
||||
def timeout_handler(signum, frame):
|
||||
raise TimeoutError("Page.content() timed out")
|
||||
|
||||
def log_note(message: str) -> None:
|
||||
timestamp = str(time_ns())[:16]
|
||||
print(f"{timestamp} {message}")
|
||||
|
@ -52,7 +56,13 @@ def run(playwright: Playwright, browser_name: str) -> None:
|
|||
except Exception as e:
|
||||
if hasattr(e, 'message'): # only Playwright error class has this member
|
||||
log_note(f"Exception occurred: {e.message}")
|
||||
|
||||
# set a timeout. Since the call to page.content() is blocking we need to defer it to the OS
|
||||
signal.signal(signal.SIGALRM, timeout_handler)
|
||||
signal.alarm(5)
|
||||
log_note(f"Page content was: {page.content()}")
|
||||
signal.alarm(0) # remove timeout signal
|
||||
|
||||
raise e
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import contextlib
|
||||
import sys
|
||||
from time import time_ns, sleep
|
||||
import signal
|
||||
|
||||
from playwright.sync_api import Playwright, sync_playwright, expect, TimeoutError
|
||||
|
||||
def timeout_handler(signum, frame):
|
||||
raise TimeoutError("Page.content() timed out")
|
||||
|
||||
def log_note(message: str) -> None:
|
||||
timestamp = str(time_ns())[:16]
|
||||
print(f"{timestamp} {message}")
|
||||
|
@ -53,8 +57,13 @@ def run(playwright: Playwright, browser_name: str) -> None:
|
|||
except Exception as e:
|
||||
if hasattr(e, 'message'): # only Playwright error class has this member
|
||||
log_note(f"Exception occurred: {e.message}")
|
||||
log_note("Page content was:")
|
||||
log_note(page.content())
|
||||
|
||||
# set a timeout. Since the call to page.content() is blocking we need to defer it to the OS
|
||||
signal.signal(signal.SIGALRM, timeout_handler)
|
||||
signal.alarm(5)
|
||||
log_note(f"Page content was: {page.content()}")
|
||||
signal.alarm(0) # remove timeout signal
|
||||
|
||||
raise e
|
||||
|
||||
# ---------------------
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import sys
|
||||
import contextlib
|
||||
from time import time_ns, sleep
|
||||
import signal
|
||||
|
||||
from playwright.sync_api import Playwright, sync_playwright, TimeoutError
|
||||
|
||||
def timeout_handler(signum, frame):
|
||||
raise TimeoutError("Page.content() timed out")
|
||||
|
||||
def log_note(message: str) -> None:
|
||||
timestamp = str(time_ns())[:16]
|
||||
print(f"{timestamp} {message}")
|
||||
|
@ -52,7 +56,13 @@ def create_user(playwright: Playwright, browser_name: str, username: str, passwo
|
|||
except Exception as e:
|
||||
if hasattr(e, 'message'): # only Playwright error class has this member
|
||||
log_note(f"Exception occurred: {e.message}")
|
||||
|
||||
# set a timeout. Since the call to page.content() is blocking we need to defer it to the OS
|
||||
signal.signal(signal.SIGALRM, timeout_handler)
|
||||
signal.alarm(5)
|
||||
log_note(f"Page content was: {page.content()}")
|
||||
signal.alarm(0) # remove timeout signal
|
||||
|
||||
raise e
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import sys
|
||||
import signal
|
||||
from time import time_ns
|
||||
from playwright.sync_api import sync_playwright, TimeoutError
|
||||
|
||||
from playwright.sync_api import sync_playwright
|
||||
def timeout_handler(signum, frame):
|
||||
raise TimeoutError("Page.content() timed out")
|
||||
|
||||
def log_note(message: str) -> None:
|
||||
timestamp = str(time_ns())[:16]
|
||||
|
@ -19,8 +22,8 @@ def main(browser_name: str = "chromium"):
|
|||
context = browser.new_context()
|
||||
page = context.new_page()
|
||||
try:
|
||||
page.goto('http://nc/')
|
||||
page.set_default_timeout(240_000) # 240 seconds (timeout is in milliseconds)
|
||||
page.goto('http://nc/')
|
||||
|
||||
# 1. Create User
|
||||
log_note("Create admin user")
|
||||
|
@ -42,7 +45,13 @@ def main(browser_name: str = "chromium"):
|
|||
except Exception as e:
|
||||
if hasattr(e, 'message'): # only Playwright error class has this member
|
||||
log_note(f"Exception occurred: {e.message}")
|
||||
|
||||
# set a timeout. Since the call to page.content() is blocking we need to defer it to the OS
|
||||
signal.signal(signal.SIGALRM, timeout_handler)
|
||||
signal.alarm(5)
|
||||
log_note(f"Page content was: {page.content()}")
|
||||
signal.alarm(0) # remove timeout signal
|
||||
|
||||
raise e
|
||||
|
||||
|
||||
|
|
|
@ -2,10 +2,14 @@ import contextlib
|
|||
import random
|
||||
import string
|
||||
import sys
|
||||
import signal
|
||||
from time import sleep, time_ns
|
||||
|
||||
from playwright.sync_api import Playwright, sync_playwright, expect, TimeoutError
|
||||
|
||||
def timeout_handler(signum, frame):
|
||||
raise TimeoutError("Page.content() timed out")
|
||||
|
||||
def log_note(message: str) -> None:
|
||||
timestamp = str(time_ns())[:16]
|
||||
print(f"{timestamp} {message}")
|
||||
|
@ -84,7 +88,13 @@ def create_conversation(playwright: Playwright, browser_name: str) -> str:
|
|||
except Exception as e:
|
||||
if hasattr(e, 'message'): # only Playwright error class has this member
|
||||
log_note(f"Exception occurred: {e.message}")
|
||||
|
||||
# set a timeout. Since the call to page.content() is blocking we need to defer it to the OS
|
||||
signal.signal(signal.SIGALRM, timeout_handler)
|
||||
signal.alarm(5)
|
||||
log_note(f"Page content was: {page.content()}")
|
||||
signal.alarm(0) # remove timeout signal
|
||||
|
||||
raise e
|
||||
|
||||
def talk(playwright: Playwright, url: str, browser_name: str) -> None:
|
||||
|
|
Loading…
Add table
Reference in a new issue