Skip to content

Commit dcf36e0

Browse files
authored
tests: added for Page.pdf (#41)
1 parent 9bafc23 commit dcf36e0

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

setup.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[tool:pytest]
2-
markers = skip_browser
2+
markers =
3+
skip_browser
4+
only_browser
35
[mypy]
46
ignore_missing_imports = True

tests/conftest.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,21 @@ def is_chromium(browser_name):
111111

112112
@pytest.fixture(autouse=True)
113113
def skip_by_browser(request, browser_name):
114-
if request.node.get_closest_marker("skip_browser"):
115-
if request.node.get_closest_marker("skip_browser").args[0] == browser_name:
116-
pytest.skip("skipped on this platform: {}".format(browser_name))
114+
skip_browsers_names = []
115+
116+
# Allowlist
117+
only_browser_marker = request.node.get_closest_marker("only_browser")
118+
if only_browser_marker:
119+
skip_browsers_names = ["chromium", "firefox", "webkit"]
120+
skip_browsers_names.remove(only_browser_marker.args[0])
121+
122+
# Denylist
123+
skip_browser_marker = request.node.get_closest_marker("skip_browser")
124+
if skip_browser_marker:
125+
skip_browsers_names.append(skip_browser_marker.args[0])
126+
127+
if browser_name in skip_browsers_names:
128+
pytest.skip("skipped on this platform: {}".format(browser_name))
117129

118130

119131
def pytest_addoption(parser):

tests/test_pdf.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) Microsoft Corporation.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import pytest
17+
18+
from playwright.page import Page
19+
20+
21+
@pytest.mark.only_browser("chromium")
22+
async def test_should_be_able_to_save_pdf_file(page: Page, server, tmpdir):
23+
output_file = tmpdir / "foo.png"
24+
await page.pdf(path=str(output_file))
25+
assert os.path.getsize(output_file) > 0

0 commit comments

Comments
 (0)