From 0db7b25e731a88092fadf7e2c81290f880f3ed50 Mon Sep 17 00:00:00 2001 From: Dinis Cruz Date: Fri, 4 Oct 2024 01:19:59 +0100 Subject: [PATCH] removed one check from GH Actions --- .../playwright/Playwright__Serverless.py | 9 ++++++--- .../playwright/test_Playwright__Serverless.py | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/osbot_serverless_flows/playwright/Playwright__Serverless.py b/osbot_serverless_flows/playwright/Playwright__Serverless.py index 357a74b..506e795 100644 --- a/osbot_serverless_flows/playwright/Playwright__Serverless.py +++ b/osbot_serverless_flows/playwright/Playwright__Serverless.py @@ -8,15 +8,17 @@ from osbot_utils.base_classes.Type_Safe import Type_Safe class Playwright__Serverless(Type_Safe): + playwright : Playwright = None playwright_cli : Playwright_CLI + @cache_on_self def chrome_path(self): return self.playwright_cli.executable_path__chrome() async def browser(self): - playwright = await self.playwright() + playwright = await self.start() return await playwright.chromium.launch(**self.browser__launch_kwargs()) async def new_page(self): @@ -27,8 +29,9 @@ async def goto(self, url): page = await self.new_page() return await page.goto(url) - async def playwright(self) -> Playwright: - return await async_playwright().start() + async def start(self) -> Playwright: + self.playwright = await async_playwright().start() + return self.playwright diff --git a/tests/unit/playwright/test_Playwright__Serverless.py b/tests/unit/playwright/test_Playwright__Serverless.py index 308233a..16cb605 100644 --- a/tests/unit/playwright/test_Playwright__Serverless.py +++ b/tests/unit/playwright/test_Playwright__Serverless.py @@ -7,7 +7,7 @@ from osbot_utils.utils.Misc import list_set from playwright.async_api import Playwright, Browser, Response, Request, Frame, Page, Accessibility from osbot_utils.utils.Threads import async_invoke_in_new_loop -from osbot_utils.utils.Env import in_github_action +from osbot_utils.utils.Env import in_github_action, not_in_github_action from osbot_utils.utils.Files import file_name, file_exists, folder_exists, folder_name from osbot_serverless_flows.playwright.Playwright__Serverless import Playwright__Serverless from osbot_utils.utils.Dev import pprint @@ -21,7 +21,9 @@ def setUpClass(cls) -> None: def test__init__(self): with self.playwright__serverless as _: - expected_locals = dict(playwright_cli=_.playwright_cli) + expected_locals = dict(playwright = None , + playwright_cli = _.playwright_cli ) + assert self.playwright__serverless.__locals__() == expected_locals def test_1__browser__install(self): # (first test to be executed) make sure that the browser is installed @@ -89,7 +91,8 @@ def test_goto(self): 'content-length', 'content-security-policy-report-only', 'content-type', 'cross-origin-opener-policy', 'date', 'expires', 'p3p', 'permissions-policy', 'report-to', 'server', 'x-frame-options', 'x-xss-protection'] - assert frame.child_frames == [] + if not_in_github_action(): + assert frame.child_frames == [] # there was an extra frame here when running in GH Actions (a 'callout') assert frame.parent_frame is None assert frame.name == '' assert frame.url == url @@ -105,10 +108,11 @@ def test_goto(self): - def test_playwright(self): + def test_start(self): with self.playwright__serverless as _: - playwright = async_invoke_in_new_loop(_.playwright()) + playwright = async_invoke_in_new_loop(_.start()) assert type(playwright) is Playwright + assert _.playwright == playwright # ---------- @@ -133,9 +137,8 @@ async def get_screenshot(url): screenshot = await page.screenshot(full_page=True) await playwright.stop() - + return bytes_to_base64(screenshot) - result = async_invoke_in_new_loop(get_screenshot("https://www.google.com/404")) - pprint(result) + async_invoke_in_new_loop(get_screenshot("https://www.google.com/404"))