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


Python BuiltIn.set_suite_variable方法代码示例

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


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

示例1: keywords

# 需要导入模块: from robot.libraries.BuiltIn import BuiltIn [as 别名]
# 或者: from robot.libraries.BuiltIn.BuiltIn import set_suite_variable [as 别名]

#.........这里部分代码省略.........
            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
                if self.robotBuiltIn.get_variable_value(variableName) == None:
                    self.robotBuiltIn.set_suite_variable(variableName, value.strip())

    def _contains(self, string, char):
        listVar = []
        for i in range(0, len(string)):
            if string[i] == char:
                listVar = listVar + [i]
        return listVar

    def _get_suite_key(self):
        suiteName = self.robotBuiltIn.get_variable_value('${SUITE_NAME}')
        tmp1 = self._contains(suiteName, '-')
        try:
            tmp2 = suiteName[:tmp1[0]]
            tmp3 = tmp2.split(".")
            key = tmp3[len(tmp3) - 1]
            self.robotBuiltIn.log("Suite Key: %s" % key.strip())
            return key.strip()
        except:
            raise Exception("Could not find symbol '-' for expected test suite data setup.")
            return None

    def _get_test_key(self):
        testName = self.robotBuiltIn.get_variable_value('${TEST_NAME}')
        tmp1 = self._contains(testName, ':')
        try:
            key = testName[:tmp1[0]]
            self.robotBuiltIn.log("Test Key: %s" % key.strip())
            return key.strip()
        except:
            raise Exception("Could not find symbol ':' for expected test case data setup.")

            return None
开发者ID:jbarnes007,项目名称:robotframework-yamlvariableslibrary,代码行数:104,代码来源:_keywords.py


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