Example #1
0
    def getUploadFiles(self, value):
        # 上传
        scriptId = self._driver.logger.scriptId
        tempFilesList = []

        filesDir = pathJoin(settings.TESTCASE['filesDir'], scriptId)  # 上传文件夹
        for x in range(len(value)):
            try:
                filePath = pathJoin(filesDir, os.path.basename(value[x]))
                if os.path.isfile(filePath):
                    tempFilesList.append(filePath)
                    continue

                filePath = value[x].replace('\\', '/')
                if not isAbsolutePath(filePath):
                    filePath = pathJoin(settings.TESTCASE['filesDir'],
                                        filePath)

                if os.path.isfile(filePath):
                    tempFilesList.append(filePath)
                else:
                    raise UploadFilePathException('', filePath)
            except Exception as e:
                putSystemLog(e, self._driver.logger, True, RunStatus.RUNNING,
                             RunResult.ERROR, True, '异常')

        return tempFilesList
Example #2
0
    def loadTestPlanXML(self):
        '''
		加载测试用例配置文件
		:return:
		'''
        try:
            if not isAbsolutePath(self.xmlPath):
                self.xmlPath = pathJoin(settings.TESTCASE['xmlDir'],
                                        self.xmlPath)

            tree = ET.parse(self.xmlPath)  # 打开xml文档
            root = tree.getroot()  # 获得root节点
            for child in root:
                if child.tag == settings.XML_TAG['testPlan']['connection']:
                    if len(self.hubDict) == 0:
                        self.hubDict = self.getHubDict(child)
                elif child.tag == settings.XML_TAG['testPlan']['scene']:
                    sceneId = child.get(
                        settings.XML_TAG['testPlan']['sceneid'])  # sceneId
                    settings.SCENEID = sceneId
                    testCaseList = self.getTestList(child)  # 读取一个场景中的所有测试用例
                    testScene = TestScene(sceneId, testCaseList)
                    self.testPlan.append(testScene)  # 将测试用例列表添加到测试方案中
        except Exception as e:
            putSystemLog('[ERROR-1001]:读取测试方案配置文件引发的异常.%s' % (e), None, True,
                         RunStatus.END, RunResult.ERROR, True, '异常')
            raise
Example #3
0
 def getTemplatePathList(self):
     list = []
     for fileName in settings.TEMPLATES['templateDir']:
         list.append(
             pathJoin(settings.SRC_DIR,
                      settings.TEMPLATES['storeTemplateDir'], fileName))
     return list
Example #4
0
 def initLocalDirectory(self, projectDir):
     if not projectDir:
         projectDir = self.getRootDir(settings.SRC_DIR)
     localTestCaseDir = pathJoin(projectDir,
                                 settings.TESTCASE['testCaseDir'])[:-1]
     self.setControlData(localTestCaseDir, self.treeWidget_local,
                         self.lineEdit_local)
Example #5
0
 def diguiReadDir(self, dir):
     files = os.listdir(dir)
     for file in files:
         path = pathJoin(dir, file)
         if os.path.isfile(path):
             self.addTestPlan(path, file)
         elif os.path.isdir(path):
             self.diguiReadDir(path)
Example #6
0
def initSettings():  # 初始化全局变量
	from collections import OrderedDict
	from SRC import settings
	from SRC.common.fileHelper import pathJoin
	from SRC.common.const import RunModel
	settings.SRC_DIR = getSrcDir(src_dir)  # 源码所在目录
	settings.SCRIPT_DIR = getScriptDir()  # 脚本所在目录
	settings.TESTCASE['xmlDir'] = pathJoin(settings.SCRIPT_DIR, settings.TESTCASE['xmlDir'])  # 测试方案目录
	settings.TESTCASE['filesDir'] = pathJoin(settings.SCRIPT_DIR, settings.TESTCASE['filesDir'])  # 上传图片路径
	settings.PARAMETERIZATION['dataDir'] = pathJoin(settings.SCRIPT_DIR, settings.PARAMETERIZATION['dataDir'])  # 参数化目录
	settings.REPORT['logDir'] = pathJoin(settings.SCRIPT_DIR, settings.REPORT['logDir'])  # 日志目录
	settings.REPORT['screenShotDir'] = pathJoin(settings.SCRIPT_DIR, settings.REPORT['screenShotDir'])  # 截图目录
	settings.logger = createSysLog()  # 系统输出日志
	settings.UNIQUECODE = None  # 唯一码
	settings.SCENEID = None  # 场景ID
	settings.LOG_RECORD = OrderedDict()
	settings.RUNMODEL = RunModel.NORMAL  # 默认运行模式
Example #7
0
def setImageFormat(path):
	'''
	设置图片路径格式为相对路径
	:param image:
	:return:
	'''
	image = ''
	if not isNoneOrEmpty(path):
		image = pathJoin(basename(settings.SCRIPT_DIR), path.split(settings.SCRIPT_DIR)[1])
	return image
Example #8
0
	def addTestCase(self, testCasePath, enabled, paramPath):
		displayParamPath = ''
		absoluteParamPath = ''
		if not isNoneOrEmpty(paramPath):
			if not isAbsolutePath(paramPath):
				paramPath = delFirstChar(paramPath, ['/', '\\'])

				displayParamPath = delsuffix(paramPath, '.xml')
				absoluteParamPath = pathJoin(settings.PARAMETERIZATION['dataDir'], paramPath)
				absoluteParamPath = delsuffix(absoluteParamPath, '.xml', False)

		fileName = ''  # 文件名称
		disPlayPath = ''  # 显示路径
		absolutePath = ''  # 绝对路径
		if not isNoneOrEmpty(testCasePath):
			testCaseDir = settings.TESTCASE['testCaseDir']
			testCasePath = delFirstChar(testCasePath, ['/', '\\'])

			if not testCasePath.startswith(testCaseDir):
				testCasePath = testCaseDir + testCasePath

			absolutePath = pathJoin(settings.SCRIPT_DIR, testCasePath)
			absolutePath = delsuffix(absolutePath, '.py', False)
			fileName = os.path.basename(absolutePath).split('.')[0]
			disPlayPath = absolutePath.split(testCaseDir)[1]
			disPlayPath = delsuffix(disPlayPath, '.py')

		enabled = True if enabled is None or enabled.lower().strip() == 'true' else False

		def testCaseFunc():
			return TestCase(absolutePath, absoluteParamPath)

		model = {'name': fileName,
				 'obj': testCaseFunc,
				 'path': disPlayPath,
				 'paramPath': displayParamPath,
				 'absolutePath': absolutePath,
				 'absoluteParamPath': absoluteParamPath,
				 'enabled': enabled,
				 'unique': randomStr(10, True, True, True)
				 }
		return model
Example #9
0
    def setTestPlanPathFromUser(self):
        '''
		控制台根据用户输入设置测试方案路径
		:return:
		'''
        filesList = []
        index = 0
        try:
            for dirPath, dirNames, fileNames in os.walk(
                    settings.TESTCASE['xmlDir']):
                for filename in fileNames:
                    if filename[-4:] == '.xml':
                        filesList.append(
                            (index + 1, filename, dirPath.replace(
                                '\\', '/').split(settings.SCRIPT_DIR)[1]))
                        index += 1
            if len(filesList) == 0:
                print('%s目录下没有测试方案' % (settings.TESTCASE['xmlDir']))
                return
            print('%-3s %s' % ('编号', '测试方案'))
            for file in filesList:
                print('%-5s %s' % (file[0], pathJoin(file[2], file[1])))
            while True:
                result = input('请选择测试方案编号:')
                if result.isdigit():
                    result = int(result) - 1
                    if result >= 0 and result < len(filesList):
                        self.xmlPath = filesList[int(result)][1]
                        print('即将运行测试方案:%s' % (self.xmlPath))
                        break
                    else:
                        print('输入错误')
                else:
                    print('输入错误')
        except Exception as e:
            print(e)
            raise
Example #10
0
 def __init__(self, projectPath, configXmlPath=None):
     self.testPlanList = []  # 测试方案列表
     # self.initSettings(projectPath)#废弃
     self.testCaseDir = pathJoin(projectPath,
                                 settings.TESTCASE['testCaseDir'])
     self.templateList = self.getTemplatePathList()
Example #11
0
	def getFullUrl(self, url=None):
		if url:
			return pathJoin(self.domain, url)
		else:
			return self.domain
Example #12
0
 def setAbsoluteXmlPath(self):
     if not isAbsolutePath(self.xmlPath):
         self.xmlPath = pathJoin(settings.TESTCASE['xmlDir'], self.xmlPath)