鱼C论坛

 找回密码
 立即注册
查看: 2904|回复: 2

selenium自动化测试结果保存

[复制链接]
发表于 2016-1-23 13:18:12 | 显示全部楼层 |阅读模式
50鱼币
利用selenium来做自动化测试、测试结果怎么保存呢?有没有一个eg。。

最佳答案

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-1-23 13:18:13 | 显示全部楼层
  1. #coding:utf-8
  2. import time
  3. import xlsxwriter

  4. class Loginfo(object):
  5.     def __init__(self, path = '', mode = 'w'):
  6.         fname = path + time.strftime('%Y-%m-%d', time.gmtime())
  7.         self.log = open(path + fname + '.txt', mode)

  8.     def log_init(self, sheetname, *title):
  9.         pass

  10.     def log_write(self, msg):
  11.         self.log.write(msg)

  12.     def log_close(self):
  13.         self.log.close()

  14. class Xlloginfo(object):
  15.     def __init__(self, path=''):
  16.         fname = path + time.strftime('%Y-%m-%d', time.gmtime())
  17.         self.row = 0
  18.         self.xl = xlsxwriter.Workbook(path+fname+'.xlsx')
  19.         self.style = self.xl.add_format({'bg_color':'red'})
  20.     def xl_write(self, *args):
  21.         col = 0
  22.         style =''
  23.         if 'Error' in args:
  24.             style = self.style
  25.         for val in args:
  26.             self.sheet.write_string(self.row, col, val, style)
  27.             col += 1
  28.         self.row+=1
  29.     def log_init(self, sheetname, *title):
  30.         self.sheet = self.xl.add_worksheet(sheetname)
  31.         self.sheet.set_column('A:E', 30)
  32.         self.xl_write(*title)

  33.     def log_write(self, *args):
  34.         self.xl_write(*args)
  35.     def log_close(self):
  36.         self.xl.close()


  37. if __name__ == '__main__':

  38.     xinfo = Xlloginfo()
  39.     xinfo.log_init('test', 'uname', 'pwd', 'result', 'info')
  40.     xinfo.log_write('123', '123', 'Error', 'error')
  41.     xinfo.log_close()
复制代码

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
哇哈哈笑哈哈 + 1 + 1 支持楼主!

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-1-23 13:22:38 | 显示全部楼层
刚好自己有一份,看着点改就可以用

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
哇哈哈笑哈哈 + 1 + 1 热爱鱼C^_^

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-19 09:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表