#!/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()