# Access Test Execution result at runtime via python script

**URL:** <https://forum.robotframework.org/t/access-test-execution-result-at-runtime-via-python-script/8967>\
**Category:** Robot Framework\
**Created:** [13 June 2025 17:02 UTC](https://forum.robotframework.org/t/access-test-execution-result-at-runtime-via-python-script/8967 "2025-06-13T17:02:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matbellara](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/matbellara/32/4292_2.png) [@Matbellara](https://forum.robotframework.org/u/Matbellara)\
**Post date:** [13 June 2025 17:02 UTC](https://forum.robotframework.org/t/access-test-execution-result-at-runtime-via-python-script/8967/1 "2025-06-13T17:02:16Z")

</div>

Hi,

i’ll explain my case: i would like to run RF from a python script and to send the test execution result as json output via http/s request in that same script.  
As of now the script run the robot (with run\_cli) then takes the output.json and sent it.  
Is there any way to avoid writing a file on the file system and access the content of the output.json at runtime?

es.

```
      from robot import run_cli
      import requests

      run_arguments=[
        ,'--output','output.json', 
       'TestPlan'
       ]
        rc = run_cli(
        runArguments,
        exit=False
        )
       with open('output.json') as output_file:
          output_content= json.loads(contentCredentialsFile)
      requests.post('myurl', json=output_content)

```

I would like to avoid to save a file to file system and just access output\_content.

Is it possibile? does RF expose an object via it’s API or its entrypoints that i can access at runtime? Maybe an [`ExecutionResult()`](https://robot-framework.readthedocs.io/en/master/autodoc/robot.result.html#robot.result.resultbuilder.ExecutionResult) or a [`TestSuite`](https://robot-framework.readthedocs.io/en/master/autodoc/robot.running.html#robot.running.model.TestSuite) that I can transform with ResultWriter? Are RF Listeners required or is there a simpler way?

expected is something like this

es.

```
      from robot import run_cli, **something**
      import requests

      run_arguments=[
        ,'--output','output.json', 
       'TestPlan'
       ]
        rc = run_cli(
        runArguments,
        exit=False
        )
       output_content = **something**.results
      requests.post('myurl', json=output_content)

```

Thank you very much for your attention.

Kind regards

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [13 June 2025 23:02 UTC](https://forum.robotframework.org/t/access-test-execution-result-at-runtime-via-python-script/8967/2 "2025-06-13T23:02:26Z")

</div>

Hi Matbellara,

I’m not sure if you can access the result objects in the API from run\_cli, I do know you can access them from the [listener](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#listener-version-3) API, as you are using run\_cli it should be easy enough to add the argument `--listener` with a listener file that does what you want.

Hope that helps,

Dave.

---

<div class="post-metadata">

**Author:** ![Matbellara](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/matbellara/32/4292_2.png) [@Matbellara](https://forum.robotframework.org/u/Matbellara)\
**Post date:** [20 June 2025 14:35 UTC](https://forum.robotframework.org/t/access-test-execution-result-at-runtime-via-python-script/8967/3 "2025-06-20T14:35:10Z")

</div>

Yes, using the listener is possible to access the datas i’m looking for although the format is not as the output.json where you can find this structure

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/0/04774dd6a69a83d7b29397e954e1f7a80b5c772c.png)

I will try to manually format the output as much similar to the one the framework create, if you have any suggestions please i’m all hears 🙂

thank you again

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [20 June 2025 23:15 UTC](https://forum.robotframework.org/t/access-test-execution-result-at-runtime-via-python-script/8967/4 "2025-06-20T23:15:52Z")

</div>

Hi Matbellara,

I’m not familiar with the output.json, it’s a new feature that I’ve not had a need to use.

Maybe if you go digging through the api documentation you can find the function call that generates the json data? or maybe you’ll have to dig around the robot code to find it, if you can call that function it might make your life easier 🤞

I’m not an expert, just another user like you.

Dave.

---

<div class="post-metadata">

**Author:** ![Matbellara](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/matbellara/32/4292_2.png) [@Matbellara](https://forum.robotframework.org/u/Matbellara)\
**Post date:** [26 June 2025 08:19 UTC](https://forum.robotframework.org/t/access-test-execution-result-at-runtime-via-python-script/8967/5 "2025-06-26T08:19:14Z")

</div>

Digging a little bit I found what I was looking for: the function **to\_json**

[robot.result.executionresult.Result.to\_json](https://robot-framework.readthedocs.io/en/master/autodoc/robot.result.html#robot.result.executionresult.Result.to_json)

However the code is the following, where the actual json format dumped in the output.json is created in the same method that dumps it in the file, giving no option for any user to access the output json format at runtime (without first creating the file on the os).

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/b/ba116135d545b64420cb6b60c373b518c1689500.png)

@pekkaklarck wouldn’t it better to have a get\_json\_format() function that creates the json format inside the Result class and then use this same function in to\_json()? In this way the new output.json format would be accessible to any Result object and to any listener/user without having to first create the output.json file.

What do you think?  
should I open an issue on the robotframework github?

Otherwise the only solution i have for my case is to copy your code into my python script, make some changes for my case and this only to access the same output.json robotframework creates, and this will happen again for all the users that have same need than me.

Thank you

---

<div class="post-metadata">

**Author:** ![rasjani](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rasjani](https://forum.robotframework.org/u/rasjani)\
**Post date:** [26 June 2025 08:24 UTC](https://forum.robotframework.org/t/access-test-execution-result-at-runtime-via-python-script/8967/6 "2025-06-26T08:24:40Z")

</div>

If the docs are correct for that `to_json()`:

> - an open file object where to write the data to, or

You can use StringIO - it is in-memory string buffer that can be used instead of a file. Using that instead of actual file should work in this case and no actual file needs to be generated..

See: [io — Core tools for working with streams — Python 3.13.5 documentation](https://docs.python.org/3/library/io.html#text-i-o)

---

<div class="post-metadata">

**Author:** ![Matbellara](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/matbellara/32/4292_2.png) [@Matbellara](https://forum.robotframework.org/u/Matbellara)\
**Post date:** [26 June 2025 10:30 UTC](https://forum.robotframework.org/t/access-test-execution-result-at-runtime-via-python-script/8967/7 "2025-06-26T10:30:28Z")

</div>

thank you very much @rasjani i did not know that

The final flow is :

I succeeded in my aim accessing the **robot.result.model.TestSuite** with a listener end\_suite method.  
However the function **to\_json** in **robot.result.model.TestSuite** is inherited from **robot.model.modelobject.ModelObject** which does not add **statistics** , **errors** , **generator** , **generated** , **rpa** , **suites** at json object level.

In order to get a json as the output.json, as the RF creates, it is required to pass as string the **robot.result.model.TestSuite.to\_json** output to **robot.result.resultbuilder.ExecutionResult** and then call again the to\_json method on the **robot.result.executionResult.Result** from **ExecutionResult**.

or manually format the json like the **robot.result.executionResult.Result.to\_json** does.

at least from what I could see

Thank you for feedbacks and support.
