Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 1b0111d

Browse files
Merge pull request #2 from SmartBear/task/TM4J-3469-add-robot-framework-example
Robot framework example
2 parents 1816669 + 8d49730 commit 1b0111d

File tree

6 files changed

+440
-1
lines changed

6 files changed

+440
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
app/__pycache__
2+
report.html
3+
log.html

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,76 @@
1-
# zephyr-scale-robot-framework-example
1+
# Example of how to use Robot Framework to generate JUnit result file
2+
3+
Small project to show how to make Robot Framework to generate the JUnit result file that you can [`POST /automations/executions/junit`](https://support.smartbear.com/zephyr-scale-cloud/api-docs/#operation/createJUnitExecutions)
4+
5+
### Configuration
6+
7+
You just have to execute Robot Framework with `-x` parameter followed by the xml result file name to instruct it to generate the JUnit result file. Here is an example:
8+
9+
```
10+
robot -x junitresult.xml mytest.robot
11+
```
12+
13+
This will execute `mytest.robot` test file and generate the JUnit result file `junitresult.xml` that you'll [`POST /automations/executions/junit`](https://support.smartbear.com/zephyr-scale-cloud/api-docs/#operation/createJUnitExecutions).
14+
15+
16+
### Naming conventions
17+
18+
There are 2 ways to match Robot Framework test cases with Zephyr Scale test cases:
19+
- **By Zephyr Scale test case key**: in case your Robot framework test case contains the Zephyr Scale test case key
20+
- **By Zephyr Scale test case name**: if your Robot Framework test case doesn't contain some Zephyr Scale test case key, then it will try to match Zephyr Scale test case by name following the pattern `<robot filename with no extension>.<robot test case name>`
21+
22+
Here is an example. Consider a file named `calculator.robot`:
23+
```robotframework
24+
*** Test Cases ***
25+
# will match Zephyr Scale test case named Calculator.User can clear the display
26+
User can clear the display
27+
Input number 10
28+
Press operator +
29+
Input number 1
30+
Press clear
31+
Display should be empty
32+
33+
*** Test Cases ***
34+
# will match Zephyr Scale test case with key NET-T1743
35+
NET-T1744 User can calculate with wrong result
36+
Input number 1
37+
Press operator +
38+
Input number 1
39+
Press enter
40+
Result should be 3
41+
42+
*** Test Cases ***
43+
# will match Zephyr Scale test case with key NET-T1744
44+
User can calculate two numbers - NET-T1744
45+
[Template] Calculate two numbers should pass
46+
10 + 5 15
47+
10 - 5 5
48+
10 / 5 2
49+
10 * 5 50
50+
```
51+
As we can see, the first Robot Framework test cases will match Zephyr Scale test cases by name and the last 2 will match by key.
52+
53+
### Requirements to run this example project
54+
55+
In order to execute this example on your local machine you’ll have to checkout this repository and install python 3. Here is how you can do it on mac:
56+
57+
```
58+
brew upgrade pyenv
59+
pyenv install 3.6.0
60+
pyenv global 3.6.0
61+
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
62+
source ~/.zshrc
63+
```
64+
65+
Now you have to install robot framework and docutils library:
66+
67+
```
68+
pip install robotframework
69+
pip install docutils
70+
```
71+
72+
You can now make Robot Framework to generate the JUnit result file by executing the following command:
73+
74+
```
75+
robot -x junitresult.xml calculator.robot
76+
```

app/Calculator.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Calculator(object):
2+
3+
def __init__(self):
4+
self.clear()
5+
6+
def clear(self):
7+
self._number1 = 0
8+
self._number2 = 0
9+
self._result = None
10+
self._display = 0
11+
self._operator = None
12+
13+
def input_number(self, number):
14+
if self._operator is None:
15+
self._number1 = number
16+
else:
17+
self._number2 = number
18+
19+
def press_operator(self, operator):
20+
self._operator = operator
21+
22+
def calculate(self):
23+
self._result = eval(self._number1 + self._operator + self._number2)
24+
25+
def display_should_be_empty(self):
26+
self._display == 0
27+
28+
def result_should_be(self, expected_result):
29+
if int(expected_result) != self._result:
30+
raise AssertionError("Expected result to be '%s' but was '%s'."
31+
% (expected_result, self._result))
32+
33+

calculator.robot

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
*** Test Cases ***
3+
# will match Zephyr Scale test case named Calculator.User can clear the display
4+
User can clear the display
5+
Input number 10
6+
Press operator +
7+
Input number 1
8+
Press clear
9+
Display should be empty
10+
11+
*** Test Cases ***
12+
# will match Zephyr Scale test case with key NET-T1743
13+
NET-T1744 User can calculate with wrong result
14+
Input number 1
15+
Press operator +
16+
Input number 1
17+
Press enter
18+
Result should be 3
19+
20+
*** Test Cases ***
21+
# will match Zephyr Scale test case with key NET-T1744
22+
User can calculate two numbers - NET-T1744
23+
[Template] Calculate two numbers should pass
24+
10 + 5 15
25+
10 - 5 5
26+
10 / 5 2
27+
10 * 5 50
28+
29+
30+
*** Keywords ***
31+
Calculate two numbers should pass
32+
[Arguments] ${number1} ${operator} ${number2} ${result}
33+
Input number ${number1}
34+
Press operator ${operator}
35+
Input number ${number2}
36+
Press enter
37+
Result should be ${result}
38+
39+
Press enter
40+
Calculate
41+
42+
Press clear
43+
Clear
44+
45+
Clear Calculator
46+
Clear
47+
48+
49+
*** Settings ***
50+
Library app/Calculator.py
51+
52+
53+
*** Settings ***
54+
Suite Setup Clear Calculator
55+
Test Teardown Clear Calculator
56+

junitresult.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite name="Calculator" tests="3" errors="0" failures="1" skipped="0" time="0.042">
3+
<testcase classname="Calculator" name="User can clear the display" time="0.003" />
4+
<testcase classname="Calculator" name="NET-T1744 User can calculate with wrong result" time="0.003">
5+
<failure message="Expected result to be '3' but was '2'." type="AssertionError" />
6+
</testcase>
7+
<testcase classname="Calculator" name="User can calculate two numbers - NET-T1744" time="0.009" />
8+
</testsuite>

0 commit comments

Comments
 (0)