0

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

2

2 Answers 2

4

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}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your valuable time and comment but I am still facing issue with my code. Could you please give me simple example in working condition so that I can try it and then modify my own code accordingly.
@Dipak: I already gave you an example. Just replace that last line of your test with the last line in my example.
0

I am facing issue while importing paramiko... normally witout paramiko will work..for below code getting No keyword with name 'getconnectionconfig' found. Test4.robot---> *** Settings *** Library SeleniumLibrary Library Test4.py

*** Test Cases *** Class : Test ${Result} = getconnectionconfig log to console ${Result}

Test4.py---->

from datetime import datetime
import paramiko


global ssh, channel
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

def cur_time():
    return datetime.now().strftime("%H:%M:%S")
cur_time()
print(cur_time())

def getconnectionconfig():
    global channel
    ssh.connect('192.168.1.1', username='root', password='root')
    channel = ssh.invoke_shell()
    print("Current Time is : [" + cur_time() + "] Connection Successful with 
    Server")
getconnectionconfig()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.