# Will read the Sahi results and print the Total,Passed,Failed steps into notepad
import configparser
import sys
import os
import shutil
import subprocess
import smtplib
import errno
import time
#import configobj
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import datetime
from datetime import date
from bs4 import BeautifulSoup
def updateResultStat():
”’
This function is will update the result status in table CI_EXECUTION_STATUS
@ciRunNo – Execution id of the CI run
@candidateName – Installer Name of the CI run
@endTime – End time of the CI run
@ciStatus – CI STatus
@moduleName – Module Name
@version – Module Version
”’
resultHome=”D:\\M7Regression\\LatestAutomationResults\\”
CreateFile()
for folderName in os.listdir(resultHome):
folderPath = resultHome +”\\”+ folderName
#os.system(“pause”)
totalStep=0
totalPassSteps=0
totalFailSteps=0
startTime=0
endTime=0
browser,startTime,endTime,totalStep,totalPassSteps,totalFailSteps = getTestStepcount(folderPath+”\\”)
WriteResultsToFile(folderName,browser,startTime,endTime,totalStep,totalPassSteps,totalFailSteps)
print(“INFO: Results Updated Please check ConsolidatedResult.txt file”)
os.system(“pause”)
def getTestStepcount(baseFolder):
”’
This function is will get the no of test steps passed and failed for complete execution
@baseFolder – Report folder path where CI TC’s execution status count needs to be updated
returns totalSteps,totalPassSteps,totalFailSteps
”’
B_Browser=0
S_StartTime=0
E_EndTime=0
Total_test_run=0
Total_Testcases_passed=0
Total_Testcases_failed=0
#for file in os.listdir(baseFolder):
# passSteps=0
# failSteps=0
# if file.endswith(“.html”):
# if file == “index.html”:
# fileName=baseFolder+”\\”+file
# B_Browser,S_StartTime,E_EndTime = getTestStepsCount(fileName)
for file in os.listdir(baseFolder):
if file.endswith(“.html”):
if file == “testcase_summary.html”:
fileName=baseFolder+”\\”+file
Total_test_run,Total_Testcases_passed,Total_Testcases_failed = getTestStepsCountIndexHTML(fileName)
return B_Browser,S_StartTime,E_EndTime,Total_test_run,Total_Testcases_passed,Total_Testcases_failed
def getTestStepsCount(fileName):
”’
This function is will get the no of pass steps and fail steps for one script
@fileName – fileName which needs to be searched for success tag
returns passSteps,failedCount
”’
Browser=0
StartTime=0
EndTime=0
try:
#fileText=open(fileName,’r’)
fileText=open(fileName, encoding=”utf8″)
soup = BeautifulSoup(fileText)
testcase_summary_table=soup.find(‘table’,{‘class’:’suite_summary_part’})
testcase_summary_table_td=testcase_summary_table.find_all(‘td’)
tdCount=0
for td in testcase_summary_table_td:
if tdCount==1:
Browser=td.text
if tdCount==3:
StartTime=td.text
if tdCount==5:
EndTime=td.text
tdCount=tdCount+1
fileText.close()
except IOError as fileOpenError:
print(“INFO”)
finally:
return Browser,StartTime,EndTime
def getCommentedCount(fileName):
”’
This function is will get the no of commented test steps for one script
@fileName – fileName which needs to be searched for success tag
returns commentedCount
”’
commentedCount=0
fileText=open(fileName,’r’)
soup = BeautifulSoup(fileText)
for tr in soup.find_all(‘tr’,{‘class’:[‘SUCCESS’]}) :
for td in tr.find_all(‘td’):
if td.text.find(‘//’)== 0:
commentedCount=commentedCount+1
break
if td.text.find(‘Test Case Id’)== 0:
commentedCount=commentedCount+1
break
fileText.close()
return(commentedCount)
def getTestStepsCountIndexHTML(fileName):
”’
This function is will get the no of pass steps and fail steps for one script
@fileName – fileName which needs to be searched for success tag
returns passSteps,failedCount
”’
commentedSteps=0
Total_testcases_run=0
Testcases_passed=0
Testcases_failed=0
try:
#fileText=open(fileName,’r’)
fileText=open(fileName, encoding=”utf8″)
print(fileName)
#print(fileText)
#time.sleep(3)
#os.system(“pause”)
soup = BeautifulSoup(fileText)
suite_summary_table=soup.find(‘table’,{‘class’:’suite_summary’})
suite_summary_td=suite_summary_table.find_all(‘td’)
tdCount=0
for td in suite_summary_td:
if tdCount==11:
Total_testcases_run=td.text
if tdCount==13:
Testcases_passed=td.text
if tdCount==15:
Testcases_failed =td.text
tdCount=tdCount+1
fileText.close()
except IOError as fileOpenError:
print(“ERROR: Error in opening file”)
os.system(“pause”)
finally:
return Total_testcases_run,Testcases_passed,Testcases_failed
def CreateFile():
”’
This function is will get the no of pass steps and fail steps for one script
@fileName – fileName which needs to be searched for success tag
returns passSteps,failedCount
”’
try:
f = open(“ConsolidatedResult.txt”,”w”) #opens file with name of “test.txt”
f.write(“FolderName\t\tTotalScripts\tTotalPassed\tTotalFailed”)
f.close()
except IOError as fileOpenError:
print(“ERROR: in creating ConsolidatedResult.txt”)
os.system(“pause”)
finally:
print(“INFO: ConsolidatedResult.txt File Created”)
def WriteResultsToFile(folderName,browser,startTime,endTime,totalStep,totalPassSteps,totalFailSteps):
”’
This function is will get the no of pass steps and fail steps for one script
@fileName – fileName which needs to be searched for success tag
returns passSteps,failedCount
”’
folderName,browser,startTime,endTime,totalStep,totalPassSteps,totalFailSteps
try:
f = open(“ConsolidatedResult.txt”,”a”)
f.write(“\n” + str(folderName) + “\t\t” + str(totalStep) + “\t” + str(totalPassSteps) + “\t” + str(totalFailSteps))
f.close()
except IOError as fileOpenError:
print(“ERROR: In updating the ConsolidatedResult.txt file”)
os.system(“pause”)
finally:
print(“Writing Total, Passed, Failed steps into ConsolidatedResult.txt for the folder ” + folderName)