Unable to Run python script from Robot framework
Question:
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
Answers:
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}
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()
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
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}
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()