Skip to content

Commit

Permalink
removed one check from GH Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Oct 4, 2024
1 parent 1bc6afe commit 0db7b25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
9 changes: 6 additions & 3 deletions osbot_serverless_flows/playwright/Playwright__Serverless.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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



Expand Down
19 changes: 11 additions & 8 deletions tests/unit/playwright/test_Playwright__Serverless.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

# ----------

Expand All @@ -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"))

0 comments on commit 0db7b25

Please sign in to comment.