generated from owasp-sbot/OSBot__Repo_Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first working MVP of Flow__Playwright__Get_Page_Html
- Loading branch information
Showing
4 changed files
with
67 additions
and
9 deletions.
There are no files selected for viewing
Submodule OSBot-Utils
updated
8 files
+1 −1 | README.md | |
+9 −4 | osbot_utils/helpers/flows/Flow.py | |
+31 −11 | osbot_utils/helpers/flows/Task.py | |
+17 −5 | osbot_utils/helpers/flows/decorators/task.py | |
+13 −0 | osbot_utils/utils/Threads.py | |
+1 −1 | osbot_utils/version | |
+1 −1 | pyproject.toml | |
+1 −0 | tests/unit/helpers/flows/test_decorator__flow.py |
47 changes: 46 additions & 1 deletion
47
osbot_serverless_flows/flows/browser_based/Flow__Playwright__Get_Page_Html.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 14 additions & 1 deletion
15
tests/integration/flows/browser_based/test_Flow__Playwright__Get_Page_Html.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |