question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] not.toBeVisible() assertion incorrectly fails at mobile screen resolution (width <= 575px)

See original GitHub issue

Context:

  • Playwright Version: 1.27.1
  • Operating System: Linux Mint 20.3 Cinnamon 5.2.7
  • Node.js version: 16.15.0
  • Browser: All
<!-- CLI to auto-capture this info -->

    Running 1 test using 1 worker
    1) [chromium] › ngx-admin/homepage.spec.ts:62:6 › Validate Home Page loads correctly in different resolutions 

    Error: expect(received).not.toBeVisible()
    Call log:
      - expect.toBeVisible with timeout 5000ms
      - waiting for selector "li.menu-item:has-text("FEATURES") >> nth=0"
      -   selector resolved to <li nbmenuitem="" _ngcontent-rsv-c116="" class="menu…>…</li>
      -   unexpected value "true"
      -   selector resolved to <li nbmenuitem="" _ngcontent-rsv-c116="" class="menu…>…</li>
      -   unexpected value "true"
      -   selector resolved to <li nbmenuitem="" _ngcontent-rsv-c116="" class="menu…>…</li>
      -   unexpected value "true"
      -   selector resolved to <li nbmenuitem="" _ngcontent-rsv-c116="" class="menu…>…</li>
      -   unexpected value "true"
      -   selector resolved to <li nbmenuitem="" _ngcontent-rsv-c116="" class="menu…>…</li>
      -   unexpected value "true"
      -   selector resolved to <li nbmenuitem="" _ngcontent-rsv-c116="" class="menu…>…</li>
      -   unexpected value "true"
      -   selector resolved to <li nbmenuitem="" _ngcontent-rsv-c116="" class="menu…>…</li>
      -   unexpected value "true"


      70 |     await expect(page.locator('li.menu-item:has-text("FEATURES")').first()).not.toBeVisible();
      71 |     await page.setViewportSize({ width: 375, height: 812 }); // iPhone X
    > 72 |     await expect(page.locator('li.menu-item:has-text("FEATURES")').first()).not.toBeVisible();
         |                                                                                 ^
      73 | });
      74 |
<!-- npx envinfo --preset playwright --markdown -->
## System:
 - OS: Linux 5.4 Linux Mint 20.3 (Una)
 - Memory: 19.67 GB / 29.40 GB
 - Container: Yes
## Binaries:
 - Node: 16.15.0 - /usr/local/bin/node
 - Yarn: 1.22.19 - /usr/bin/yarn
 - npm: 8.11.0 - /usr/local/bin/npm
## Languages:
 - Bash: 5.0.17 - /usr/bin/bash
## npmPackages:
 - playwright: ^1.27.1 => 1.27.1 

Code Snippet Validating www.akveo.com/ngx-admin application homepage at different screen resolutions:

test('Validate Home Page loads correctly in different resolutions', async ({ page }) => {
    await page.goto('https://www.akveo.com/ngx-admin/themes')
    await page.locator('nb-card-body img[alt="Material Light Theme"]').click()
    await page.setViewportSize({ width: 1920, height: 1080 }); // Full HD
    await expect(page.locator('li.menu-item:has-text("FEATURES")').first()).toBeVisible();
    await page.setViewportSize({ width: 1280, height: 800 }); // macbook-13
    await expect(page.locator('li.menu-item:has-text("FEATURES")').first()).toBeVisible();
    await page.setViewportSize({ width: 810, height: 1080 }); // iPad
    await expect(page.locator('li.menu-item:has-text("FEATURES")').first()).not.toBeVisible();
    await page.setViewportSize({ width: 375, height: 812 }); // iPhone X
    await expect(page.locator('li.menu-item:has-text("FEATURES")').first()).not.toBeVisible();
});

Describe the bug The www.akveo.com/ngx-admin is used as a demo application under test If you run the code from the snippet, the first 3 validations will pass, and the last one will fail — that is an incorrect, because the li.menu-item:has-text("FEATURES") element is definitely not visible.

NOTE: the 3rd validation (at the iPad resolution) passes correctly, as the element is already not visible at this resolution. But as soon as the width of the viewport becomes 575 pixels or less — Playwrigth starts to see this element again despite it’s absence on the screen.

The bug was discovered while building a pet test automation project for 1:1 comparison with Cypress (which didn’t have this issue)

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pavelfeldmancommented, Nov 14, 2022

I don’t think it is an app bug per se - menu area is occluded by an opaque element, so the user taps won’t trigger the menu. But we can’t known that before we start clicking - the element is technically visible, everything above it can be transparent and pointer-events: none-y. I would not know why it is not caught by Cypress.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot check expect(elm).not.toBeVisible() for semantic-ui ...
An element is visible if all the following conditions are met: it does not have its css property display set to none; it...
Read more >
Requires 1024x768 screen resolution - NWEA Connection
This error occurs if your screen resolution is smaller than 1024x768. This error can also occur when the display or font size is...
Read more >
Change your screen resolution in Windows - Microsoft Support
Learn how to improve the clarity of text and images displayed on your screen by changing the screen resolution of your monitor.
Read more >
Window.devicePixelRatio - Web APIs | MDN
The devicePixelRatio of Window interface returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the ...
Read more >
Change desktop screen resolution in Selenium tests
Sample resolutions and how they appear in video logs; Example code snippets. Note: Browser window is not maximized upon launch in any Selenium...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found