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

bug: Cannot create a screenshot of a hover state in e2e test #3188

Closed
3 tasks done
borisdiakur opened this issue Dec 15, 2021 · 5 comments · Fixed by #5828 or ionic-team/ionic-framework#29666
Closed
3 tasks done
Assignees
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@borisdiakur
Copy link

borisdiakur commented Dec 15, 2021

Prerequisites

Stencil Version

2.12.0

Current Behavior

It seems impossible to create a screenshot of a hover state in e2e tests. As soon as the screenshot is made the hover state is unset.

Expected Behavior

I should be able to hover a component in a e2e test and create a screenshot of the hovered component.

Steps to Reproduce

  1. Clone https://github.com/borisdiakur/mwe-stencil-screenshot-hover-issue
  2. Install dependencies
  3. Run stencil test --e2e --screenshot
  4. Observe in chromium how the hover state is unset as soon as the screenshot is being made
  5. Check the created image files in the screenshot directory (component should be red, but it's green)

Code Reproduction URL

https://github.com/borisdiakur/mwe-stencil-screenshot-hover-issue

Additional Information

Environment:

  • @stencil/core: ^2.12.0
  • node: v17.2.0
  • OS: macOS Monterey 12.0.1
  • Chip: Apple M1 Max

This issue is related to #3145
When I add captureBeyondViewport: false to the createPuppeteerScreenshopOptions in node_modules/@stencil/core/testing/index.js the screenshot does not change the hover state of the component (it is still red).

@ionitron-bot ionitron-bot bot added the triage label Dec 15, 2021
@rwaskiewicz
Copy link
Contributor

👋 Thanks for the reproduction case, they greatly help looking at issues! I took a look, and there seems to be a timing issue of sorts here. I can reproduce the issue, but only some of the time (with a machine that has very similar specs to your's). I'm going to label this issue to get it ingested into our internal backlog for the team to take a further look.

For what it's worth, I had a harder time reproducing this when I made the following change to
my-component.e2e.ts:

  it('has a hover state', async () => {
    const page = await newE2EPage();

    await page.setContent('<my-component></my-component>');
    await page.hover('my-component')
-   await page.waitForTimeout(1000)
    const results = await page.compareScreenshot()
    await page.waitForTimeout(3000)
    expect(results).toMatchScreenshot()
  });

But I understand this is just your reproduction case and is probably simpler than the one you're working in (and that 'fix' may not apply)

@rwaskiewicz rwaskiewicz added Bug: Validated This PR or Issue is verified to be a bug within Stencil Feature: Testing and removed triage labels Dec 16, 2021
@johnjenkins
Copy link
Contributor

I managed to monkey patch the screenshot method

const screenshot = page.screenshot;
page.screenshot = async function () {
    return screenshot.call(page, {
      captureBeyondViewport: false,
    });
};

When I setup my tests. That fixes it for me

@borisdiakur
Copy link
Author

Thank you @johnjenkins 🙏
I can confirm that the monkey patch helps fixing the issue.

@ryuran
Copy link

ryuran commented Jan 7, 2022

Thanks @johnjenkins it unlocks my team.
Typescript version we use:

const screenshot = (page as E2EPageInternal).screenshot;
(page as E2EPageInternal).screenshot = function () {
  return screenshot.call(page, { captureBeyondViewport: false });
};

@tanner-reits
Copy link
Contributor

This was included in today's v4.19.0 release!

github-merge-queue bot pushed a commit to ionic-team/ionic-framework that referenced this issue Jun 26, 2024
### Release Notes

<details>
<summary>ionic-team/stencil (@&#8203;stencil/core)</summary>

###
[`v4.19.0`](https://togithub.com/ionic-team/stencil/blob/HEAD/CHANGELOG.md#-4190-2024-06-26)

[Compare
Source](https://togithub.com/ionic-team/stencil/compare/v4.18.3...v4.19.0)

### Bug Fixes

* **compiler:** support rollup's external input option
([#3227](stenciljs/core#3227))
([2c68849](stenciljs/core@2c68849)),
fixes [#3226](stenciljs/core#3226)
* **emit:** don't emit test files
([#5789](stenciljs/core#5789))
([50892f1](stenciljs/core@50892f1)),
fixes [#5788](stenciljs/core#5788)
* **hyrdate:** support vdom annotation in nested dsd structures
([#5856](stenciljs/core#5856))
([61bb5e3](stenciljs/core@61bb5e3))
* label attribute not toggling input
([#3474](stenciljs/core#3474))
([13db920](stenciljs/core@13db920)),
fixes [#3473](stenciljs/core#3473)
* **mock-doc:** expose ShadowRoot and DocumentFragment globals
([#5827](stenciljs/core#5827))
([98bbd7c](stenciljs/core@98bbd7c)),
fixes [#3260](stenciljs/core#3260)
* **runtime:** allow watchers to fire w/ no Stencil members
([#5855](stenciljs/core#5855))
([850ad4f](stenciljs/core@850ad4f)),
fixes [#5854](stenciljs/core#5854)
* **runtime:** catch errors in async lifecycle methods
([#5826](stenciljs/core#5826))
([87e5b33](stenciljs/core@87e5b33)),
fixes [#5824](stenciljs/core#5824)
* **runtime:** don't register listener before connected to DOM
([#5844](stenciljs/core#5844))
([9d7021f](stenciljs/core@9d7021f)),
fixes [#4067](stenciljs/core#4067)
* **runtime:** properly assign style declarations
([#5838](stenciljs/core#5838))
([5c10ebf](stenciljs/core@5c10ebf))
* **testing:** allow to re-use pages across it blocks
([#5830](stenciljs/core#5830))
([561eab4](stenciljs/core@561eab4)),
fixes [#3720](stenciljs/core#3720)
* **typescript:** remove unsupported label property
([#5840](stenciljs/core#5840))
([d26ea2b](stenciljs/core@d26ea2b)),
fixes [#3473](stenciljs/core#3473)


### Features

* **cli:** support generation of sass and less files
([#5857](stenciljs/core#5857))
([1883812](stenciljs/core@1883812)),
closes [#2155](stenciljs/core#2155)
* **compiler:** generate export maps on build
([#5809](stenciljs/core#5809))
([b6d2404](stenciljs/core@b6d2404))
* **complier:** support type import aliasing
([#5836](stenciljs/core#5836))
([7ffb25d](stenciljs/core@7ffb25d)),
closes [#2335](stenciljs/core#2335)
* **runtime:** support declarative shadow DOM
([#5792](stenciljs/core#5792))
([c837063](stenciljs/core@c837063)),
closes [#4010](stenciljs/core#4010)
* **testing:** add `toHaveLastReceivedEventDetail` event spy matcher
([#5829](stenciljs/core#5829))
([63491de](stenciljs/core@63491de)),
closes [#2488](stenciljs/core#2488)
* **testing:** allow to disable network error logging via
'logFailingNetworkRequests' option
([#5839](stenciljs/core#5839))
([dac3e33](stenciljs/core@dac3e33)),
closes [#2572](stenciljs/core#2572)
* **testing:** expose captureBeyondViewport in pageCompareScreenshot
([#5828](stenciljs/core#5828))
([cf6a450](stenciljs/core@cf6a450)),
closes [#3188](stenciljs/core#3188)

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
6 participants