Python 写了个小程序,耗时一天,结果才100多行
from selenium import webdriver
import selenium.webdriver.support.ui as ui
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException,WebDriverException
import selenium.webdriver.support.expected_conditions as EC
import time
from selenium.webdriver.chrome.options import Options
import io
import os
import re
import urllib2
from datetime import datetime
projectList=['*','**']
serverURL='****'
userProfile='C:/Users/***a'
consoleText='consoleText'
logPath='**'
def write_file(data,fileName):
file_name = logPath+fileName+r'.txt'
append_write = 'a'
if os.path.exists(file_name):
append_write = 'w'
f = open(file_name, append_write)
f.writelines(data)
f.close()
return file_name
def get_latest_version(driver,projectList,serverURL):
version=[]
for i in projectList:
### get latest version ID. Such as 31,32
url = serverURL+str(i)
driver.get(url)
click_submit(driver)
attr = driver.find_elements_by_css_selector("div.build-icon>a")[0].get_attribute("href")
buildId = attr.split('/')[-2]
### get log content with encoding utf-8
url = url+r'/'+buildId+r'/'+consoleText
driver.get(url)
time.sleep(2)
content = driver.page_source.encode("utf-8")
### write file to local, named with like rhel-buildId
### list format: os, logPath(local),buildId
version.append([i,write_file(content,i+'#'+buildId),buildId])
return version
def click_submit(driver):
if len(driver.find_elements_by_css_selector("input[name='j_password']")) > 0:
driver.find_element_by_css_selector("span[name='Submit'] button").click();
def get_test_summary(file_obj):
isSummary = False
result = []
for line in file_obj:
if not isSummary:
if 'Test Summary' in line:
isSummary = True
elif 'End of Summary' in line:
break
else:
result.append(line)
return result
def get_common_issues(list1,list2):
common_issues = []
result = [l for l in list1 if l in list2 and 'Failed: 0' not in l]
for ele in result:
if ele != '\r\n' and ele != '\n':
common_issues.append(ele)
print ele
return common_issues
def get_server_log_path(file_obj):
for line in file_obj:
if 'GQL Log is located at' in line:
return line.split()[-1]
def get_summary_list(version):
summary_list = []
for os_ele in version:
file_obj = open(os_ele[1],'r')
summary_list.append(get_test_summary(file_obj))
os_ele.append(get_server_log_path(file_obj))
file_obj.close()
return summary_list
def write_summary_log(summary_log_name, common_issues,baseUrl):
for com_is in common_issues:
com_is = com_is.split(':')[0]
try:
response = urllib2.urlopen(baseUrl+r'/'+com_is)
case_log_path = write_file(response,com_is+datetime.today().strftime('%Y-%m-%d'))
#print 'case log path:',case_log_path
except:
continue
f = open(case_log_path,'r')
data = f.read()
f.close()
match = re.findall(r'(?:(?!Test Case: ).)*Test Case: Fail',data,re.DOTALL)
for i in match:
if os.path.exists(summary_log_name):
append_write = 'a'
else:
append_write = 'w'
f = open(summary_log_name,append_write)
f.writelines('#########'+com_is+'#########')
f.write('\r\n')
if i.startswith('est Case:'):
i = i[i.find('\n'):]
for parsed in [line for line in i.split('\n') if line.strip() !='']:
f.writelines(parsed)
f.write('\r\n')
f.close()
print 'Summary file put in ', summary_log_name
options = webdriver.ChromeOptions()
options.add_argument('--user-data-dir='+userProfile)
driver = webdriver.Chrome(executable_path=r'C:/Python27/chromedriver.exe',chrome_options=options)
version = get_latest_version(driver,projectList,serverURL)
driver.quit()
summary_list = get_summary_list(version)
common_issues = get_common_issues(summary_list[0],summary_list[1])
baseUrl = version[0][-1]
print baseUrl
summary_log_name = logPath + datetime.today().strftime('%Y-%m-%d') + r'.txt'
if os.path.exists(summary_log_name):
os.remove(summary_log_name)
write_summary_log(summary_log_name, common_issues,baseUrl)
Python 写了个小程序,耗时一天,结果才100多行的更多相关文章
- 用python写一个定时提醒程序
身体是革命的本钱,身体健康了我们才有更多精力做自己想做的事情,追求女神,追求梦想.然而程序员是一个苦比的职业,大部分时间都对着电脑,我现在颈椎就不好了,有时候眼睛还疼,我还没20阿,伤心...于是乎写 ...
- Python flask构建微信小程序订餐系统✍✍✍
Python flask构建微信小程序订餐系统 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程本身没问题, ...
- python实现串口通讯小程序(GUI界面)
python实现串口通讯小程序(GUI界面) 使用python实现串口通讯需要使用python的pyserial库来实现,这个库在安装python的时候没有自动进行安装,需要自己进行安装. 1.安装p ...
- Python flask构建微信小程序订餐系统
第1章 <Python Flask构建微信小程序订餐系统>课程简介 本章内容会带领大家通览整体架构,功能模块,及学习建议.让大家在一个清晰的开发思路下,进行后续的学习.同时领着大家登陆ht ...
- Python flask构建微信小程序订餐系统☝☝☝
Python flask构建微信小程序订餐系统☝☝☝ 一.Flask MVC框架结构 1.1实际项目结构 1.2application.py 项目配置文件 Flask之flask-script模块使 ...
- python爬取微信小程序(实战篇)
python爬取微信小程序(实战篇) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90452656 展开 一.背景介绍 近期有需求需要抓 ...
- Python爬取微信小程序(Charles)
Python爬取微信小程序(Charles) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90045204 一.前言 最近需要获取微信小 ...
- Python 每日提醒写博客小程序,使用pywin32、bs4库
死循环延迟调用方法,使用bs4库检索博客首页文章的日期是否与今天日期匹配,不匹配则说明今天没写文章,调用pywin32库进行弹窗提醒我写博客.
- 使用Python编写打字训练小程序【华为云技术分享】
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/devcloud/article/detail ...
随机推荐
- bool值的底层应用场景
这里我们的if 或者while,还有and,or,not 等都是在内部调用一个对象的bool方法,然后返回True或者是False, a = [0, ] # a = [] # print(bool(a ...
- JavaEE 之 后台验证+拦截器
1.Validator后台验证 a.在web.xml中配置 <listener> <listener-class>org.springframework.web.context ...
- java 多态 向上 向下转型
向上转型 将子类对象当作父类对象 子类对象------>父类对象 先实例化子类 父类 父类对象 = 子类实例 package test2; class Father{ public vo ...
- Mybatis 通用 Mapper 和 Spring 集成
依赖 正常情况下,在原有依赖基础上增加的 mapper-spring. <!-- https://mvnrepository.com/artifact/tk.mybatis/mapper-spr ...
- 使用CSS达到文字首尾对齐效果
在制作表单的时候经常会遇到需要不同个数的文字首尾对齐,比如: <span>姓名:</span> <span>联系方式:</span> 姓名: 联系方式: ...
- Petrozavodsk Winter-2018. Jagiellonian U Contest
A. XOR 求出所有数的异或和$sum$,将所有数and上$sum$,然后求线性基,则选取$sum$的所有$1$对应的基最优. 时间复杂度$O(n\log x)$. #include<cstd ...
- [LeetCode] Bricks Falling When Hit 碰撞时砖头掉落
We have a grid of 1s and 0s; the 1s in a cell represent bricks. A brick will not drop if and only i ...
- centos下静默安装oracle11g
一.安装依赖包 yum -y install gcc make binutils gcc-c++ compat-libstdc++-33 elfutils-libelf-devel elfutils- ...
- python 读取文本文档中的数据
import os dir = input('Please input the file dir:')#提示输入文件路径 while not os.path.exists(dir):#判断文件是否存在 ...
- 使用ajax分页查询
controller: /** * 查询所有用户/查找指定用户 * 分页+搜索 * */@RequestMapping("/findClientBySize")@ResponseB ...