I am learning the dynamic library implementation in robot framework using python. In this process, I have created a new keyword using the dynamic library as explained in this link.
The source code is given below
import logging
class libdynamicsampl1:
def get_keyword_names(self):
return ["methOne", "methTwo"]
def methOne(self):
logging.info("called the methone")
def methTwo(self, name):
logging.info("called the methtwo with the arg as" + name)
def run_keyword(self, name, args):
print "Running keyword '%s' with arguments %s." % (name, args)
methArgs = (self,) + (args)
return getattr(self, name, methArgs)()
When i run this keyword from the robot file, like the code given below,
*** Test Cases ***
Log Dynamic Test Library
Invoke dyn tests no arg
Invoke dyn tests with arg
*** Keywords ***
Invoke dyn tests no arg
meth one
Invoke dyn tests with arg
meth two "welcome to awesome robot framework"
There is an error like the below, the inference is that the methTwo takes "self" and "name", but using getattr(...) passes only the name I guess.
TypeError: methTwo() takes exactly 2 arguments (1 given)
Kindly help in fixing this issue or suggest the best practice / implementation on how to invoke the methods based on the input arguments. There is no sample from the robot framework site, hence any fix will be very helpful.
The below implementation in the run_keyword method works fine, but i feel that its not the best practice to implement in a production ready code base.
def run_keyword(self, name, args):
print "Running keyword '%s' with arguments %s." % (name, args)
if name == "methOne":
return self.methOne()
if name == "methTwo":
return self.methTwo(args[0])
methOnemethod? The code you posted doesn't give the error you say it does. It will give the errorNo keyword with name 'meth one' found..libdynamicsampl1.pyinvoked and tested in the robot file mentioned above. I am not sure on how to use therun_keywordimplementation. Though the documentation gives a sample that prints out the name of the methods that are being invoked, there is no mention on how to invoke the method in the real time, meaning, we should invoke the method as robot framework has no way to identify which method we are actually invoking. How should the implementation be so that the methods are invoked. The documentation lacks the robot file consumption and real-time examples