-
Notifications
You must be signed in to change notification settings - Fork 993
Verify files status in parallel while using bulk upload #1480
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
Comments
Thanks for your report! I'm not fully following. Can you include your previous attempts with some comments in the code so I can get a better sense of what you're trying to do? Thanks! |
Ok, so here are two examples:
if name == "main":
async def verify_upload(page, entry_name): async def main():
asyncio.run(main()) I'm not sure how to pass the page so that it will work, I'm getting error when I'm getting to the expect in verify_upload, also not sure that it's even the correct way, I got a little bit confused how to do it. |
Thanks—I recommend keeping it as simple as possible. Avoid using Your line:
looks good. If you run the script to that point and manually looks at the page, is it doing the correct thing, or is it stuck before there? Once you manually confirm the files are uploading, I recommend verifying the uploads serially. With async, you'll be able to parallelize to a degree, but it'll be helpful to first get it working inline. |
Here's a standalone example for some inspiration: import asyncio
from playwright.async_api import async_playwright, expect
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=False)
page = await browser.new_page()
await page.goto("https://pw.rwoll.dev/file-uploads")
await page.locator("input[type=file]").set_input_files(["a.txt", "b.txt", "c.txt"])
await page.wait_for_timeout(10000)
# option 1: simple multi text match
await expect(page.locator("li")).to_contain_text([
"Name: a.txt",
"Name: b.txt",
"Name: c.txt",
])
# alternatives…
# define some verification function with multiple verification assertions
async def verify(name):
await expect(page.locator("li", has_text=name)).to_be_visible()
# …
# any other work you need to do to verify things
# OPTION 2: Run them serially:
for name in ["a.txt", "b.txt", "c.txt"]:
await verify(name)
# OPTION 3: Run them concurrently
tasks = []
for name in ["a.txt", "b.txt", "c.txt"]:
tasks.append(verify(name)) # notice no await!
# c: await all of them to complete
await asyncio.gather(*tasks)
asyncio.run(main()) If you save files |
Thanks for the detailed answer! I tried with option 3 and it works good, but I have another question. @pytest.fixture(scope="session")
@pytest.fixture(scope='session')
Example test:
So my question is how to combine the set up in conftest with the async function and the test, also how to pass all the variables |
Are you using pytest-playwright already? If so, you'll want to stick sync version of option 2 (i.e. drop the
Which variables and where? Also, please format your code in future comments so it's easier to read/follow. |
Yes, I'm using pytest-playwright, but If I'm using option 2 I won't really be able to see what happens to all media that I'm uploading in realtime, until one will finish, other also can, so I won't know if they got the real status. |
Unfortunately not today—please watch for support: microsoft/playwright-pytest#74. Until then, we recommend using the sync API in the testing.
Option 2 of #1480 (comment) can be used. You can either make a helper function that takes in your required variables and calls your check, or create a helper function as a fixture that already has access to page fixture. Neither are Playwright-specific, so the the pytest docs, Community Slack, or Stack Overflow would be alternative resources for generic pytest/python pointers. |
Your question
I'm trying to check status of files while using bulk upload.
for single upload I'm using this verification:
def verify_entry_process_status(self, entry_name):
file_status = self.file_status_selector.replace("ENTRY_NAME", entry_name)
expect(self.page.locator(file_status)).not_to_have_text("Processing", timeout=100000)
expect(self.page.locator(file_status)).to_have_text("Ready")
I'm waiting for the status text not to be processing and then that it was changed to ready.
So for bulk upload I want to use this function for all the files that I uploaded at the same time.
Tried async, multiprocessing, but I'm pretty stuck of how I should to it (new with playwright/async/multiprocessing)
The text was updated successfully, but these errors were encountered: