BuiltIn().get_variables().get('${EXECDIR}') not working getting AttributeError in robot framework 2.8.4

527 views
Skip to first unread message

gunaseelan Sakkarapani

unread,
Feb 24, 2014, 1:41:42 AM2/24/14
to robotframe...@googlegroups.com

Code snippet:
from robot.api import TestCaseFile
from robot.api import TestSuite
from robot.api import TestSuiteBuilder
from robot.api import ResultWriter
from robot.api import logger

class SampleClient:
  def __init__(self,configFileName):
    self.testdetails = {}
    self.loglevel = "INFO"
     /* instead of  use os.getcwd and i want to use $EXECDIR builtin OS variable */
${EXECDIR}An absolute path to the directory where test execution was started from. New in Robot Framework 2.1.
    self.logpath  = os.getcwd()
    self.reportpath = os.getcwd()

    self.logpath =  BuiltIn().get_variable_value('${ $EXECDIR}')
    self.reportpath  =  BuiltIn().get_variable_value('${ $EXECDIR}')

 getting following error
     self.logpath  = BuiltIn().get_variables().get('${EXECDIR}')
  File "/usr/local/lib/python2.5/site-packages/robot/libraries/BuiltIn.py", line 940, in get_variables
    return utils.NormalizedDict(self._variables.current, ignore='_')
  File "/usr/local/lib/python2.5/site-packages/robot/libraries/BuiltIn.py", line 2664, in _variables
    return self._namespace.variables
  File "/usr/local/lib/python2.5/site-packages/robot/libraries/BuiltIn.py", line 2656, in _namespace
    return self._context.namespace
AttributeError: 'NoneType' object has no attribute 'namespace'

       
def generateTests(self):
    self.testSuite = TestSuite(Constants.TEST_SUITE_NAME)
    self.testSuite.imports.library(Constants.LIBRARY_NAME,args=[self.testdetails])
    scriptname_list = self.getSASScript()
    if scriptname_list.__len__() == 0:return False 
    for script_name in scriptname_list:
      test = self.testSuite.tests.create(script_name)
      test.keywords.create(Constants.KEYWORD_EXECUTE, args=[script_name])
      test.keywords.create(Constants.KEYWORD_RESULT_SHOULD_BE, args=[Constants.TEST_PASSED])
    return True

def getScripts(self):
    script_list = []
    if os.path.islink(Constants.SCRIPT_LINK_PATH):
      script_list = [fn for fn in os.listdir(Constants.SCRIPT_LINK_PATH) if any([fn.endswith(ext) for ext in Constants.SCRIPT_EXTENSIONS])];
    return script_list

Pekka Klärck

unread,
Feb 25, 2014, 9:03:05 AM2/25/14
to gunaseelan...@gmail.com, robotframework-users
2014-02-24 8:41 GMT+02:00 gunaseelan Sakkarapani
<gunaseelan...@gmail.com>:
You didn't really explain what you are trying to do, but my guess is
that you are trying to create some kind of a custom test runner. If
that's the case, the reason for the above failure is that Robot's
variables are available only during test execution and in this case
execution hasn't yet started. The resulting error isn't too
informative. If you want, you can submit an enhancement request about
enhancing the error message.

In your case the easiest solution to this problem is using
os.getcwd(). The result ought to be exactly same as the value of
${EXECDIR}.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org
Reply all
Reply to author
Forward
0 new messages