Skip to content
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

Closed
GunjanSheth opened this issue Jan 16, 2023 · 8 comments
Closed

[Question]: Can I set retrying action attempt ? #1727

GunjanSheth opened this issue Jan 16, 2023 · 8 comments

Comments

@GunjanSheth
Copy link

GunjanSheth commented Jan 16, 2023

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

import time

url = "https://the-internet.herokuapp.com/exit_intent"
with playwright.sync_api.sync_playwright() as playwright:
    browser = playwright.chromium.launch(headless=False, channel="chrome")
    page = browser.new_page()
    page.goto(url)
    page.mouse.move(50, 50)
    time.sleep(1)
    page.mouse.move(-5, -5)
    time.sleep(2)
    page.locator("xpath=//h3[text()='Exit Intent']").click()
    time.sleep(2)

the above will reproduce the following error

playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "xpath=//h3[text()='Exit Intent']"
  selector resolved to visible <h3>Exit Intent</h3>
attempting click action
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #1
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #2
  waiting 20ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #3
  waiting 100ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #4
  waiting 100ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #5
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #6
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #7
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #8
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #9
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #10
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #11
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #12
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #13
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #14
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #15
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #16
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #17
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #18
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #19
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #20
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #21
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #22
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #23
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #24
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #25
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #26
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #27
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #28
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #29
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #30
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #31
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #32
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #33
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #34
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #35
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #36
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #37
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #38
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #39
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #40
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #41
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #42
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #43
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #44
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #45
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #46
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #47
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #48
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #49
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #50
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #51
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #52
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #53
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #54
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #55
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #56
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #57
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #58
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #59
  waiting 500ms
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  <div class="underlay"></div> from <div id="ouibounce-modal">…</div> subtree intercepts pointer events
retrying click action, attempt #60
  waiting 500ms
============================================================

Process finished with exit code 1


@sueskind
Copy link

sueskind commented Jan 17, 2023

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:

  • Playwright tries to click the element <h3>Exit Intent</h3>.
  • This element is not clickable since it is overlayed by the modal dialog.
  • Playwright tries to click it repeatedly with increasing delays (0ms, 20ms, 100ms, 100ms, 500ms, 500ms, ...).
  • After 30s (i.e. 30000ms) the timeout is reached and an error thrown. This is the default timeout. Incidentally this is after exactly 60 tries in your case.

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 time.sleep() is actively discouraged.

Furthermore, the selector for your to-be-clicked element can be vastly simplified to text='Exit Intent' and the page object also has a click() method which makes the usage of page.locator() unnecessary. I would suggest the following improved version of your code, assuming that you wanted to click somewhere next to the dialog:

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 page.click("Close").

@GunjanSheth
Copy link
Author

@sueskind
thanks for your detailed answer, i wasn't aware of the fact
Playwright tries to click it repeatedly with increasing delays (0ms, 20ms, 100ms, 100ms, 500ms, 500ms, ...).

i tried to reduce the default timeout and the number of tries did lessen up

thanks a lot that would help me

@sarthak9793
Copy link

@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.

@sueskind
Copy link

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).

@sarthak9793
Copy link

sarthak9793 commented Sep 22, 2024

@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.

  • attempting click action
  • waiting for element to be visible, enabled and stable
  • element is visible, enabled and stable
  • scrolling into view if needed
  • done scrolling
  • ?
    from
    ?
    subtree intercepts pointer events
  • retrying click action, attempt #_1
  • waiting for element to be visible, enabled and stable
  • element is visible, enabled and stable
  • scrolling into view if needed
  • done scrolling
  • ?
    from
    ?
    subtree intercepts pointer events
  • retrying click action, attempt #_2
  • waiting 20ms
  • waiting for element to be visible, enabled and stable
  • element is visible, enabled and stable
  • scrolling into view if needed
  • done scrolling
  • ?
    from
    ?
    subtree intercepts pointer events
  • retrying click action, attempt #_3
  • waiting 100ms
  • waiting for element to be visible, enabled and stable
  • element is visible, enabled and stable
  • scrolling into view if needed
  • done scrolling
  • ?
    from
    ?
    subtree intercepts pointer events
  • retrying click action, attempt #_4
  • waiting 100ms
  • waiting for element to be visible, enabled and stable
  • element is visible, enabled and stable
  • scrolling into view if needed
  • done scrolling
  • ?
    from
    ?
    subtree intercepts pointer events

@sueskind
Copy link

@sarthak9793 I'm not sure if the functionality you are looking for exists out-of-the-box. You could just catch the TimeoutError and raise another one instead, with a shorter message.

@leskop2
Copy link

leskop2 commented Oct 1, 2024

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

@adamreisnz
Copy link

adamreisnz commented Oct 13, 2024

Is this page timeout configurable on a global level via the config?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants