当前位置: 首页>>代码示例>>Python>>正文


Python BuiltIn.run_keyword_and_ignore_error方法代码示例

本文整理汇总了Python中robot.libraries.BuiltIn.BuiltIn.run_keyword_and_ignore_error方法的典型用法代码示例。如果您正苦于以下问题:Python BuiltIn.run_keyword_and_ignore_error方法的具体用法?Python BuiltIn.run_keyword_and_ignore_error怎么用?Python BuiltIn.run_keyword_and_ignore_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在robot.libraries.BuiltIn.BuiltIn的用法示例。


在下文中一共展示了BuiltIn.run_keyword_and_ignore_error方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: keywords

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import run_keyword_and_ignore_error [as 别名]
class keywords (object):

    def __init__(self, baseDir, envDir=None):
        # Get the base working directory
        self.baseDir = baseDir.replace("\\", "/")

        # Get the directory that stores the test environment resources
        if envDir != None:
            self.envDir = envDir.replace("\\", "/")

        # Get an instances of the RF BuildIn Functions
        self.robotBuiltIn = BuiltIn()

    def get_data(self, environments=None):
        # Gets the full location on this file
        self.me = os.path.abspath(__file__)[:-1].replace("\\", "/")
        self.robotBuiltIn.log("File Path: %s" % self.me)

        # Gets the current test suite source
        suiteSource = self.robotBuiltIn.get_variable_value('${SUITE SOURCE}').replace("\\", "/")
        charPos = len(suiteSource) - suiteSource.rfind("/")
        # Removes the last \\ from the suite source
        suiteSourceDir = suiteSource[:-charPos]
        self.robotBuiltIn.log("Suite Directory: %s" % suiteSourceDir)

        # Gets the current test name
        testCaseName = self.robotBuiltIn.get_variable_value('${TEST_NAME}')
        suiteKey = self._get_suite_key()

        # If testCaseName is none, then set suite and environment variables
        if testCaseName == None:
            self.robotBuiltIn.log("Test Case Name is None")

            # Gets the environment level variables
            if environments != None:
                self.robotBuiltIn.log("Environment variable has been passed")

                # Get the environment value if a RF variable has been passed
                patternRFVar = re.compile(r'''\${(.*?)}''', re.UNICODE |
                                                            re.VERBOSE |
                                                            re.S)
                if patternRFVar.search(environments):
                    self.robotBuiltIn.log("Environment variable is a RF variable")
                    environments = self.robotBuiltIn.get_variable_value(environments)

                # Split the env string to get each env that was passed
                envList = environments.split(":")

                # Read the contents of each env yaml and create the variables
                for envFile in envList:
                    self.robotBuiltIn.log("Importing Environment Variables for: %s" % envFile)
                    varFile = os.path.join(self.baseDir, self.envDir, envFile).replace("\\", "/")
                    self.robotBuiltIn.import_variables(self.me, varFile, "env")

            # Gets the suite test data variables and imports variables
            varFile = os.path.join(suiteSourceDir, suiteKey).replace("\\", "/")
            if suiteKey != None:
                self.robotBuiltIn.log("Trying to import suite variables: %s" % varFile)
                if os.path.isfile(varFile + ".yaml"):
                    self.robotBuiltIn.log("File found, importing.")
                    self.robotBuiltIn.import_variables(self.me, varFile)
                else:
                    self.robotBuiltIn.log("File not found. Not importing.")

        # if testCaseName is not none, then set test case variables
        if testCaseName != None:

            # Gets the test case data variables and imports variables
            testKey = self._get_test_key()
            #varFile = (suiteSourceDir + "/" + suiteKey + "-" + testKey)
            varFile = (suiteSourceDir + "/" + testKey)
            print varFile
            if testKey != None:
                if os.path.isfile(varFile + ".yaml"):
                    self.robotBuiltIn.import_variables(self.me, varFile)

    def get_data_service(self, keyword):
        keywordArray = keyword.split("|")
        print keywordArray
        keywordArrayLen = len(keywordArray)
        #print keywordArrayLen
        if keywordArrayLen == 1:
            runKeyword = keywordArray[0]
        else:
            runKeyword = keywordArray.pop(0)

        result = self.robotBuiltIn.run_keyword_and_ignore_error('Keyword Should Exist', runKeyword)
        if result[0] == 'PASS':
            if keywordArrayLen == 1:
                # Gets the return value from the keyword
                testData = self.robotBuiltIn.run_keyword_and_ignore_error(runKeyword)
            else:
                # Gets the return value from the keyword
                testData = self.robotBuiltIn.run_keyword_and_ignore_error(runKeyword, *keywordArray)

        # Run if the keyword runs to PASS and has returned values
        if testData[0] == 'PASS' and testData[1] != None:
            for key, value in testData[1].items():
                variableName = ("${%s}" % key)
                # If the variable is not set the set the variable
#.........这里部分代码省略.........
开发者ID:jbarnes007,项目名称:robotframework-yamlvariableslibrary,代码行数:103,代码来源:_keywords.py


注:本文中的robot.libraries.BuiltIn.BuiltIn.run_keyword_and_ignore_error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。