Repository navigation
Feature: Add playwright support in build command - #76
shubhamofbce wants to merge 5 commits into
Conversation
…ee proper error messages and playwright is not a required library
|
This is a sample code generated using lavague-build-playwright @mbrunel import asyncio
async def wrapper_func():
try:
from playwright.async_api import async_playwright
except (ImportError, ModuleNotFoundError) as error:
raise ImportError("Please install playwright using `pip install pytest-playwright` and then `playwright install` to install the necessary browser drivers") from error
p = await async_playwright().__aenter__()
browser = await p.chromium.launch()
page = await browser.new_page()
await page.goto('https://huggingface.co/')
########################################
# Query: Click on the Docs
# Code:
# Based on the provided HTML snippet, we need to identify the link that contains the text "Docs"
# We can use the text selector to find the link with the text "Docs"
docs_link = page.locator('text="Docs"')
# Then we can click on the link
await docs_link.click()
########################################
# Query: Click on Optimum
# Code:
# Based on the provided HTML snippet, the text "Optimum" is within an anchor tag.
# We can use the text selector to identify and click on the element.
optimum_link = page.locator('text=Optimum')
await optimum_link.click()
# Based on the provided HTML snippet, we can see that the link for NVIDIA is within an anchor tag.
# We can use the text content of the anchor tag to identify and click on the link.
# Find the anchor tag containing the text "NVIDIA"
nvidia_link = page.locator('a').with_text('NVIDIA')
# Click on the NVIDIA link
await nvidia_link.click()
asyncio.run(wrapper_func())
|
|
@mbrunel Moved this to draft as i need to do some code cleanup and comments to improve code quality. You can review the core changes they will remain same. |
|
Pretty cool @shubhamofbce! I think focusing on the build for now might make the most sense. We will soon switch to a VS Code Extension. I don't know if it will create the same issues with async/sync though |
|
Also, tried using that for the GUI, seems to be working: from playwright.async_api import async_playwright
playwright = await async_playwright().start()
browser = await playwright.chromium.launch(headless = False)
page = await browser.new_page()
await page.goto("http://whatsmyuseragent.org/")Will have a look too this weekend |
|
Added comments in the utils function and did some code cleanup, Now it is ready for review. |
|
It works! Pretty cool, thanks for a great job! I have a few things to highlight that might be relevant before we merge, some you can help with, some we will have to look at as well (@lyie28 / @mbrunel ):
Here is a gist to give some idea. I think each block of action can be wrapped in an async function and called progressively. What do you think @shubhamofbce ? |
|
@shubhamofbce Both of these are great ideas, let me look into them. |
|
@dhuynh95 |
|
@shubhamofbce super! Will have a look Also regarding the second point I don't think it's actually possible and your solution might be the only one working with Playwright |
|
You are right @dhuynh95 It is actually difficult to achieve that. we can create an issue for it and pick that up later as an optimisation. |
|
@shubhamofbce I agree let's see later. In any way, we got big stuff coming that will solve it:
I did some experiment on my side, nothing ready yet but it will look like that: Regarding the merge, @lyie28 and @mbrunel are off until Tuesday, so we will merge around that. @mbrunel is working on a cleaning of the codebase, so we might wait until we converge on a more modular architecture before merging your PR. I am thinking the build can be decomposed in the following steps, that can be modular and adapted:
What do you think? @shubhamofbce :) |
|
@dhuynh95, the VS code demo/experiment is looking fantastic! 😄 Just a friendly note: there's no rush to merge my code. Feel free to take your time, and let's sync up when we all agree it's the right moment. Also, breaking it down into steps is a brilliant idea. It not only enhances readability and maintainability but also offers users greater flexibility in various use cases. Let's do this. |
|
Sure! Yeah I am so excited about this project that I put myself big objectives haha Because of the time you put, I want to make sure we merge this so that we make sure we show with acts and not just words how we appreciate your efforts in helping build this project! :) |
|
I opened #131 to reflect your changes on an up to date branch, while keeping this as a reference. I would like you to take a look and tell me your toughts. |
|
I close this as #131 was merged. |

Partially closes: #1
This PR adds a new command
lavague-build-playwrightto build playwright code similar tolavague-build.We are using playwright async api, and i have created a new function for it without affecting any existing methods.
Command to run build playwright code
!lavague-build-playwright --file_path hf.txt --config_path openai.pyOther things that I tried which didn't worked:
I also tried using playwright sync API in build such that the code looks similar to selenium and we don't need async await but it was throwing error:
error: It looks like you are using Playwright Sync API inside the asyncio loop.I searched and found that sync api is not allowed in jupyter notebooks and collab as they are already in asyncio loop.I also tried implementing the launch method using both sync and async playwright but no luck as It uses gradio and gradio was switching threads and plawright is not thread aware. We can create a separate issue for this and look into it later.