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

[Feature] Watch for quick changes on the website #22930

Closed
aklajnert opened this issue May 10, 2023 · 2 comments
Closed

[Feature] Watch for quick changes on the website #22930

aklajnert opened this issue May 10, 2023 · 2 comments

Comments

@aklajnert
Copy link

Currently, in my project I have a bug, when I quickly cycle between two tabs, for a split second the tab content displays something that it shouldn't. I was thinking about writing a test for it, but it seems impossible to have a reliable test for it. Here's what I did:

page.get_by_test_id("tab-1").click()

expect(page.get_by_test_id("unwanted-section").not_to_be_visible()
expect(page.get_by_test_id("expected-content").to_be_visible()

The problem is that this test will always pass since the first expect() will wait until the unwanted element is gone.

What would be helpful in this case, is a simple context manager:

with ensure_condition(page.get_by_test_id("unwanted-section").not_to_be_visible():
    page.get_by_test_id("tab-1").click()
    expect(page.get_by_test_id("expected-content").to_be_visible()

The new ensure_condition() context manager would work similarly to expect(), but instead of waiting for the condition to be met, it will ensure it is like that for the whole with block. That means that the unwanted-section showing up anytime while this block is active will trigger an error. This could be also slightly extended (maybe parametrized?) to allow also catching elements that are expected to show for a brief moment, which is also hard to catch with regular except(). But in this case the ensure_condition() or equivalent would need to react on the condition being met at least once within the with block.

This seems to be a bit similar to microsoft/playwright-python#1638.

@mxschmitt mxschmitt transferred this issue from microsoft/playwright-python May 10, 2023
@pavelfeldman
Copy link
Member

Playwright can not detect something that shows up for a split second as of today. If I were to implement something like this, I would do that in the web page via using MutationObserver. I would evaluate code that install mutation observer and calls console.log when it detected something that should not happen. I would log all the console messages and assert them after the test.

@pavelfeldman
Copy link
Member

Closing as per above, please feel free to open a new issue if this does not cover your use case.

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

No branches or pull requests

2 participants