microsoft / playwright-testing-service

MIT License
89 stars 14 forks source link

Python Support? #98

Open kiebak3r opened 9 months ago

kiebak3r commented 9 months ago

Is your feature request related to a problem? Please describe. Does this or Will this ever be supported with Python using pytest-playwright?

Describe the solution you'd like Python Support

AB#2017180

vvs11 commented 8 months ago

Thanks @kiebak3r for submitting this issue. This is in our backlog. Currently we support Playwright test runner and Nunit runner.

Folks, please upvote 👍 this issue if you want us to prioritize it.

LarsKemmann commented 8 months ago

I'm currently using Playwright from the Python 'playwright' package for web scraping and am curious about whether MPT could be leveraged for this purpose. My alternative is to set up some more involved plumbing to get my code to run in Azure Container Apps, but MPT feels like a quicker way to scale this dynamically and get other managed service benefits.

LarsKemmann commented 8 months ago

I'm currently using Playwright from the Python 'playwright' package for web scraping and am curious about whether MPT could be leveraged for this purpose. My alternative is to set up some more involved plumbing to get my code to run in Azure Container Apps, but MPT feels like a quicker way to scale this dynamically and get other managed service benefits.

Edit: What I'd be curious to see is if MPT can offer any benefits to the scraping use case that I couldn't get by just deploying a Python container with the playwright package installed and using Azure Functions with Azure Container Apps.

winwinashwin commented 1 month ago

I was able to use the service with pytest-playwright by overriding the browser fixture in my conftest.py


## Environment Variables
# PW_SERVICE_URL -> Service URL from Azure
# PW_SERVICE_TOKEN -> Access token generated from Azure. Ref: https://learn.microsoft.com/en-us/azure/playwright-testing/how-to-manage-access-tokens
# PW_SERVICE_RUN_ID -> Any unique identifer for the test run.

import json
import os
import sys
import typing as t

import pytest

if t.TYPE_CHECKING:
    from playwright.sync_api import Browser, Playwright

@pytest.fixture(scope="session")
def browser(playwright: Playwright) -> Browser:
    cap = json.dumps({"os": sys.platform, "runId": os.environ["PW_SERVICE_RUN_ID"]})
    return playwright.chromium.connect(
        f"{os.environ['PW_SERVICE_URL']}?cap={cap}",
        headers={"x-mpt-access-key": os.environ["PW_SERVICE_TOKEN"]},
        expose_network="<loopback>",
    )

NOTE: This still doesn't handle reporting. I was not able to figure that out - yet.

vvs11 commented 1 month ago

Hi @winwinashwin You can run tests written in Python on cloud-hosted browsers with the service. However, you won't be able to get the support for reporting and authentication to the service from the client running the tests via Entra ID. Both of these features work with package that supports Playwright test runner.

itlackey commented 2 weeks ago

My team has a large number of python based playwright tests. We are working towards integrating them into a DevOps pipeline. Is there any guidance on how to use this service with python or an ETA for official support yet?

kiebak3r commented 2 weeks ago

My team has a large number of python based playwright tests. We are working towards integrating them into a DevOps pipeline. Is there any guidance on how to use this service with python or an ETA for official support yet?

In its current state, this is not an option using this service as mentioned above you could run tests but not authenticate or get any results, the current best method for devops integration is allocating multiple agents to a run in your yaml to increase the parallel strategy and then splicing the pytest suite between the agents,

For example, my suite has over 1000 tests which collects all the tests then splits them between 10 agents which on each agent machine can run 2 threads with pytest-xdist concurrently (spec limit)

itlackey commented 2 weeks ago

Thank you for the guidance. We will investigate that option. Is there no current plan to support python?