aboutsummaryrefslogtreecommitdiffstats
path: root/qa_graph.py
blob: 6d3c64c2fc47b7353ea51fc2167a8980ffea1aa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/env python2.7

# Description:
# This script is intend to analyse the testopia result of any particular release using selenium
# This script will create a qa_graph excel sheet upon successful execution which will contain following information under that release:
# total number of - auto test cases, manual test cases, passed test cases, failed test cases,
# idle test cases, running test cases, blocked test cases,  paused test cases, error test cases
# Prerequisite:
# use a good network so that testopia pages are opened within the given delay time to fetch the required information.
# install any selenium driver (eg.gecko or chromedriver) on the host machine. 
# put the main script 'qa_graph' and config file 'config.ini' on the same location.
# modify the config file accordingly and mention your selenium driver path in it.
# run the script using command - python qa_graph.py

# Python Standard Library modules
import os
import time
import getpass
import logging
import ConfigParser
import openpyxl
from selenium import webdriver

#Opening an excel sheet to store the result of the script 
wb = openpyxl.Workbook()
sheet=wb.active
sheet = wb.get_sheet_by_name('Sheet')
sheet.title = 'result'
sheet['A1'] = 'Total Auto'
sheet['A2'] = 'Total Manual'
sheet['A3'] = 'Total Passed'
sheet['A4'] = 'Total Failed'
sheet['A5'] = 'Total Idle'
sheet['A6'] = 'Total Running'
sheet['A7'] = 'Total Paused'
sheet['A8'] = 'Total Blocked' 
sheet['A9'] = 'Total Error'
sheet['A10'] = 'Total Test Cases'

#taking logs of the script into 'test.log' file
logging.basicConfig(filename='test.log', level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(message)s')
try:

	#configParser = ConfigParser.RawConfigParser()
	#configFilePath = os.getcwd() + r'/config.ini'
	#configParser.read(configFilePath)
	release_name = raw_input("Enter release number: ")
	#testopia release url
	testopia_url = "https://wiki.yoctoproject.org/wiki/Yocto_Project_" + release_name + "_Release_Test_Plan"
	logging.info("URL : %s" %testopia_url)
	#user inputs for testopia login id
	login = raw_input("Enter user name: ")
	#user inputs for testopia login password
	password = getpass.getpass("Enter password: ")
	#getting local session of Chrome by giving driver path from the config file
	#driver_path = configParser.get('testopia', 'driver_path')
	#driver = webdriver.Chrome(driver_path)
	print os.getcwd() + "/chromedriver"
	driver = webdriver.Chrome(os.getcwd() + "/chromedriver")
	driver.maximize_window()
	print "Nain"
	#opening the testopia page for the release
	driver.get(testopia_url)
	time.sleep(7)
	driver.find_element_by_partial_link_text("WW").click()
	time.sleep(7)
	driver.find_element_by_xpath("//*[@id='mw-content-text']/table[3]/tbody/tr/td/table[1]/tbody/tr[2]/td/div/table/tbody/tr[2]/td[1]/a[1]").click()
	time.sleep(3)
	# using user credentials to login into the testopia
	Login = driver.find_element_by_css_selector('#Bugzilla_login')
	Login.send_keys(login)
	Password = driver.find_element_by_css_selector('#Bugzilla_password')
	Password.send_keys(password)
	login = driver.find_element_by_css_selector('#log_in')
	login.click()
	logging.info("Login Completed Using '%s' username" %login)
	time.sleep(7)
	driver.get(testopia_url)
	time.sleep(7)
	release_paths = driver.find_elements_by_partial_link_text("WW")
	release_count = len(driver.find_elements_by_partial_link_text("WW"))
	print " "
	print("Releases under %s are : " % release_name)
	print "--------------------------------------------------------------------------------"
	for item in release_paths:
		release_path = item.get_attribute("href")
		release_text = (release_path).split('Cycle')
		release_name = release_text[1]
		for i in range(0,len(release_name)):
			if release_name[i].isnumeric():
				print release_name[i:]
				break

	print "--------------------------------------------------------------------------------"
	my_release = raw_input("Copy your Release Name exactly from the above and enter here:\n \n")
	print " "
	for item in release_paths:
		release_path = item.get_attribute("href")
		release_text = (release_path).split('Cycle')
		release_name = release_text[1]
		if my_release in release_name:
			driver.get(release_path)
			break
	time.sleep(7)
	rows = len(driver.find_elements_by_xpath("(//table[@class='testopia_Table_Data'])[1]/tbody/tr/td[@align='left']/a"))
	logging.info('Total No. of TestSuites Present in Home page : %s' %rows)
	print "--------------------------------------------------------------------------------"
	print 'Total No. of TestSuites Present in Home page : %s' %rows
	print "--------------------------------------------------------------------------------"
	print " "
	total = 0
	auto = 0
	manual = 0
	total_passed = 0
	total_failed = 0
	total_idle = 0
	total_running = 0
	total_paused = 0
	total_blocked = 0
	total_error = 0
	status = ['IDLE','PASSED','FAILED','RUNNING','PAUSED','BLOCKED','ERROR']
	for item in range(1,rows+1):
		element = driver.find_element_by_xpath("((//table[@class='testopia_Table_Data'])[1]/tbody/tr/td[@align='left']/a)[%d]" %item)
		time.sleep(7)
		elem = str(element.text)
		element.click()
		time.sleep(10)
		driver.find_element_by_id("ext-gen176").click()
		time.sleep(7)
		Run_Summary = driver.find_element_by_css_selector('#run_summary_div').text
		if "AUTO" in Run_Summary:
			test_suite_status = "AUTO"
		elif "MANUAL" in Run_Summary:
			test_suite_status = "MANUAL"
		else:
			test_suite_status = driver.find_element_by_xpath("//*[@id='category']/option").text
		check = driver.find_element_by_id("ext-comp-1021").text
		if "of" not in check:
			Run_Summary = driver.find_element_by_css_selector('#run_summary_div').text
			text = Run_Summary.split('_')
			test_cases_count = 0
			pass_count = 0
			fail_count = 0
			idle_count = 0
			running_count = 0
			paused_count = 0
			blocked_count = 0
			error_count = 0
			print "TestSuite(%s)-%s : Number of test cases-%d (%s)" %(elem,text[3],test_cases_count,test_suite_status)
			print "--------------------------------------------------------------------------------"
			print "Pass Count = ",pass_count
			print "Fail Count = ",fail_count
			print "Idle Count = ",idle_count
			print "Running Count = ",running_count
			print "Paused Count = ",paused_count
			print "Blocked Count = ",blocked_count
			print "Error Count = ",error_count
			driver.back()
			time.sleep(7)
		elif "of" in check:
			count = check.split('of')
			test_cases_count = int(count[1])
			total = total + test_cases_count
			pass_count = 0
			fail_count = 0
			idle_count = 0
			running_count = 0
			paused_count = 0
			blocked_count = 0
			error_count = 0
			module_name = driver.find_element_by_xpath("//*[@id='run_overview']/table/tbody/tr[6]/td[1]/a").text
			for x in range(1,test_cases_count+1):
				for y in status:
					if(x == '1' and y=='PASSED'):
						driver.find_element_by_xpath("//*[@id='ext-gen68']/div[%d]//table/tbody/tr[1]/td[9]/div/img[@alt='%s']" %(x,y))
						status_bar = driver.find_element_by_css_selector('#ext-gen141').text
						if (status_bar == "100%"):
							pass_count = test_cases_count
							break
						time.sleep(2)
						break
					elif (y=='IDLE'):
						try:
							driver.find_element_by_xpath("//*[@id='ext-gen68']/div[%d]//table/tbody/tr[1]/td[9]/div/img[@alt='%s']" %(x,y))
							idle_count = idle_count + 1
							break
						except Exception as e:
							continue
			
					elif (y == 'FAILED'):
						try:
							test_count = driver.find_element_by_xpath("//*[@id='ext-gen68']/div[%d]//table/tbody/tr[1]/td[9]/div/img[@alt='%s']" %(x,y))
							fail_count = fail_count + 1
							break
						except Exception as e:
							continue	
						
					elif (y == 'RUNNING'):
						try:
							test_count = driver.find_element_by_xpath("//*[@id='ext-gen68']/div[%d]//table/tbody/tr[1]/td[9]/div/img[@alt='%s']" %(x,y))	 
							running_count = running_count + 1
							break
						except Exception as e:
							continue
					elif (y == 'PAUSED'):
						try:
							test_count = driver.find_element_by_xpath("//*[@id='ext-gen68']/div[%d]//table/tbody/tr[1]/td[9]/div/img[@alt='%s']" %(x,y))
							paused_count = paused_count + 1
							break
						except Exception as e:
							continue
					elif (y == 'BLOCKED'):
						try: 	
							test_count = driver.find_element_by_xpath("//*[@id='ext-gen68']/div[%d]//table/tbody/tr[1]/td[9]/div/img[@alt='%s']" %(x,y))
							blocked_count = blocked_count + 1
							break
						except Exception as e:
							continue
					elif (y == 'ERROR'):	
						try:
							test_count = driver.find_element_by_xpath("//*[@id='ext-gen68']/div[%d]//table/tbody/tr[1]/td[9]/div/img[@alt='%s']" %(x,y)) 		
							error_count = error_count + 1
							break
						except Exception as e:
							continue
					else:
						continue
	
				pass_count = test_cases_count - (idle_count + fail_count + running_count + paused_count + blocked_count + error_count)
				logging.info("TestSuite(%s)-%s : Number of test cases-%d (%s)" %(elem,module_name,test_cases_count,test_suite_status))
			print " "
			print "TestSuite(%s)- %s : Number of test cases-%d (%s)" %(elem,module_name,test_cases_count,test_suite_status)
			print "--------------------------------------------------------------------------------"
			if test_suite_status == "AUTO":
				auto = auto + test_cases_count
				total_passed = total_passed + pass_count
				total_failed = total_failed + fail_count
				total_idle = total_idle + idle_count
				total_running = total_running + running_count
				total_paused = total_paused + paused_count
				total_blocked = total_blocked + blocked_count
				total_error = total_error + error_count
				print "Pass Count = ",pass_count
				print "Fail Count = ",fail_count
				print "Idle Count = ",idle_count
				print "Running Count = ",running_count
				print "Paused Count = ",paused_count
				print "Blocked Count = ",blocked_count
				print "Error Count = ",error_count
			elif test_suite_status == "MANUAL":
				manual = manual + test_cases_count
				total_passed = total_passed + pass_count
				total_failed = total_failed + fail_count
				total_idle = total_idle + idle_count
				total_running = total_running + running_count
				total_paused = total_paused + paused_count
				total_blocked = total_blocked + blocked_count
				total_error = total_error + error_count
				print "Pass Count = ",pass_count
				print "Fail Count = ",fail_count
				print "Idle Count = ",idle_count
				print "Running Count = ",running_count
				print "Paused Count = ",paused_count
				print "Blocked Count = ",blocked_count
				print "Error Count = ",error_count
			logging.info("Auto++ = %d \nManual++ = %d" %(auto, manual))
			print "--------------------------------------------------------------------------------"
		print "Auto++ = %d \nManual++ = %d" %(auto, manual)
		print "--------------------------------------------------------------------------------"
		driver.back()
	time.sleep(7)
	#saving the final result of the script into the excel sheet 'qa_graph.xslx' generated by the script execution in the same directory
	sheet['B1'] = auto
	sheet['B2'] = manual
	sheet['B3'] = total_passed
	sheet['B4'] = total_failed
	sheet['B5'] = total_idle
	sheet['B6'] = total_running
	sheet['B7'] = total_paused
	sheet['B8'] = total_blocked 
	sheet['B9'] = total_error
	sheet['B10'] = total
	wb.save('qa_graph.xlsx')
	logging.info("Total No. of Auto test cases is : %d \nTotal No. of Manual test cases is : %d" %(auto, manual))
	logging.info("Total No. of Passed test cases is : %d \nTotal No. of Failed test cases is : %d" %(auto, manual))
	logging.info("Total No. of Idle test cases is : %d \nTotal No. of Running test cases is : %d" %(auto, manual))
	logging.info("Total No. of Paused test cases is : %d \nTotal No. of Blocked test cases is : %d" %(auto, manual))
	logging.info("Total No. of Error test cases is : %d \nTotal No. of test cases is : %d" %(auto, manual))
	print "Total No. of Auto test cases is : %d \nTotal No. of Manual test cases is : %d" %(auto, manual)
	print "Total No. of Passed test cases is : %d \nTotal No. of Failed test cases is : %d" %(total_passed, total_failed)
	print "Total No. of Idle test cases is : %d \nTotal No. of Running test cases is : %d" %(total_idle, total_running)
	print "Total No. of Paused test cases is : %d \nTotal No. of Blocked test cases is : %d" %(total_paused, total_blocked)
	print "Total No. of Error test cases is : %d \nTotal No. of test cases is : %d" %(total_error, total)
except Exception as e:
	logging.debug("Error is : ", e)
	

finally:
	driver.quit()