Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Support? #98

Open
kiebak3r opened this issue Feb 26, 2024 · 8 comments
Open

Python Support? #98

kiebak3r opened this issue Feb 26, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@kiebak3r
Copy link

kiebak3r commented Feb 26, 2024

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

@kiebak3r kiebak3r added the enhancement New feature or request label Feb 26, 2024
@vvs11
Copy link
Contributor

vvs11 commented Mar 4, 2024

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
Copy link

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
Copy link

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
Copy link

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
Copy link
Contributor

vvs11 commented Oct 18, 2024

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
Copy link

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
Copy link
Author

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants