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

Screenshots in macOS Safari: Unable to locate the page area - mark not found. #8154

Closed
htho opened this issue Mar 14, 2024 · 5 comments
Closed
Assignees
Labels
TYPE: bug The described behavior is considered as wrong (bug).

Comments

@htho
Copy link
Contributor

htho commented Mar 14, 2024

What is your Scenario?

I do visual regression tests. Now I need to test Safari as well.

What is the Current behavior?

When I run the tests, the screenshot is not cropped - so the window chrome (frame, browser-bars etc.) is still included, and the mark is visible in the bottom right corner.

safari--screenshot
Test "Screenhot" - in Safari

What is the Expected behavior?

The screenshots should be cropped and not include the mark. Also there should be no warning in the log. Like for example in Chrome on macOS.

chrome--screenshot
Test "Screenhot" - in Chrome

What is the public URL of the test page? (attach your complete example)

I created a repository at https://github.com/htho/testcafe-repro-screenshot-mark-macos-14

What is your TestCafe test code?

import { fixture, test } from "testcafe";

const allowedChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
export function mkValidPath(path: string): string {
	return path.split("").map(char => allowedChars.includes(char) ? char : "_").join("");
}

fixture("screenshot")
    .page("about:blank");

test("screenshot", async t => {
    await t.eval(() => document.body.style.backgroundColor = "#dde")
    await t.resizeWindow(640, 480);
    await t.takeScreenshot(mkValidPath(`${t.browser.alias}--${t.test.name}`));
});

Your complete configuration file

none

Your complete test report

% npm run test

> testcafe-repro-screenshot-mark-macos-14@1.0.0 test
> testcafe safari screenshot.tc.ts

(node:5212) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
 Running tests in:
 - Safari 17.3.1 / Sonoma 14

 screenshot
 ✓ screenshot (screenshots: /Users/xxx/testcafe-repro-screenshot-mark-macos-14/screenshots/safari--screenshot.png)


 1 passed (3s)

 Warnings (1):
 --
  Unable to locate the page area in the browser window screenshot at /Users/xxx/testcafe-repro-screenshot-mark-macos-14/screenshots/safari--screenshot.png, because the page area
  mark with ID 3194121322 is not found in the screenshot.

Screenshots

No response

Steps to Reproduce

  1. % git clone https://github.com/htho/testcafe-repro-screenshot-mark-macos-14.git
  2. % cd testcafe-repro-screenshot-mark-macos-14
  3. % npm i
  4. % npm run test

TestCafe version

3.5.0

Node.js version

21.6.2

Command-line arguments

testcafe safari screenshot.tc.ts

Browser name(s) and version(s)

Safari 17.3.1

Platform(s) and version(s)

macOS 14.3.1

Other

No response

@htho htho added the TYPE: bug The described behavior is considered as wrong (bug). label Mar 14, 2024
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 14, 2024
@htho
Copy link
Contributor Author

htho commented Mar 14, 2024

I assume it has something to do with macOS rounded corners.
In https://github.com/DevExpress/testcafe/blob/master/src/screenshots/constants.js
I increased MARK_RIGHT_MARGIN from 10 to 15 and it solved the problem.

But I don't know why there is no such problem in Chrome although it also has rounded corners in macOS.
However the Chrome screenshot does not have rounded corners.

@PavelMor25
Copy link
Collaborator

Hello @htho,

TestCafe allows you to capture screenshots of the application at any point during a test run or when a test fails - this helps in debugging. However, please note that TestCafe does not include a scenario for visual regression tests. As a result, we cannot guarantee consistent screenshots across different versions.

In theory, you can use TestCafe for screenshot testing, but since Safari and Chrome are two completely different browsers, their HTML rendering and screenshot mechanisms differ. This leads to visual discrepancies. We recommend comparing screenshots within the same browser, not across different ones.

At this moment, we're unable to prioritize the task of adjusting the UI on screenshots for Safari as we have other priorities with our tasks. In the future, if this issue becomes more prominent, we will revisit the consideration of this improvement.

@PavelMor25 PavelMor25 removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 20, 2024
@htho
Copy link
Contributor Author

htho commented Mar 20, 2024

Hello @PavelMor25

I am aware that screenshots from two different browsers can not simply be compared.
This bug is not about differences between Chrome and Safari. This issue is about Safari on macOS, where TestCafe produces an error because it can not find the screenshot mark. Chrome is only cited to show how it should be.

Since there is the screenshot-feature in TestCafe, it makes sense for it to work - right?

Anyway, I am willing to create a PR for this.
Would you accept any PR regarding this, although it is not your priority right now?

@PavelMor25 PavelMor25 added the STATE: Need response An issue that requires a response or attention from the team. label Mar 21, 2024
@PavelMor25
Copy link
Collaborator

@htho,

We are always happy to consider all proposed changes. You can submit a pull request and include a description. We will review it and accept it if everything is okay.

Before creating the fix, please take a look at our contributing guide

@PavelMor25 PavelMor25 removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 26, 2024
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 26, 2024
@PavelMor25 PavelMor25 removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 26, 2024
@PavelMor25 PavelMor25 self-assigned this Apr 1, 2024
PavelMor25 pushed a commit that referenced this issue Apr 9, 2024
## Purpose
#8154 addresses the issue, where screenshots are not cropped on macOS
(14) Safari.
The problem is, that the screenshot mark can not be found.
This is because part of the mark is not visible because of the rounded
corners in macOS.


![312752882-4a8a5548-85e3-4805-855e-608366c74c8b](https://github.com/DevExpress/testcafe/assets/2182288/be53f18f-be1a-41ce-b432-26b68aa561e4)

## Approach
The solution is to increase `MARK_RIGHT_MARGIN` in
`src/screenshots/constants.js`.
I found that `25` is the lowest value that works for all resolutions I
was able to test.

* In order for the tests to work I parametrized the tests to depend on
`MARK_RIGHT_MARGIN`.
* ~~I enabled the screenshot-tests that were skipped in the safari
browser~~
  * ~~fix tests~~
  * ~~retina aware~~
  * ~~color-profile aware~~

## References
#8154 

## Pre-Merge TODO
- [x] Write tests for your proposed changes
- [x] Make sure that existing tests do not fail

---------

Co-authored-by: gti <support@gti.de>
@htho
Copy link
Contributor Author

htho commented Apr 9, 2024

fixed by #8161

@htho htho closed this as completed Apr 9, 2024
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Apr 9, 2024
@PavelMor25 PavelMor25 removed the STATE: Need response An issue that requires a response or attention from the team. label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

2 participants