I am new to Robot Framework. I am writing my own library to work with Robot and I want to save the class object. I want the object to be created and saved once at the suite setup and keep using that same object for the entire test suite. Is there a way to do that?
Aristalibrary.py
import pyeapi
active_conn = None
class AristaLibrary:
def __init__(self, proto="https", hostname='localhost',
username="admin", passwd="admin", port="443"):
self.hostname = hostname
self.proto = proto
self.port = port
self.username = username
self.passwd = passwd
def connect_to(self, proto, hostname, username, passwd, port):
proto = str(proto)
hostname = str(hostname)
username = str(username)
passwd = str(passwd)
port = str(port)
active_conn = pyeapi.connect(proto, hostname, username, passwd, port)
return active_conn
def enable(self, conn, command):
return conn.execute([command])
def get_active_connection(self):
return active_conn
loginsight_sshlib_demo.txt
*** Setting ***
Library BuiltIn
Library String
Library AristaLibrary
*** Variables ***
${hostname} 192.168.117.20
${username} admin
${password} admin
${port} 80
${proto} http
*** Test Cases ***
Test Aristalibrary
${node}= Connect To ${proto} ${hostname} ${username} ${password} ${port}
LOG ${node} level=DEBUG
Test Persistance of variables
${node}= Get Active Connection
${output}= Enable ${node} show version
LOG ${output} level=DEBUG
*** Keywords ***
Open Connection and Login
Open Connection ${hostname}
Login ${username} ${password}
Write enable
${Output}= Read
Log ${Output} level=INFO