Sending images and log messages to ReportPortal

Problem: There is not much information on how to send or attach images to ReportPortal

Why this post?

We started using ReportPortal for reporting automation test results. Along with the test results we also need to send log messages and images/screenshot to ReportPortal. These are useful artifacts which help people monitoring them check the success and failure reasons and take necessary actions.

We were not able to find information on how to send a screenshot to ReportPortal easily and had to spend some time to get it going. So this blog post is to share our knowledge on how to send the images to ReportPortal using pytest.

Note: This is in continuation to our previous post on ReportPortal integration with pytestnd pytest markers

How to send logs and images to ReportPortal

1. Sending log messages
The agent-python-pytest plugin provides a python logging handle which can be used in file.

def rp_logger(request):
    import logging
    # Import Report Portal logger and handler to the test module.
    from pytest_reportportal import RPLogger, RPLogHandler
    # Setting up a logging.
    logger = logging.getLogger(__name__)
    # Create handler for Report Portal.
    rp_handler = RPLogHandler(request.node.config.py_test_service)
    # Set INFO level for Report Portal handler.
    return logger

We can then use the rp_logger in tests to send log messages easily.

def test_launch_success(rp_logger):"A GUI test. Launch")

2. Sending screenshot
We can use the same method rp_logger along with the attachment details to send image to ReportPortal. We need to pass the image_name which will be the name of the image in ReportPortal, data which is the image and the mime type.
                "data": image,
                "mime": "application/octet-stream"

We have created a separate method save_screenshot_reportportal() which takes in an image and sends it to ReportPortal. We also need to open the .png(binary file) before sending the image file.

Below is the complete code for the test file.

# Sample test to load and send image to ReportPortal
import pytest
from selenium import webdriver
def test_launch_success(rp_logger):
    "Launch Qxf2 and save image"
    # Log message to ReportPortal"GUI Test. Launch")
    driver = webdriver.Chrome()
    image_name = "Test_Launch_Success"
    # Save screenshot to ReportPortal
def save_screenshot_reportportal(rp_logger,image_name):
    "Method to save image to ReportPortal"
        with open(image_name+'.png', "rb") as fh:
            image =

                "data": image,
                "mime": "application/octet-stream"
    except Exception as e:
        print("Exception when trying to save screenshot to reportportal: %s" %str(e))
def test_api():
    print ("API Test")

3. Running the test
We can use the same conftest file mentioned in the previous post by adding the rp_logger method mentioned in step 1 and run the test



There we go, we now have our screenshots and log messages attached in ReportPortal. Enjoy testing and reporting…


1. ReportPortal python client
2. agent-python-pytest

7 thoughts on “Sending images and log messages to ReportPortal

  1. Hi,

    This is very useful post .I facing an error when try to use rp_logger in other class inside method directly and getting an errot that attribute is not defined

  2. Not sure if some can help same for JAVA+TEsngNG.I am getting hard time in sending screenshot to reportportal.

    1. Hi,

      I am not sure you have tried this link. If not you can refer this link. I hope it should be helpful for you.

Leave a Reply

Your email address will not be published.