Skip to content

Commit

Permalink
change test script
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwcfan committed Sep 26, 2024
1 parent f871bfb commit aea162d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.8'
services:
chrome:
build:
context: ../chrome
context: ./chrome
dockerfile: Dockerfile
container_name: chrome
ports:
Expand Down
1 change: 0 additions & 1 deletion python_library/finicapi/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ async def process_selector_queue(llm_provider: LLMProvider, provider_api_key: st

with open('selectors.json', 'w') as f:
json.dump(output, f, indent=2)
import pdb; pdb.set_trace()
print(f"\nSelectors have been generated and saved to selectors.json")

async def handle_inspect_node(cdp_session: CDPSession, page: Page, event: Dict[str, Any], current_node: List[NodeInfo]):
Expand Down
78 changes: 62 additions & 16 deletions testscript.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,69 @@
import asyncio
from playwright.async_api import async_playwright, Playwright
from playwright.sync_api import sync_playwright, Playwright
import requests

import json
CDP_URL = "ws://localhost:8000/ws"

TEST_DATA = {
"url": "https://testpages.herokuapp.com/styled/basic-html-form-test.html",
"form_data": {
"username": "finictest",
"password": "Password123",
"comment": "This is a test comment",
"checkbox_values": ["cb1", "cb2"],
"radio_value": "rd3",
"multi_select_values": ["ms1", "ms2"],
"dropdown_value": "dd5"
}
}

def main():
url = TEST_DATA["url"]
form_data = TEST_DATA["form_data"]

print("Running the Playwright script")

with sync_playwright() as p:
print("Connecting to Browser...")
browser = p.chromium.launch(headless=False, slow_mo=500)

### Uncomment this line when you're ready to connect to Finic Browser
# browser = p.chromium.connect_over_cdp("ws://localhost:8000/ws")

page = browser.new_page()

# Navigate to the website and login
page.goto(url)
page.wait_for_load_state("networkidle", timeout=10000)

page.fill('input[name="username"]', form_data["username"])
page.fill('input[name="password"]', form_data["password"])
page.fill('textarea[name="comments"]', form_data["comment"])

# click on the input
# import pdb; pdb.set_trace()
page.check('input[type="radio"][value="{}"]'.format(form_data["radio_value"]))
for checkbox_value in form_data["checkbox_values"]:
page.check('input[type="checkbox"][value="{}"]'.format(checkbox_value))
page.select_option('select[name="multipleselect[]"]', value=form_data["multi_select_values"])
page.select_option('select[name="dropdown"]', value=form_data["dropdown_value"])

page.click('input[type="submit"]')

# Check if page confirms our success
form_results = page.query_selector('.form-results')
if form_results:
# Query for the element with class "centered form-results"
print(form_results.inner_text())
print("\nForm submission successful")
else:
print("Form submission was not successful")

async def main(pw: Playwright):
print("Connecting to Browser...")
async with async_playwright() as pw:
browser = await pw.chromium.connect_over_cdp(CDP_URL)
try:
print("Connected! Navigating...")
page = await browser.new_page()
await page.goto("https://example.com", timeout=2 * 60 * 1000)
print("Navigated! Scraping page content...")
html = await page.content()
print(html)
finally:
await browser.close()
# Set a timeout of 2 seconds
page.wait_for_timeout(2000)
# import pdb; pdb.set_trace()
browser.close()


asyncio.run(main())
if __name__ == "__main__":
main()

0 comments on commit aea162d

Please sign in to comment.