Search code examples
pythonrobotframework

Unable to Run python script from Robot framework


Sample.py

       import json    
       def getElementCount(jsonObj):

       data1 = json.dumps(jsonObj)
       item_dict = json.loads(data1)

       countElement=(item_dict['one'])
       print len(countElement) 
       return countElement

Robot framework

       Library           Sample.py

       ** Test Cases ***

       [TC-001]-Registering a device with INVALID SUBSCRIBER name 

       ${ResponseJson}=    Customer Method API Call ${host}   ${apivalue}

       ${value} =    Call Method  getElementCount ${ResponseJson}

Description of Error

It is not working can someone please help with above solution

I want to call to above python method from robot framework and also pass ${ResponseJson} value to above python method. And after identifying length result should be return to robot framework.

i already went through below link but dint understand meaning of call method. http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Call%20Method


Solution

  • Call method is for calling methods on objects. When you import a library, you don't get objects.

    When you import a module as a library, every function becomes a keyword. Therefore you can directly call getElementCount:

       ** Test Cases ***
       ...
       ${value} =    getElementCount  ${ResponseJson}