Hey everyone, I’m hoping for some help with this!
I’m working with a Robot Framework test suite that interacts with a WebSocket server using a custom Python library. This library has an expectedErrorSeen
flag, which is set to True
when an expected error is see in the web socket reply. Im using a test template and there the error can happen at different keywords in the test.
What I Want to Achieve:
- Whenever
expectedErrorSeen
is set toTrue
, stop the test immediately but mark it as passed. - This should work for any keyword, not just a specific one.
I wrote the following listener to detect when expectedErrorSeen
is True
in the library and i tried to stop the execution using BuiltIn().pass_execution() function. I get the following errror and the keywords in the test are executed.
Calling method ‘end_library_keyword’ of listener HarrierListener.py’ failed: Expected error encountered, skipping test.
Test Template
Send Test Email <— error could happen here if it does i don’t want the rest of the test to run
Process Release Approval Of Email
Verify Test Email In Recipients Inbox
Retransmit Test Message <— error could happen here if it does i don’t want the rest of the test to run
Verify Retrasmited Message In Senders Folder
Process Release Approval Of Retransmitted Message
Verify Retrasmited Message In All Recipients Folder
from robot.libraries.BuiltIn import BuiltIn
from robot import result, running
from robot.api.interfaces import ListenerV3
from pprint import pprint
class HarrierListener(ListenerV3):
def __init__(self):
self.expected_error_seen = False
self.test_started = False
def start_test(self, data, result):
"""Reset expected error flag at the start of each test."""
self.test_started = True
harrier_ws= BuiltIn().get_library_instance("HarrierUtilities.SMIME.HarrierWebSocket")
setattr(harrier_ws, "expectedErrorSeen", False)
def end_keyword(self, data: running.Keyword, result: result.Keyword):
"""Check for the expected error flag after every keyword execution."""
if self.test_started == True:
# Retrieve the HarrierWebSocket instance and check for expectedErrorSeen
harrier_ws= BuiltIn().get_library_instance("HarrierUtilities.SMIME.HarrierWebSocket")
if hasattr(harrier_ws, "expectedErrorSeen") and harrier_ws.expectedErrorSeen:
self.expected_error_seen = True
BuiltIn().pass_execution("Expected error encountered, skipping test.")
My question is:
is this even possible using a listener or do i need to look at managing this another way.