Skip to content

Commit

Permalink
first working MVP of Flow__Playwright__Get_Page_Html
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Oct 4, 2024
1 parent 29fae39 commit f47e79c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
from osbot_serverless_flows.playwright.Playwright__Serverless import Playwright__Serverless
from osbot_utils.helpers.flows.decorators.task import task
from playwright.async_api import Browser

from osbot_utils.helpers.flows.Flow import Flow

from osbot_utils.helpers.flows.decorators.flow import flow

from osbot_utils.base_classes.Type_Safe import Type_Safe


class Flow__Playwright__Get_Page_Html(Type_Safe):

pass
playwright_serverless : Playwright__Serverless
url : str = 'https://www.google.com'

@task()
def check_config(self) -> Browser:
print('checking config')

@task()
async def launch_browser(self) -> Browser:
await self.playwright_serverless.launch()
print('launched playwright')

@task()
async def new_page(self) -> Browser:
await self.playwright_serverless.new_page()

@task()
async def open_url(self) -> Browser:
await self.playwright_serverless.goto(self.url)

@task()
async def print_html(self, flow_data: dict) -> Browser:
page_content = await self.playwright_serverless.page.content()
flow_data['page_content'] = page_content

@flow()
async def flow(self) -> Flow:
self.check_config()
await self.launch_browser()
await self.new_page ()
await self.open_url ()
await self.print_html ()
return 'all done'

def run(self):
with self.flow() as _:
_.execute_flow()
return _.data
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
from unittest import TestCase

from osbot_utils.utils.Dev import pprint

from osbot_serverless_flows.flows.browser_based.Flow__Playwright__Get_Page_Html import Flow__Playwright__Get_Page_Html


class test_Flow__Playwright__Get_Page_Html(TestCase):
pass

@classmethod
def setUpClass(cls) -> None:
cls.flow__get_page_html = Flow__Playwright__Get_Page_Html()

def test_run(self):
flow_data = self.flow__get_page_html.run()
page_content = flow_data.get('page_content')
assert "<title>Google</title>" in page_content
assert len(page_content) > 10000

0 comments on commit f47e79c

Please sign in to comment.