Skip to content

Commit 23a27be

Browse files
rmehnermattheworiordan
authored andcommitted
Add support for Playwright driver
This adds support to take full page screenshots when you are using the [playwright driver](https://github.com/YusukeIwaki/capybara-playwright-driver) This has been tested in our projects and works like a charm :)
1 parent 6b80ac2 commit 23a27be

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/capybara-screenshot.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ def self.capybara_tmp_path=(path)
198198
register_driver(:cuprite) do |driver, path|
199199
driver.render(path, :full => true)
200200
end
201+
202+
register_driver(:playwright) do |driver, path|
203+
driver.with_playwright_page do |page|
204+
page.screenshot(path: path, fullPage: true)
205+
end
206+
end
201207
end
202208

203209
# Register filename prefix formatters

spec/unit/saver_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,24 @@
311311
end
312312
end
313313

314+
describe "with playwright driver" do
315+
let(:playwright_page_mock) {
316+
double('Playwright Page Mock').as_null_object
317+
}
318+
319+
before do
320+
allow(capybara_mock).to receive(:current_driver).and_return(:playwright)
321+
end
322+
323+
it 'saves driver screenshot via playwright page with :fullPage => true' do
324+
expect(driver_mock).to receive(:with_playwright_page).and_yield(playwright_page_mock)
325+
expect(playwright_page_mock).to receive(:screenshot).with(path: screenshot_path, fullPage: true)
326+
327+
saver.save
328+
expect(saver).to be_screenshot_saved
329+
end
330+
end
331+
314332
describe "with webkit driver" do
315333
before do
316334
allow(capybara_mock).to receive(:current_driver).and_return(:webkit)

0 commit comments

Comments
 (0)