===== Usage ===== Options ======= These are the options that can be added to the ``pytest.ini`` file. ---- * ``extras_screenshots`` The screenshots to add in the report. Accepted values: * ``all``: Include all gathered screenshots in the report. * ``last``: Include only the last screenshot of each test in the report. Works only if the API has been previously called during the test execution in order to store the reference of the WebDriver (Selenium) or Page (Playwright) object. Default value: ``all`` ---- * ``extras_sources`` Whether to include gathered webpage sources in the report. Default value: ``False`` ---- * ``extras_description_tag`` The HTML tag for the test description (test docstring). Accepted values: ``h1``, ``h2``, ``h3``, ``p`` or ``pre`` Default value: ``pre`` API === The function scoped fixture ``report`` provides the following methods: To add a step to the report: .. code-block:: python step( comment: str = None, target: WebDriver|WebElement|Page|Locator = None, code_block: CodeBlockText = None, full_page: bool = True, page_source: bool = False, # Whether to include the webpage HTML source. escape_html: bool = False # Whether to escape HTML characters in the comment. ) Auxiliary method to get the code block format of a string: .. code-block:: python format_code_block(text: str) -> CodeBlockText Auxiliary methods to format XML, JSON and YAML strings and files: .. code-block:: python format_json_file(filepath: string, indent: int = 4) -> CodeBlockText format_json_str(text: string, indent: int = 4) -> CodeBlockText format_xml_file(filepath: string, indent: int = 4) -> CodeBlockText format_xml_str(text: string, indent: int = 4) -> CodeBlockText format_yaml_file(filepath: string, indent: int = 4) -> CodeBlockText format_yaml_str(text: string, indent: int = 4) -> CodeBlockText Limitations =========== * No support for any kind of parallel tests execution (multi-treads, multi-tabs or multi-windows). * For Playwright, only ``sync_api`` is supported. Example ======= When using the **pytest-html** plugin (with the ``--html`` option), an external CSS file needs be provided with the ``--css`` option. Command-line invocation ----------------------- If using pytest-html report: .. code-block:: bash pytest --html=/path/to/report --css=/path/to/css If using Allure report: .. code-block:: bash pytest --alluredir=/path/to/allure-results If using both reports: .. code-block:: bash pytest --html=/path/to/report --css=/path/to/css --alluredir=/path/to/allure-results Sample ``pytest.ini`` file -------------------------- .. code-block:: ini extras_description_tag = pre extras_screenshots = all extras_sources = False Sample code ----------- * Example using Selenium .. code-block:: python def test_with_selenium(report): """ This is a test using Selenium """ driver = WebDriver() driver.get("https://www.selenium.dev/selenium/web/web-form.html") report.step("Get the webpage to test", driver) driver.find_element(By.ID, "my-text-id").send_keys("Hello World!") report.step("