reader = Reader() reader.open_excel(f'./lib/{casename}.xlsx') writer = Writer() #复制用例文件,用于写入结果 writer.copy_open(f'./lib/{casename}.xlsx', f'./lib/{casename}_result.xlsx') sheetname = reader.get_sheets() # 写开始时间 starttime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) writer.set_sheet(sheetname[0]) writer.write(1, 3, starttime) # 运行的实例对象,默认是HTTP接口,可选为webUI自动化,app自动化 http = HTTP(writer) web = Web(writer) app = App(writer) obj = http for sheet in sheetname: # 设置当前读取的sheet页面 reader.set_sheet(sheet) writer.set_sheet(sheet) lines = reader.readline() # 分用例类型执行,不填则为HTTP line = lines[1] if line[1] == "HTTP": obj = http elif line[1] == "WEB": obj = web
sheetname = reader.get_sheets() writer.set_sheet(sheetname[0]) starttime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) writer.write(1, 3, starttime) reader.readline() casetype = reader.readline()[1] # 执行用例的关键字库对象 obj = None if casetype == 'HTTP' or casetype == '': # 执行http接口自动化 obj = HTTP(writer) elif casetype == 'SOAP': obj = SOAP(writer) elif casetype == 'WEB': obj = Web(writer) elif casetype == 'APP': obj = App(writer) for sheet in sheetname: # 设置当前读取的sheet页面 reader.set_sheet(sheet) # 读到哪个sheet页,写到哪个sheet页 writer.set_sheet(sheet) for i in range(reader.rows): line = reader.readline() # 读到哪一行,写到哪一行 obj.row = i if len(line[0]) > 0 or len(line[1]) > 0: # 分组信息,不用执行 pass
# coding=utf-8 from web.webkeys import Web webobj = Web() # 打开谷歌浏览器 webobj.openbrowser('gc') # 访问网站 webobj.geturl('http://112.74.191.10:8000/') # 登录 webobj.click_link('//*[text()="登录"]') webobj.input('//*[@id="username"]', '13800138006') webobj.input('//*[@id="password"]', '123456') webobj.input('//*[@id="verify_code"]', '111') webobj.js_click('//*[@id="loginform"]/div/div[6]/a') # 校验 webobj.sleep(2) webobj.gettext('/html/body/div[1]/div/div/div/div[2]/a[1]') webobj.assertequals('南京', '登录') webobj.sleep(3) webobj.quit()