===== 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`` ---- * ``extras_attachment_indent`` The indent to use for attachments. Accepted values: any positive integer. Default value: ``4`` API === The function scoped fixture ``report`` provides the following methods: To add a step with screenshot: .. code-block:: python screenshot( comment: str, # Comment of the test step. target: WebDriver | WebElement | Page | Locator = None, # The page or element. full_page: bool = True, # Whether to take a full page screenshot. page_source: bool = False, # Whether to include the webpage HTML source. escape_html: bool = False # Whether to escape HTML characters in the comment. ) To add a step with attachment: .. code-block:: python attach( comment: str, # Comment of the test step. body: str | bytes | Dict | List[str] = None, # The content/body of the attachment. source: str = None, # The filepath of the attachment. mime: str | Mime = None, # The attachment mime type. escape_html: bool = False # Whether to escape HTML characters in the comment. ) # Type of body parameter: # str: - for XML, JSON, YAML, CSV or TXT attachments # - for image attachments if it is a base64 string # bytes: for image attachments # Dict: for JSON attachments # List[str]: for list-uri attachments # The supported mime types are: # report.Mime.image_bmp or "image/png" # report.Mime.image_gif or "image/gif" # report.Mime.image_jpeg or "image/jpeg" # report.Mime.image_png or "image/png" # report.Mime.image_svg_xml or "image/svg+xml" # report.Mime.image_tiff or "image/tiff" # report.Mime.text_csv or "text/csv" # report.Mime.text_html or "text/html" # report.Mime.text_plain or "text/plain" # report.Mime.text_uri_list or "text/uri-list" # report.Mime.application_json or "application/json" # report.Mime.application_xml or "application/xml" # report.Mime.application_yaml or "application/yaml" To add a link to the report: .. code-block:: python link( uri: str, # The uri. name: str = None # The text of the anchor tag. ) Limitations =========== * Limited support for the ``--self-contained-html`` option of the **pytest-html** plugin. The report still contains links for attachments of unsopported mime types. * 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 = h1 extras_attachment_indent = 4 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.screenshot("Get the webpage to test", driver) driver.find_element(By.ID, "my-text-id").send_keys("Hello World!") report.screenshot("