fromSeleniumImportWebdriverImportSelenium.webdriver.support.ui as UI fromSelenium.webdriver.common.byImport by fromSelenium.webdriver.support.uiImportwebdriverwait fromSelenium.common.exceptionsImportnosuchelementexception,webdriverexceptionImportSelenium.webdriver.support.expected_conditions as ECImport Time fromSelenium.webdriver.chrome.optionsImportOptionsImportioImportOSImportReImportUrllib2 fromDatetimeImportdatetimeprojectlist=['*','**']serverurl='****'UserProfile='c:/users/***a'Consoletext='Consoletext'LogPath='**'defWrite_file (data,filename): file_name= Logpath+filename+r'. txt'Append_write='a' ifos.path.exists (file_name): Append_write='W'F=Open (file_name, append_write) f.writelines (data) f.close ()returnfile_namedefget_latest_version (driver,projectlist,serverurl): Version=[] forIinchprojectlist:## # Get Latest version ID. Such as 31,32URL = 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-8URL = 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), BuildidVersion.append ([I,write_file (content,i+'#'+buildid), Buildid])returnversiondefClick_submit (Driver):ifLen (Driver.find_elements_by_css_selector ("input[name= ' J_password ']")) >0:driver.find_element_by_css_selector ("span[name= ' Submit ' button"). Click ();defget_test_summary (file_obj): Issummary=False Result= [] forLineinchFile_obj:if notissummary:if 'Test Summary' inchline:issummary=Trueelif 'End of Summary' inchLine : Break Else: Result.append (line)returnresultdefget_common_issues (list1,list2): Common_issues=[] Result= [L forLinchList1ifLinchList2 and 'failed:0' not inchL] forEleinchResult:ifEle! ='\ r \ n' andEle! ='\ n': Common_issues.append (ele)PrintElereturncommon_issuesdefGet_server_log_path (file_obj): forLineinchFile_obj:if 'GQL Log is located at' inchLine :returnLine.split () [-1]defget_summary_list (Version): Summary_list= [] forOs_eleinchVersion:file_obj= Open (Os_ele[1],'R') Summary_list.append (Get_test_summary (file_obj)) Os_ele.append (Get_server_log_path (file_obj)) fi Le_obj.close ()returnsummary_listdefWrite_summary_log (Summary_log_name, Common_issues,baseurl): forCom_isinchcommon_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: ContinueF= Open (Case_log_path,'R') Data=F.read () f.close () match= Re.findall (r'(?:(?! Test case:).) *test Case:fail', Data,re. Dotall) forIinchmatch:ifos.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') ifI.startswith ('EST Case:'): I= I[i.find ('\ n'):] forParsedinch[Line forLineinchI.split ('\ n')ifLine.strip ()! ="']: F.writelines (parsed) f.write ('\ r \ n') F.close ()Print 'Summary file put in', Summary_log_nameoptions=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]PrintBaseurlsummary_log_name= LogPath + Datetime.today (). Strftime ('%y-%m-%d') + R'. txt'ifos.path.exists (summary_log_name): Os.remove (summary_log_name) write_summary_log (Summary_log_name, Common_ Issues,baseurl)
Python wrote a small program that took a day and turned out to be more than 100 lines.