关键字驱动
import xlrd from xlutils.copy import copy class ExcelUtil: def __init__(self,excel_path=None,index=None): if excel_path == None: excel_path = '路经\\ddt_case.xls' if index == None: index = 0 self.data = xlrd.open_workbook(excel_path) self.table = self.data.sheets()[index] #按照每行的List,添加到一个大的List里面 def get_data(self): ddt_list = [] rows = self.get_lines() if rows!=None: for i in range(rows): col = self.table.row_values(i) ddt_list.append(col) return ddt_list return None def get_lines(self):#获取excel的行数 rows = self.table.nrows if rows>=1: return rows return None def get_col_value(self,row,col):#获取单元格的数据 if self.get_lines()>row: data = self.table.cell(row,col).value return data return None def write_value(self,row,value):#写入数据 read_value = self.data write_data = copy(read_value) write_data.get_sheet(0).write(row,7,value) #2是要写入的列数,从0开始的 write_data.save('路经\\keyword.xls')
from gongju_nei.excel_read import ExcelUtil from key_word.actionMethod import ActinMethod import sys sys.path.append('E:\\test_project') class Keywordcase: def run_main(self): self.actin_mentgod = ActinMethod() handle_excel = ExcelUtil('路经\\keyword.xls') #拿到行数 case_lines = handle_excel.get_lines() if case_lines: for i in range(1,case_lines): is_run = handle_excel.get_col_value(i,3) #1.是否执行 if is_run == 'yes': method = handle_excel.get_col_value(i, 4) #2.执行方法 send_value = handle_excel.get_col_value(i, 5) #3.输入数据 handle_value = handle_excel.get_col_value(i, 6) #4.操作元素 这里面对应的是xelce里面的数据 mokuai = handle_excel.get_col_value(i,1)# element在哪里取 if method=='open_browser': self.actin_mentgod.open_browser(handle_value) elif method=='get_url': self.actin_mentgod.get_url(handle_value) elif method=='element_send_keys': self.actin_mentgod.element_send_keys(mokuai,handle_value,send_value) elif method=='click_element': self.actin_mentgod.click_element(mokuai,handle_value) else: self.actin_mentgod.sleep_time() self.actin_mentgod.close_browser() if __name__ == '__main__': Keywordcase().run_main()