Skip to content

Commit 2e67d22

Browse files
author
Tim Lolkema
committed
Make robotfamework-notifications compatible with robotframework 4
1 parent cc1edc1 commit 2e67d22

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎RobotNotifications/__init__.py‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RobotNotifications:
1515
POST a message to a Slack or Mattermost channel.
1616
'''
1717
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
18-
ROBOT_LIBRARY_VERSION = '1.1.3'
18+
ROBOT_LIBRARY_VERSION = '1.2.0'
1919
ROBOT_LISTENER_API_VERSION = 3
2020

2121
def __init__(self, webhook, *args):
@@ -35,6 +35,15 @@ def _clean_data(self, text, data):
3535
raise ValueError('Invalid Parameter')
3636
return json.dumps(json_data)
3737

38+
def _return_statistics(self, statistics):
39+
'''Returns the base path where the summary statistics are stored
40+
This path is different between robotframework versions'''
41+
try:
42+
if statistics.total:
43+
return statistics # robotframework < 4.0.0
44+
except:
45+
return statistics.all # robotframework > 4.0.0
46+
3847
@keyword('Post Message To Channel')
3948
def post_message_to_channel(self, text, **kwargs):
4049
'''POST a custom message to a Slack or Mattermost channel.'''
@@ -70,6 +79,9 @@ def _get_attachments(self, status, text):
7079

7180
def end_suite(self, data, result):
7281
'''Post the suite results to Slack or Mattermost'''
82+
83+
statistics = self._return_statistics(result.statistics)
84+
7385
if 'end_suite' in self.args:
7486
if result.parent:
7587
text = f'*{result.longname}*\n'
@@ -83,13 +95,13 @@ def end_suite(self, data, result):
8395
if not result.parent:
8496
text = f'*Report Summary - {result.longname}*'
8597
attachment_text = (
86-
f'Total Tests : {result.statistics.all.total}\n'
87-
f'Total Passed : {result.statistics.all.passed}\n'
88-
f'Total Failed : {result.statistics.all.failed}'
98+
f'Total Tests : {statistics.total}\n'
99+
f'Total Passed : {statistics.passed}\n'
100+
f'Total Failed : {statistics.failed}'
89101
)
90-
if result.statistics.all.failed == 0:
102+
if statistics.failed == 0:
91103
attachments_data = self._get_attachments('GREEN', attachment_text)
92-
elif result.statistics.all.failed > 0:
104+
elif statistics.failed > 0:
93105
attachments_data = self._get_attachments('RED', attachment_text)
94106
self.post_message_to_channel(text, attachments=attachments_data)
95107

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="robotframework-notifications",
10-
version="1.1.3",
10+
version="1.2.0",
1111
description="Send notifications to Slack or Mattermost using Robot Framework.",
1212
long_description=README,
1313
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)