# tmp_path fixture: # https://docs.pytest.org/en/6.2.x/tmpdir.html from pathlib import Path import pytest from icecream import ic # type: ignore from playwright.sync_api import BrowserContext, expect from pytest_abra import BaseUrl from pytest_abra.html_helper import merge_html_reports @pytest.fixture(scope="session") def session_tmp_path(tmp_path_factory: pytest.TempPathFactory) -> Path: return tmp_path_factory.mktemp("html_test") def test_merge_html(session_tmp_path: Path): """combines all generated pytest html reports into one""" in_dir_path = Path(__file__).parent / "assets" / "html_merge" in_dir_path = in_dir_path.resolve() ic(in_dir_path) out_file_path = session_tmp_path / "test.html" out_assets_dir = session_tmp_path / "assets" merge_html_reports(in_dir_path.as_posix(), out_file_path.as_posix(), "combined.html") assert out_file_path.is_file() assert out_assets_dir.is_dir() assert next(out_assets_dir.glob("*")) @pytest.mark.slow def test_check_result_with_playwright(session_tmp_path, context: BrowserContext): html_file = session_tmp_path / "test.html" file_url = BaseUrl(netloc=html_file.as_posix(), scheme="file").get() page = context.new_page() page.goto(file_url) # check if combined is correct expect(page.get_by_text("2 Passed,")).to_be_visible() expect(page.get_by_text("2 Failed,")).to_be_visible() expect(page.get_by_text("tests ran in 12.946 seconds")).to_be_visible() # check if heading is correct expect(page.get_by_role("heading", name="combined.html")).to_be_visible() # check if traceback is included expect(page.get_by_text("E AssertionError: One or more")).to_be_visible() # check if asset works with page.expect_popup() as page1_info: page.get_by_role("link", name="Authentik Blueprint Status").click() page1 = page1_info.value # see if content of txt file is correct expect(page1.get_by_text("failed")).to_be_visible()