Skip to content

Commit 2c7a8a5

Browse files
rostrovskysseliverstov
authored andcommitted
support for Allure links in RobotFramework integration (via #371)
1 parent 5f37709 commit 2c7a8a5

File tree

4 files changed

+120
-6
lines changed

4 files changed

+120
-6
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Links
2+
-----
3+
4+
Issues are supported via tags prefixed with :code:`issue:` :
5+
6+
.. code:: robotframework
7+
8+
*** Test Cases ***
9+
Test Case With Issue Link Without URL
10+
[Tags] issue:ISSUE-1
11+
No Operation
12+
13+
14+
.. code:: robotframework
15+
16+
*** Test Cases ***
17+
Test Case With Issue Link With URL
18+
[Tags] issue:https://jira.com/browse/ISSUE-1
19+
No Operation
20+
21+
TMS links are supported via tags prefixed with :code:`test_case:` :
22+
23+
.. code:: robotframework
24+
25+
*** Test Cases ***
26+
Test Case With TMS Link Without URL
27+
[Tags] test_case:TEST-1
28+
No Operation
29+
30+
31+
.. code:: robotframework
32+
33+
*** Test Cases ***
34+
Test Case With TMS Link With URL
35+
[Tags] test_case:https://testrail.com/browse/TEST-1
36+
No Operation
37+
38+
Ordinary links are supported via tags prefixed with :code:`link:` :
39+
40+
.. code:: robotframework
41+
42+
*** Test Cases ***
43+
Test Case With Unlabeled Link
44+
[Tags] link:https://homepage.com/
45+
No Operation
46+
47+
Link label can be specified by text placed in :code:`[square brackets]` :
48+
49+
.. code:: robotframework
50+
51+
*** Test Cases ***
52+
Test Case With Labeled Link
53+
[Tags] link:[Home Page]https://homepage.com/
54+
No Operation

allure-robotframework/src/listener/robot_listener.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from allure_robotframework import utils
1818
from allure_robotframework.allure_listener import AllureListener
1919

20-
from allure_robotframework.utils import allure_tags, allure_labels
20+
from allure_robotframework.utils import allure_tags, allure_labels, allure_links
2121

2222

2323
# noinspection PyPep8Naming
@@ -111,10 +111,10 @@ def stop_current_test(self, name, attributes):
111111
test.labels.extend(utils.get_allure_suites(attributes.get('longname')))
112112

113113
test.labels.extend(allure_tags(attributes))
114-
test.labels.extend(allure_labels(attributes, LabelType.EPIC))
115-
test.labels.extend(allure_labels(attributes, LabelType.FEATURE))
116-
test.labels.extend(allure_labels(attributes, LabelType.STORY))
117-
114+
for label_type in (LabelType.EPIC, LabelType.FEATURE, LabelType.STORY):
115+
test.labels.extend(allure_labels(attributes, label_type))
116+
for link_type in (LinkType.ISSUE, LinkType.TEST_CASE, LinkType.LINK):
117+
test.links.extend(allure_links(attributes, link_type))
118118
test.labels.append(Label(name=LabelType.THREAD, value=self.pool_id))
119119
test.labels.append(Label(name=LabelType.HOST, value=host_tag()))
120120
test.labels.append(Label(name=LabelType.FRAMEWORK, value='robotframework'))

allure-robotframework/src/listener/utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import
2-
from allure_commons.model2 import Status, Label, Parameter
2+
from re import search
3+
from allure_commons.model2 import Status, Label, Parameter, Link
34
from allure_commons.types import LabelType
45
from allure_robotframework.types import RobotStatus
56

@@ -47,3 +48,25 @@ def label_value(label):
4748
return label.split(':')[1] or 'unknown'
4849

4950
return [Label(name=prefix, value=label_value(tag)) for tag in tags if is_label(tag)]
51+
52+
53+
def allure_links(attributes, prefix):
54+
tags = attributes.get('tags', ())
55+
56+
def is_link(link):
57+
return link.startswith("{link}:".format(link=prefix))
58+
59+
def parse_link(link):
60+
lnk_val = link.split(':', 1)[1] or 'unknown'
61+
lnk_label = search(r'\[.+\]', lnk_val)
62+
if lnk_label:
63+
lnk_label = lnk_label.group(0)
64+
lnk_val = lnk_val.strip(lnk_label)
65+
lnk_label = lnk_label.strip('[]')
66+
else:
67+
lnk_label = lnk_val
68+
69+
return {'name': lnk_label, 'value': lnk_val}
70+
71+
return [Link(type=prefix, url=parse_link(tag).get('value'), name=parse_link(tag).get('name')) for tag in tags if
72+
is_link(tag)]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
*** Settings ***
2+
Library ../run_robot_library.py
3+
Library ../test_allure_library.py
4+
Suite Setup Run example
5+
6+
7+
*** Keywords ***
8+
Run example
9+
${allure_report} Run Robot With Allure examples/link/link.rst
10+
Set Suite Variable ${report} ${allure_report}
11+
12+
13+
*** Test Case ***
14+
Test Case With Issue Link Without URL
15+
${test_case} Should Has Test Case ${report} Test Case With Issue Link Without URL
16+
Should Has Link ${test_case} ISSUE-1 issue
17+
18+
Test Case With Issue Link With URL
19+
${test_case} Should Has Test Case ${report} Test Case With Issue Link With URL
20+
Should Has Link ${test_case} https://jira.com/browse/ISSUE-1 issue
21+
22+
Test Case With TMS Link Without URL
23+
${test_case} Should Has Test Case ${report} Test Case With TMS Link Without URL
24+
Should Has Link ${test_case} TEST-1 test_case
25+
26+
Test Case With TMS Link With URL
27+
${test_case} Should Has Test Case ${report} Test Case With TMS Link With URL
28+
Should Has Link ${test_case} https://testrail.com/browse/TEST-1 test_case
29+
30+
Test Case With Unlabeled Link
31+
${test_case} Should Has Test Case ${report} Test Case With Unlabeled Link
32+
Should Has Link ${test_case} https://homepage.com/ link
33+
34+
Test Case With Labeled Link
35+
${test_case} Should Has Test Case ${report} Test Case With Labeled Link
36+
Should Has Link ${test_case} https://homepage.com/ link Home Page
37+

0 commit comments

Comments
 (0)