Skip to content

Commit

Permalink
Fix TestPageScreenshotFullpage on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Jan 15, 2025
1 parent 96ad387 commit 3dcc9db
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions js/modules/k6/browser/tests/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ func TestPageScreenshotFullpage(t *testing.T) {
const div = document.createElement('div');
div.style.width = '1280px';
div.style.height = '800px';
div.style.background = 'linear-gradient(red, blue)';
div.style.background = 'linear-gradient(to bottom, red, blue)';
document.body.appendChild(div);
}`)
Expand All @@ -688,15 +688,16 @@ func TestPageScreenshotFullpage(t *testing.T) {
img, err := png.Decode(reader)
assert.Nil(t, err)

assert.Equal(t, 1280, img.Bounds().Max.X, "screenshot width is not 1280px as expected, but %dpx", img.Bounds().Max.X)
assert.Equal(t, 800, img.Bounds().Max.Y, "screenshot height is not 800px as expected, but %dpx", img.Bounds().Max.Y)
assert.Equal(t, 1280, img.Bounds().Max.X, "want: screenshot width is 1280px, got: %dpx", img.Bounds().Max.X)
assert.Equal(t, 800, img.Bounds().Max.Y, "want: screenshot height is 800px, got: %dpx", img.Bounds().Max.Y)

// Allow tolerance to account for differences in rendering between
// different platforms and browsers. The goal is to ensure that the
// screenshot is mostly red at the top and mostly blue at the bottom.
r, _, b, _ := img.At(0, 0).RGBA()
assert.Greater(t, r, uint32(128))
assert.Less(t, b, uint32(128))
require.Truef(t, r > b*2, "want: the top pixel to be dominantly red, got R: %d, B: %d", r, b)
r, _, b, _ = img.At(0, 799).RGBA()
assert.Less(t, r, uint32(128))
assert.Greater(t, b, uint32(128))
require.Truef(t, b > r*2, "want: the bottom pixel to be dominantly blue, got R: %d, B: %d", r, b)
}

func TestPageTitle(t *testing.T) {
Expand Down

0 comments on commit 3dcc9db

Please sign in to comment.