Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inspect variable type in Robot Framework?

I am using Robot Framework to test a system that returns an int which represents the number of errors the system encountered while under test. However, if the system becomes unresponsive the return will be a NoneType and I receive this error: 'None' cannot be converted to an integer: TypeError: int() argument must be a string or a number, not 'NoneType'

I'm not able to use the Should Be True keyword because a passing response will be 0.

Is there any way to test the variable's type in Robot? My goal is to do something like this:

Should Not Be NoneType    ${error_count}    msg=System is not responding after test.
Should Be Equal As Integers    ${error_count}    ${0}    msg=System generated ${error_count} errors during test.
like image 587
BakerBug Avatar asked Mar 18 '26 03:03

BakerBug


1 Answers

To check that ${error_count} is not None, you can do the following:

Should Be True    ${error_count} is not ${None}    msg=Returned None

So long as the previous statement passes, your test can move forward with printing your result like so:

Log to Console    System generated ${error_count} errors during test

Alternatively, you can merge everything onto one line using the Run Keyword Unless keyword:

Run Keyword Unless    ${error_count} is ${None}    Log to Console    System generated ${error_count} errors during test    
like image 133
ILostMySpoon Avatar answered Mar 21 '26 07:03

ILostMySpoon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!