Skip to content

Commit

Permalink
feat(vrt): allow providing screenshot style
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeIwaki committed Dec 24, 2023
1 parent cdc90eb commit 3867bfe
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/playwright/channel_owners/element_handle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def screenshot(
path: nil,
quality: nil,
scale: nil,
style: nil,
timeout: nil,
type: nil)

Expand All @@ -312,6 +313,7 @@ def screenshot(
path: path,
quality: quality,
scale: scale,
style: style,
timeout: timeout,
type: type,
}.compact
Expand Down
2 changes: 2 additions & 0 deletions lib/playwright/channel_owners/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ def screenshot(
path: nil,
quality: nil,
scale: nil,
style: nil,
timeout: nil,
type: nil)

Expand All @@ -470,6 +471,7 @@ def screenshot(
animations: animations,
caret: caret,
scale: scale,
style: style,
timeout: timeout,
}.compact
if mask.is_a?(Enumerable)
Expand Down
2 changes: 2 additions & 0 deletions lib/playwright/locator_impl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def screenshot(
path: nil,
quality: nil,
scale: nil,
style: nil,
timeout: nil,
type: nil)

Expand All @@ -376,6 +377,7 @@ def screenshot(
path: path,
quality: quality,
scale: scale,
style: style,
timeout: options[:timeout],
type: type)
end
Expand Down
58 changes: 58 additions & 0 deletions spec/integration/page/screenshot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,64 @@
expect(masked).not_to eq(original)
end
end

it 'should work when mask color is not pink #F0F' do
with_page do |page|
page.viewport_size = { width: 500, height: 500 }
page.goto("#{server_prefix}/grid.html")

masked = page.screenshot(
mask: [page.locator('div').nth(5)],
maskColor: '#00FF00',
)
original = page.screenshot
expect(masked).not_to eq(original)
end
end

it 'should hide elements based on attr' do
with_page do |page|
page.viewport_size = { width: 500, height: 500 }
page.goto("#{server_prefix}/grid.html")
page.locator('div').nth(5).evaluate("element => {
element.setAttribute('data-test-screenshot', 'hide');
}")
masked = page.screenshot(
# path: 'screenshot-style1.png',
style: <<~CSS
[data-test-screenshot="hide"] {
visibility: hidden;
}
CSS
)
original = page.screenshot
expect(masked).not_to eq(original)
visibility = page.locator('div').nth(5).evaluate("element => element.style.visibility")
expect(visibility).to eq('')
end
end

it 'should remove elements based on attr' do
with_page do |page|
page.viewport_size = { width: 500, height: 500 }
page.goto("#{server_prefix}/grid.html")
page.locator('div').nth(5).evaluate("element => {
element.setAttribute('data-test-screenshot', 'remove');
}")
masked = page.screenshot(
# path: 'screenshot-style2.png',
style: <<~CSS
[data-test-screenshot="remove"] {
display: none;
}
CSS
)
original = page.screenshot
expect(masked).not_to eq(original)
display = page.locator('div').nth(5).evaluate("element => element.style.display")
expect(display).to eq('')
end
end
end

describe 'page screenshot animations', sinatra: true do
Expand Down

0 comments on commit 3867bfe

Please sign in to comment.