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多行的更多相关文章

  1. 用python写一个定时提醒程序

    身体是革命的本钱,身体健康了我们才有更多精力做自己想做的事情,追求女神,追求梦想.然而程序员是一个苦比的职业,大部分时间都对着电脑,我现在颈椎就不好了,有时候眼睛还疼,我还没20阿,伤心...于是乎写 ...

  2. Python flask构建微信小程序订餐系统✍✍✍

    Python flask构建微信小程序订餐系统  整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程本身没问题, ...

  3. python实现串口通讯小程序(GUI界面)

    python实现串口通讯小程序(GUI界面) 使用python实现串口通讯需要使用python的pyserial库来实现,这个库在安装python的时候没有自动进行安装,需要自己进行安装. 1.安装p ...

  4. Python flask构建微信小程序订餐系统

    第1章 <Python Flask构建微信小程序订餐系统>课程简介 本章内容会带领大家通览整体架构,功能模块,及学习建议.让大家在一个清晰的开发思路下,进行后续的学习.同时领着大家登陆ht ...

  5. Python flask构建微信小程序订餐系统☝☝☝

    Python flask构建微信小程序订餐系统☝☝☝ 一.Flask MVC框架结构 1.1实际项目结构 1.2application.py  项目配置文件 Flask之flask-script模块使 ...

  6. python爬取微信小程序(实战篇)

    python爬取微信小程序(实战篇) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90452656 展开 一.背景介绍 近期有需求需要抓 ...

  7. Python爬取微信小程序(Charles)

    Python爬取微信小程序(Charles) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90045204 一.前言 最近需要获取微信小 ...

  8. Python 每日提醒写博客小程序,使用pywin32、bs4库

    死循环延迟调用方法,使用bs4库检索博客首页文章的日期是否与今天日期匹配,不匹配则说明今天没写文章,调用pywin32库进行弹窗提醒我写博客.

  9. 使用Python编写打字训练小程序【华为云技术分享】

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/devcloud/article/detail ...

随机推荐

  1. centos7 yum安装LAMP

    说明:我安装后的版本号分别是: apache : Apache/2.4.6 (CentOS)mysql:5.6.42php:5.6.39 一.配置网络. 我们首先需要让我们的虚拟机能够连接上外网,这样 ...

  2. centos7安装python3 以及tab补全功能

    1.安装python3 1.1下载python源码包 网址:https://www.python.org/downloads/release/python-362/ 下载地址:https://www. ...

  3. jq三级联动

    test.html <div class="a_list"> <div class="a_title">商城分类:</div> ...

  4. python在读取文件时出现 'gbk' codec can't decode byte 0x89 in position 68: illegal multibyte sequence

    python在读取文件时出现“UnicodeDecodeError:'gbk' codec can't decode byte 0x89 in position 68: illegal multiby ...

  5. Linux命令 file

    查看文件类型:

  6. ECC椭圆曲线以及计算出公钥的过程(BTC为例)

    ECC概念 全称 “ Ellipse Curve Cryptography ”  means “ 椭圆 曲线 密码学 ”. 传统加密方法大多基于大质数因子分解困难性来实现,ECC则是通过椭圆曲线方程式 ...

  7. [03-01]JDBC基础

    JDBC是什么? 1.java Database Connectivity:java访问数据库的解决方案: 2.用相同的方式访问不同的数据库,以实现与具体数据库无关的java操作界面: 3.JDBC定 ...

  8. day27:反射和双下方法

    1, # 面向对象的三大特性:继承,多态和封装 # 继承: # 单继承: **** # 父类(超类,基类) # 子类(派生类) 派生方法和派生属性 # 子类的对象在调用方法和属性:先用自己的,自己没有 ...

  9. eclipse启动报错

    我的是win64位系统,eclipse,jdk1.8    64位 原因:网上说是jdk和eclipse的版本不一致导致的(32位jdk64位eclipse,或者相反): 解决过程: 安装了jdk1. ...

  10. java script基本数据类型与数组

    基本数据类型 1.undefined  (var a;) 2.null   (var a=null); 3.String  (var a=" " or ' '); 4.boolea ...