-
Notifications
You must be signed in to change notification settings - Fork 947
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Question]: Can I set retrying action attempt ? #1727
Comments
Per default, Playwright does something called Auto-waiting. This means it waits for certain criteria to be met, before the action is taken (see the link for an overview). Of course, those criteria might never be met, so there is a timeout after which an error is thrown. Therefore, your situation is more like this:
You have multiple options:
However, it looks like you are trying to write "Selenium-style" code. This whole explicitly waiting business, which one has to do in Selenium, is something that Playwright solves with the auto-waiting feature. Using Furthermore, the selector for your to-be-clicked element can be vastly simplified to from playwright.sync_api import sync_playwright
url = "https://the-internet.herokuapp.com/exit_intent"
with sync_playwright() as playwright:
browser = playwright.chromium.launch(headless=False, channel="chrome")
page = browser.new_page()
page.goto(url)
page.mouse.move(50, 50) # necessary so the website registers "moving out" of frame
page.mouse.move(-5, -5) # move mouse out of frame
page.wait_for_selector("text='This is a modal window'") # make sure the pop-up appears
page.mouse.click(5, 5) # moving to the upper left corner and clicking, so the pop-up disappears Then you could for example use the Locator assertions to check that the modal window has disappeared again. If clicking the "Close" button instead of somewhere next to the dialog is fine, too, you can replace the last two lines with |
@sueskind i tried to reduce the default timeout and the number of tries did lessen up thanks a lot that would help me |
@sueskind Do you have an idea how to not log the retrying action in console? I want to avoid the spamming, which is especially bad for large test suites. |
@sarthak9793 Do you have a minimal code example where this is the case? It's been some months when I worked last with playwright, but don't remember this being a thing (except for errors of course, but I guess this is desired). |
@sueskind I just mean that I dont want this retrying message to be logged into the console, even if this is there is an error. I would be okay with a simple message that the element was not found. I dont to log the details of all the attempts.
|
@sarthak9793 I'm not sure if the functionality you are looking for exists out-of-the-box. You could just catch the |
I agree with @sarthak9793 that producing 59 messages for retrying or waiting in logs is extremely annoying, especially when tests running in parallel, but in test reports(allure) as well |
Is this page timeout configurable on a global level via the config? |
Your question
Playwright keeps on retrying on its own, to perform an Action multiple number of time, probably 60 times by default, before it logs a failure.
Sometimes it seems silly to retry for 60 times, so is there a way to stop this or set it to some other value ?
This usually can be reproduced when there is an unwanted Modal overlay, and your code is clicking some element underneath the modal.
Now i tried the "force=True" over the click method in the following example and it worked, but obviously in my real application, the overlay does not appear on specific click, but can appear on any random click. So i am looking for a way to restrict the retries or stop it all together
Repro steps
the above will reproduce the following error
The text was updated successfully, but these errors were encountered: