I am importing a python libraries and wanted to create two objects with different arguments and call method defined in the class.
demo.py
class Sample:
def __init__(self,path,device):
self.device=device
self.path = path
print(self.device)
print(self.path)
def getting_path(self):
print(self.path)
print(self.device)
return self.path
demo.robot
===============
*** Settings ***
*** Variables ***
${path} c:
${device} samsung
${path1} D:
${device1} samsung11
*** Test Cases ***
Test
Test_python_class
*** Keywords ***
Test_python_class
Import Library demo.Sample ${path1} ${device1}
${result} = demo.sample.getting_path
log ${result}
Import Library demo.Sample ${path} ${device}
${result1} = demo.sample.getting_path
log ${result1}
It is not creating second object. ${result} and {result1} printing the same value.
I can achieve this by using below syntax using WITH name with two value. and calling like below using WITH NAME
Import Library demo.Sample ${path1} ${device1} With Name c1
${result} = c1.getting_path
log ${result}
Import Library demo.Sample ${path} ${device} With Name c2
${result1} = c2.getting_path
log ${result1}
But this solution is not optimal. If I need to create 10 objects with different value , I need to use 10 import statements here.
Appreciate if anybody can provide any inputs on optimum solution, where I can define this steps as robot function/keyword which will take these arguments for constructor and return me the object handle so that we can call class method using different object.