Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Last active October 26, 2021 15:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffbrl/037efcbc7170581cc558659c4714bdc1 to your computer and use it in GitHub Desktop.
Save jeffbrl/037efcbc7170581cc558659c4714bdc1 to your computer and use it in GitHub Desktop.
Simple test of a calculator function with the robot framework - v2
*** Settings ***
Documentation Check arithmetic operations
Resource ${EXEC_DIR}/resources/keywords.txt
# currently only prints to output.xml
Suite Setup math.setup
Suite Teardown math.teardown
*** Variables ***
*** Test Cases ***
T1: Adding two integers
Verify addition of ${20} and ${5} is ${25}
T2: Subtracting two integers
Verify subtraction of ${20} and ${5} is ${15}
T3: Multiplying two integers
Verify multiplication of ${20} and ${5} is ${100}
T4: Dividing two integers -- integer result
Verify division of ${20} and ${5} is ${4}
T5: Dividing two integers -- confirm round down to integer
Verify division of ${20} and ${6} is ${3}
T6: Subracting two integers that results in negative number
Verify subtraction of ${5} and ${20} is ${-15}
import operator as op
def setup():
print "setting stuff up"
def calculate(number1, number2, operation):
arithmetic_function = { '+': op.add, '-': op.sub, '*': op.mul, '/': op.div }
return arithmetic_function[operation](number1, number2)
def teardown():
print "tearing stuff down"
*** Settings ***
Library ${EXEC_DIR}/lib/easy_math.py WITH NAME math
*** Keywords ***
Verify addition of ${operand1} and ${operand2} is ${result}
[Documentation] Verify addition of two integers
${calculated_result}= math.calculate ${operand1} ${operand2} +
Should Be Equal as Integers ${calculated_result} ${result}
Verify subtraction of ${operand1} and ${operand2} is ${result}
[Documentation] Verify subtraction of two integers
${calculated_result}= math.calculate ${operand1} ${operand2} -
Should Be Equal as Integers ${calculated_result} ${result}
Verify multiplication of ${operand1} and ${operand2} is ${result}
[Documentation] Verify multiplication of two integers
${calculated_result}= math.calculate ${operand1} ${operand2} *
Should Be Equal as Integers ${calculated_result} ${result}
Verify division of ${operand1} and ${operand2} is ${result}
[Documentation] Verify division of two integers
${calculated_result}= math.calculate ${operand1} ${operand2} /
Should Be Equal as Integers ${calculated_result} ${result}
@bjaishankar
Copy link

Hi, I got a error saying there is no file names "math.setup". I am new to robot framework, please help me solve this issue.

@jeffbrl
Copy link
Author

jeffbrl commented Jun 17, 2019

@bjaishanker, make sure the keywords.txt file exists in resources/keywords.txt and the easy_match.py file exists in lib/easy_math.py.

@dmiek
Copy link

dmiek commented Sep 30, 2020

@bjaishankar Adding parantheses for the print statements seems to solve it. The error output hints about this.

@jeffbrl
Copy link
Author

jeffbrl commented Sep 30, 2020

@dmiek That makes sense. I was using python 2.7 at the time I posted this gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment