From 78be6ca25232dabc1614c1567ae8a83367bc5ba2 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Sat, 11 Jul 2020 01:37:14 +0200 Subject: [PATCH] tests: added for Page.pdf --- setup.cfg | 4 +++- tests/conftest.py | 18 +++++++++++++++--- tests/test_pdf.py | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 tests/test_pdf.py diff --git a/setup.cfg b/setup.cfg index 4b26491e0..19b6920fc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,6 @@ [tool:pytest] -markers = skip_browser +markers = + skip_browser + only_browser [mypy] ignore_missing_imports = True diff --git a/tests/conftest.py b/tests/conftest.py index b48bee849..679a9e392 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -111,9 +111,21 @@ def is_chromium(browser_name): @pytest.fixture(autouse=True) def skip_by_browser(request, browser_name): - if request.node.get_closest_marker("skip_browser"): - if request.node.get_closest_marker("skip_browser").args[0] == browser_name: - pytest.skip("skipped on this platform: {}".format(browser_name)) + skip_browsers_names = [] + + # Allowlist + only_browser_marker = request.node.get_closest_marker("only_browser") + if only_browser_marker: + skip_browsers_names = ["chromium", "firefox", "webkit"] + skip_browsers_names.remove(only_browser_marker.args[0]) + + # Denylist + skip_browser_marker = request.node.get_closest_marker("skip_browser") + if skip_browser_marker: + skip_browsers_names.append(skip_browser_marker.args[0]) + + if browser_name in skip_browsers_names: + pytest.skip("skipped on this platform: {}".format(browser_name)) def pytest_addoption(parser): diff --git a/tests/test_pdf.py b/tests/test_pdf.py new file mode 100644 index 000000000..8f50f019a --- /dev/null +++ b/tests/test_pdf.py @@ -0,0 +1,25 @@ +# Copyright (c) Microsoft Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import pytest + +from playwright.page import Page + + +@pytest.mark.only_browser("chromium") +async def test_should_be_able_to_save_pdf_file(page: Page, server, tmpdir): + output_file = tmpdir / "foo.png" + await page.pdf(path=str(output_file)) + assert os.path.getsize(output_file) > 0