赞
踩
实现的datas数据是这样的:
任务就是把里面的数据全部都取到,并且对数据可以进行处理。
datas内容:
SheetName,Step,Behavior,OperationPage,Description,ObjectName,PositioningExpression,InputValue,OutputValue,ExpectedResult,WaitTime,Enabled,IgnoreErr,LoopCnt
case_one,1,openurl,Logon,打开浏览器,Stadd,,http://mozilla.com.cn/moz-portal.html,,,1,True,True,1
case_one,2,refresh,Logon,刷新,Stadd,,,,,10,True,True,1
case_one,3,click,Logon,电影,Button,/html/body/div[6]/div[1]/div/div/form/div/div[1]/a[1],,,,2,True,True,1
case_one,4,quit,,close webdrive,,,,,,2,True,True,1
话不多说,上代码!
import pandas as pd import os class DoFile: def get_excellist(self): file_list = [] root_dir = os.getcwd() dir_or_files = os.listdir(root_dir) for dir_file in dir_or_files: dir_file_path = os.path.join(root_dir, dir_file) if os.path.isdir(dir_file_path): pass else: filepath, filename = os.path.split(dir_file_path) file_list.append(filename) case_list = list(filter(lambda case: ".csv" in case, file_list)) if not case_list: raise Exception(self.log.logMsg(3, ("case not exist"))) return case_list class CaseStep: def __init__(self): self.SheetName = '' self.Step = 0 self.Behavior = '' self.OperationPage = '' self.Description = '' self.ObjectName = '' self.PositioningExpression = '' self.InputValue = '' self.OutputValue = '' self.ExpectedResult = '' self.WaitTime = 1 self.Enabled = 1 self.IgnoreErr = 1 self.LoopCnt = 1 class Case: def __init__(self): self.caseSteps = list() self.elementMaps = list() class ExcelCaseReader: def __init__(self): self.excel = DoFile() def read_case(self): """ read case file and return case """ case = Case() csv_list = self.excel.get_excellist() print('*'*30,f'{csv_list}') for xlsx in csv_list: if "~$" in xlsx: pass else: csv = pd.read_csv(xlsx) # print(pd.read_csv(xlsx).loc[0].to_dict()) df = pd.DataFrame(csv) self.df = df for value in range(len(df.index)): case_step = CaseStep() case_step.SheetName = df['SheetName'][value] case_step.Step = df['Step'][value] case_step.Behavior = df['Behavior'][value] case_step.OperationPage = df['OperationPage'][value] case_step.Description = df['Description'][value] case_step.ObjectName = df['ObjectName'][value] case_step.PositioningExpression = df['PositioningExpression'][value] case_step.InputValue = df['InputValue'][value] case_step.OutputValue = df['OutputValue'][value] case_step.ExpectedResult = df['ExpectedResult'][value] case_step.WaitTime = df['WaitTime'][value] case_step.Enabled = df['Enabled'][value] case_step.IgnoreErr = df['IgnoreErr'][value] case_step.LoopCnt = df['LoopCnt'][value] case.caseSteps.append(case_step) return case if __name__ == '__main__': case = ExcelCaseReader().read_case() for i in case.caseSteps: print(i.Description)
那么运行的结果如下:
****************************** ['datas.csv']
打开浏览器
刷新
电影
close webdrive
补充接口的:
CsvName,Step,Description,Method,Url,Grant_type,Client_id,Client_secret,Username,Password,WaitTime,Enabled,IgnoreErr
CsvName,1,demo1,get,/wmr-auth/v1/wmr-token,password,cfss_wmr,secret,100557,0000abc!,1,0,0
CsvName,2,demo2,post,/wmr-auth/v1/wmr-token,password,cfss_wmr,secret,105565,0000abc!,2,0,0
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。