robotframework - How to write python function to test the matched strings (to use for Robot framework keyword)? -
i writing custom library robot framework in python. don't want use builtin library reasons.
my python code :
import os import re output = "ip address 1.1.1.1" def find_ip(): cmd = 'ipconfig' output = os.popen(cmd).read() match1 = re.findall('.* (1.1.1.1).*',output) mat1 = ['1.1.1.1'] if match1 == mat1: print "pass"
in above program have written python function :
- execute windows command "ipconfig"
- written regular expression match 1.1.1.1
- create list variable, mat1 = ['1.1.1.1']
now want put condition like, if "match1" , "mat1" equal test should pass. else should fail in robot framework.
any 1 please give idea on how write python function purpose?
please note dont want use "should match regexp" keyword in robot framework. because know same whatever asking.
to make keyword pass, don't need except return caller. fail, need raise exception:
def find_ip(): ... if match1 != mat1: raise exception('expected matches similar; not")
this documented in robot user guide in section returning keyword status:
reporting keyword status done using exceptions. if executed method raises exception, keyword status fail, , if returns normally, status pass.
the error message shown in logs, reports , console created exception type , message. generic exceptions (for example, assertionerror, exception, , runtimeerror), exception message used, , others, message created in format exceptiontype: actual message.
Comments
Post a Comment