Skip to content

Conversation

@afomi
Copy link

@afomi afomi commented Nov 12, 2025

  • for ChromeDriver and GeckoDriver

* for ChromeDriver and GeckoDriver
@afomi afomi changed the title support full-page screenshots feat: support full-page screenshots Nov 12, 2025
assert_file_exists(path)

# Verify the file is a valid PNG by checking the PNG signature
{:ok, file_content} = File.read(path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use File.read! here, so if it fails, it fails with the right error and not a match error.

ensure_setting_is_reset(:wallaby, :screenshot_dir)
Application.put_env(:wallaby, :screenshot_dir, screenshots_path)

[path] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[path] =
assert [path] =


# Verify the file is a valid PNG by checking the PNG signature
{:ok, file_content} = File.read(path)
<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, _rest::binary>> = file_content
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, _rest::binary>> = file_content
assert <<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, _rest::binary>> = file_content

Application.put_env(:wallaby, :screenshot_dir, screenshots_path)

# Both of these should work the same way (viewport screenshot)
[path1] = page |> take_screenshot(name: "test1") |> Map.get(:screenshots)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[path1] = page |> take_screenshot(name: "test1") |> Map.get(:screenshots)
assert [path1] = page |> take_screenshot(name: "test1") |> Map.get(:screenshots)


# Both of these should work the same way (viewport screenshot)
[path1] = page |> take_screenshot(name: "test1") |> Map.get(:screenshots)
[path2] = page |> take_screenshot(name: "test2", full_page: false) |> Map.get(:screenshots)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[path2] = page |> take_screenshot(name: "test2", full_page: false) |> Map.get(:screenshots)
assert [path2] = page |> take_screenshot(name: "test2", full_page: false) |> Map.get(:screenshots)

Comment on lines +235 to +236
- Chrome: Uses Chrome DevTools Protocol (CDP) for native fullpage capture
- Firefox: Uses GeckoDriver's Moz-specific fullpage screenshot endpoint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this information relevant? I feel like implies to the user that they should know how these things work, but the respective webdriver takes care of it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to indicate which versions of the webdriver that supports this functionality


@doc false
def take_fullpage_screenshot(session_or_element) do
WebdriverClient.take_fullpage_screenshot_moz(session_or_element)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, selenium is not only used for Firefox. You can use it with any browser/web driver it supports. I think this code won't work if you use selenium with chrome.

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

Successfully merging this pull request may close these issues.

2 participants