I have developed few libraries for robot framework for my feature testing, for these libraries all variables are coming from a variables.py file. Below is the code block for variables.py:
#!/usr/bin/env python import sys import os import optparse import HostProperties import xml.etree.ElementTree as ET from robot.api import logger testBed = 748 tree = ET.parse('/home/p6mishra/mybkp/testLibs/TestBedProperties.xml') class raftGetTestBedProp(object): def GetTestBedNumber(self): _attributeDict = {} root = tree.getroot() for _tbProperties in root: for _tbNumber in _tbProperties: get_tb = _tbNumber.attrib if get_tb['name']== str(testBed): get_tb2 = _tbNumber.attrib return root, get_tb2['name'] def GetTestBedProperties(self, root, testBedNumber): propertyList = [] for _tbProperties in root: get_tb = _tbProperties.attrib for _tbProperty in _tbProperties: get_tb1 = _tbProperty.attrib if get_tb1['name']== str(testBedNumber): for _tbPropertyVal in _tbProperty: get_tb2 = _tbPropertyVal.attrib if 'name' in get_tb2.keys(): propertyList.append(get_tb2['name']) return propertyList def GetIPNodeType(self, root, testBedNumber): for tbNumber1 in root.findall('tbproperties'): for tbNumber in tbNumber1: ipv4support = tbNumber.find('ipv4support').text ipv6support = tbNumber.find('ipv6support').text lbSetup = tbNumber.find('lbSetup').text name = tbNumber.get('name') if name==str(testBedNumber): return ipv4support, ipv6support, lbSetup obj1, obj2 = raftGetTestBedProp().GetTestBedNumber() ipv4support, ipv6support, lbSetup = raftGetTestBedProp().GetIPNodeType(obj1, obj2) AlltestBedProperties = raftGetTestBedProp().GetTestBedProperties(obj1, obj2) HostPropertyDict = {} for testBedProperty in AlltestBedProperties: try: val1 = getattr(HostProperties, testBedProperty) HostPropertyDict[testBedProperty] = val1 except: logger.write("Error in the Configuration data. Please correct and then proceed with the testing", 'ERROR') for indexVal in range(len(AlltestBedProperties)): temp = AlltestBedProperties[indexVal] globals()[temp] = HostPropertyDict[temp] This variables.py file returns all variables defined in HostProperties.py file based on testbed number. If i import this library like from variables import * in other libraries it gives me the required variables.
But the problem is here I have hardcoaded 748 so it works fine for me but i want to pass this testbed number information from pybot command and make it available for my Robot testcase as well as all the developed libraries.