Date: Fri, 29 Mar 2024 15:56:05 +0000 (UTC) Message-ID: <1972978499.11848.1711727765687@docs.getxray.app> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_11847_2118135516.1711727765686" ------=_Part_11847_2118135516.1711727765686 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
In this tutorial, we will execute some tests using the Robot Framew= ork.
Please note
This tutorial explores the integration using the JUnit XML report that t= he Robot Framework is capable of generate.
Since the Robot Framework native XML format is supported by Xray, it is = the preferable way of importing tests/results from Robot test cases. Whenev= er integrating through Robot's specfic XML format, you have access to more = features than the ones that are available if you use JUnit's XML format, si= nce the latter is a generic format.
This and more examples may be found in Robot framework's robotdemo repository.
class Cal= culator(object): BUTTONS =3D '1234567890+-*/C=3D' def __init__(self): self._expression =3D '' def push(self, button): if button not in self.BUTTONS: raise CalculationError("Invalid button '%s'." % button) if button =3D=3D '=3D': self._expression =3D self._calculate(self._expression) elif button =3D=3D 'C': self._expression =3D '' elif button =3D=3D '/': self._expression +=3D '//' # Integer division also in Python= 3 else: self._expression +=3D button return self._expression def _calculate(self, expression): try: return str(eval(expression)) except SyntaxError: raise CalculationError('Invalid expression.') except ZeroDivisionError: raise CalculationError('Division by zero.') class CalculationError(Exception): pass
The Robot test:
*** Set= tings *** Documentation Example test cases using the keyword-driven testing appro= ach. ... ... All tests contain a workflow constructed from keywords in ... ``CalculatorLibrary.py``. Creating new tests or editing ... existing is easy even for people without programming skil= ls. ... ... The _keyword-driven_ appoach works well for normal test ... automation, but the _gherkin_ style might be even better ... if also business people need to understand tests. If the ... same workflow needs to repeated multiple times, it is bes= t ... to use to the _data-driven_ approach. Library CalculatorLibrary.py *** Test Cases *** Push button Push button 1 Result should be 1 Push multiple buttons Push button 1 Push button 2 Result should be 12 Simple calculation Push button 1 Push button + Push button 2 Push button =3D Result should be 3 Longer calculation Push buttons 5 + 4 - 3 * 2 / 1 =3D Result should be 3 Clear Push button 1 Push button C Result should be ${EMPTY} # ${EMPTY} is a built-in variable =20
After running the tests and generating the JUnit XML report (e.g., robot.xml=
a>), it can be imported to Xray (by using either the REST API or the
If you're using Python,
robot -x robot.xml keyword_driven.robot
If you're using Java,
java -jar robotframework-3.0.jar -x robot.xml keyword_driven.robot<= /pre>
JUnit's Test Case is mapped to a Generic Test in Jira, and the G= eneric Test Definition field contains the friendly name of the Rob= ot script concatenated with the aliias of the test case.
The Execution Details of the Generic Test contains information about the= Test Suite, which in this case corresponds to the friendly name of the rob= ot script (i.e., "Keyword Driven").