Skip to content

Commit

Permalink
FEATURE : Very basic iframe functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
crdoconnor committed Sep 9, 2023
1 parent d35aba2 commit 717b047
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hitch/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Engine(BaseEngine):
docs=InfoProperty(schema=Str()),
)

def __init__(self, paths, python_path, rewrite=False, cprofile=False, timeout=5.0):
def __init__(self, paths, python_path, rewrite=False, cprofile=False, timeout=30.0):
self.path = paths
self._rewrite = rewrite
self._python_path = python_path
Expand Down
53 changes: 53 additions & 0 deletions hitch/story/iframe.story
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Iframe:
docs: iframe
about: |
Look for an element inside an iframe.

Then look for an element inside an iframe inside an iframe.
given:
files:
selectors.yml: |
iframe:
element:
iframe page title: "#id_iframe_title"
message iframe:
locator: "#message_iframe"
iframe content message:
in iframe: message iframe
locator: "#id_dashboard_message"

html:
index.html: |
<div class="form-login">
<h4 id="id_iframe_title">This page contains an iframe</h4>
<iframe id="message_iframe" src="iframe_content.html" />
</div>
iframe_content.html: |
<p id="id_dashboard_message">hello!</a>
setup: |
from playwright.sync_api import expect, sync_playwright
from hitchpage import PlaywrightPageConfig
from pathlib import Path

browser = sync_playwright().start().chromium.connect("ws://127.0.0.1:3605")
page = browser.new_page()

conf = PlaywrightPageConfig(
*Path(".").glob("*.yml"), # all .yml files in this folder
playwright_page=page,
)

page.goto("http://localhost:8001")

steps:
- Run:
code: |
conf.next_page("iframe")
print("iframe page")
expect(conf.element("iframe page title")).to_be_visible()
expect(conf.element("iframe content message")).to_be_visible()

will output: |-
iframe page


18 changes: 16 additions & 2 deletions hitchpage/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def __init__(self, *config_files: Path, playwright_page: PlaywrightPage):
| Map(
{
Optional("text"): Str(),
Optional("locator"): Str(),
Optional("in iframe"): Str(),
}
),
)
Expand All @@ -34,13 +36,25 @@ def next_page(self, new_page: str):
@property
def _page_conf(self):
return self._config_dict[self._current_page]

def _get_iframe(self, which_iframe):
return self._playwright_page.frame_locator(
self._page_conf["element"][which_iframe]["locator"]
)

def element(self, name):
element_dict = self._page_conf["element"][name]
if isinstance(element_dict, str):
return self._playwright_page.locator(element_dict)
else:
if "text" in element_dict:
return self._playwright_page.get_by_text(element_dict["text"])
if "in iframe" in element_dict:
page = self._get_iframe(element_dict["in iframe"])
else:
page = self._playwright_page

if "locator" in element_dict:
return page.locator(element_dict["locator"])
elif "text" in element_dict:
return page.get_by_text(element_dict["text"])
else:
raise Exception("Unknown")

0 comments on commit 717b047

Please sign in to comment.