microsoft / playwright-python

Python version of the Playwright testing and automation library.
https://playwright.dev/python/
Apache License 2.0
11.23k stars 851 forks source link

[Feature] Playwright should be able to install browser binaries from poetry install (Python) #1322

Open dil-gfischhof opened 2 years ago

dil-gfischhof commented 2 years ago

Playwright should be able to install browser binaries from poetry install (Python) (Specially related to CI systems)

Hi Folks,

Two things to start my feature request with: 1.) Poetry is practically the new way of Python package management 2.) Installing project dependencies is practically the responsibility of the project (yes, the borders are flexible...)

So I have the following situation: we have a project which needs in-browser testing, and API testing, perhaps someone will need other (performance etc) testing, which does not require browser.

Right now we use Poetry (Python) to install dependencies, it installs Playwright, but is not able to tell Playwright to install browsers binaries.

So now we have to setup our CI to install browser binaries, but the other CI jobs do not need that, so installing is just waste of time and space. But it would be good to have only one type of test job in CI: install project dependencies, and start testing. And if the project needs browser then it should install it automatically.

BR, George

yury-s commented 2 years ago

Can you explain how you see this working with poetry (what commands the user would have to run to install playwright with browsers vs. without them)? Or do you want it to essentially run playwright install as part of playwright installation?

dil-gfischhof commented 2 years ago

Hi,

as playwright's strength is browser automation, so I think it should install browser as default.

Installing all would be time and space consuming, so I think installing the one with the largest market share -which is chromium- would be a good choice for default.

The adding method / syntax for browsers should follow optional dependencies: poetry add playwright - would install chromium poetry add playwright[chromium] - would install chromium poetry add playwright[all]- would install all poetry add playwright[chrome, firefox] - would install chrome and firefox poetry add playwright[no-browser] - would not install any browser

and I think it would be good to add browser dependencies automatically too, specially because the user may not know what are the dependencies and what kind of dependencies are there, what will not work without them

BR, George

codejedi-ai commented 1 year ago

As of right now poetry add playwright does not work instead it throws and error. I am currently using poetry 1.1.13. How should I structure the commands to add playwright?

dil-gfischhof commented 1 year ago

@codejedi-ai What error do you have?

FredHappyface commented 1 year ago

Currently I use https://github.com/pyppeteer/pyppeteer within a python library to launch a headless chrome instance, do some "stuff"

https://github.com/pyppeteer/pyppeteer currently will install a chrome instance on the first run. For example when testing a poetry project with 'tox'. As this is intended for a library and poetry will not provide the means to add a post install script to my lib is it possible to install a browser at runtime as with pyppeteer?

Potential solutions to this problem are:

  1. Continue using an out of support tool [less than ideal]
  2. Use a different packaging tool that supports post-install
  3. Ask "playwright" devs if they'd consider installing a browser binary with pip install [seems compatible with the 'happy path' for an end user too rather than running playwright install
  4. Ask "playwright" devs if they'd consider exposing some function call to do a playwright install eg
    from playwright import install
    install("chrome")

    There is already a project that acheived this by calling pyright install with the subprocess module https://pypi.org/project/install-playwright/

Thank you for your time :)

umang94 commented 3 months ago

Hi, I ran into this problem while setting up langchain for webscraping. Looks like Poetry as a tool will never support post-install scripts. @mxschmitt How long is the feedback collection process ? The 7 likes on @dil-gfischhof 's approach makes it seem like there is consensus.

DanteOz commented 1 month ago

+1 for @dil-gfischhof 's suggestion

Using optional dependencies to install browsers would simplify CI, and help the dev workflow, for the project I'm currently working on. Would be great to see a resolution on this issue, either way, given the original creation date.

nmzabith commented 1 month ago

+1 for the suggestion

came across the issue while deploying a web scraping service, its clean if we can do this within poetry