def selected_given_nename(driver,nename): ne_param = find_single_widget(driver,10,(By.XPATH,"//input[@class='ebInputNe']")) if ne_param.get_attribute('value'): ne_param.click() find_single_widget(driver, 10, (By.XPATH,"//div[@id='btnAllLeft']")).click() else: ne_param.click() input_ne = find_single_widget(driver,10,(By.XPATH,"//table[@class='ebTable elWidgets-Table-body']/thead/tr[2]/th[2]/input")) input_ne.clear() input_ne.send_keys(nename) time.sleep(1) found_ne=find_single_widget(driver, 10, (By.XPATH,"//table[@class='ebTable elWidgets-Table-body']/tbody/tr")) if found_ne: ne_check_box = find_single_widget(found_ne, 10, (By.XPATH,"./td/div/div/input")) if not ne_check_box.is_selected(): ne_check_box.click() else: logCommon.error("the given nename: " + nename + " not found") right_arrow = find_single_widget(driver, 10,(By.XPATH,"//div[@id='btnRight']")) right_arrow.click() confirm_btn = find_single_widget(driver,10,(By.XPATH,"//div[@class='choose']/button")) confirm_btn.click()
def findLineOfCertainStatus(driver, status): try: WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.XPATH, "//div[@class='table']/div/div/table/tbody"))) except TimeoutException as e: logCommon.error('None unacked records in the table.') tbody = driver.find_element_by_xpath("//div[@class='table']/div/div/table/tbody") trs = WebDriverWait(tbody, 10).until(EC.presence_of_all_elements_located((By.XPATH, ".//tr"))) # trs = tbody.find_elements_by_xpath(".//tr") for tr in trs: # tds = tr.find_elements_by_xpath(".//td") tds = WebDriverWait(tr, 10).until(EC.presence_of_all_elements_located((By.XPATH, ".//td"))) if (0 == status): if ("��???" == tds[5].get_attribute("innerHTML").encode('utf-8').strip()): print "?��????" + tds[1].get_attribute("innerHTML").encode('utf-8') + " ��???" return tr elif (2 == status): if ("��???" == tds[6].get_attribute("innerHTML").encode('utf-8').strip()): # print "?��????" + tds[1].get_attribute("innerHTML").encode('utf-8') + " ��???" logCommon.info("ID: " + str(tds[1].get_attribute("innerHTML").encode('utf-8')) + " not acked") return tr elif (4 == status): if ("��???" == tds[6].get_attribute("innerHTML").encode('utf-8').strip() and "��???" == tds[5].get_attribute( "innerHTML").encode('utf-8').strip()): print "?��????" + tds[1].get_attribute("innerHTML").encode('utf-8') + " ��??????��???" return tr return False
def get_1st_row_on_gui(driver): table_i = ( By.XPATH, "//div[@class='table']/div/div/table[@class='ebTable elWidgets-Table-body']" ) table = find_single_widget(driver, 10, table_i) name_i = (By.XPATH, "./thead/tr/th") column_name = find_all_widgets(table, 10, name_i) value_i = (By.XPATH, "./tbody/tr[1]/td") find_single_widget(table, 10, value_i).click() column_value = find_all_widgets(table, 10, value_i) name_list = [] value_list = [] if (len(column_name) != len(column_value)): logCommon.error("Alarm data mismatched on gui") for name in column_name: alarm_name = name.text.encode('utf-8') name_list.append(alarm_name) del name_list[0] for value in column_value: filed_value = value.text.encode('utf-8') value_list.append(filed_value) del value_list[0] alarm_gui = dict(zip(name_list, value_list)) del alarm_gui["告警代码"] del alarm_gui["类型代码"] del alarm_gui["类型编号"] return alarm_gui
def get_1st_row_on_gui(driver): table_i = (By.XPATH,"//div[@class='table']/div/div/table[@class='ebTable elWidgets-Table-body']") table=find_single_widget(driver,10,table_i) name_i=(By.XPATH,"./thead/tr/th") column_name = find_all_widgets(table,10,name_i) value_i = (By.XPATH,"./tbody/tr[1]/td") find_single_widget(table,10,value_i).click() column_value = find_all_widgets(table,10,value_i) name_list=[] value_list=[] if(len(column_name) != len(column_value)): logCommon.error("Alarm data mismatched on gui") for name in column_name: alarm_name = name.text.encode('utf-8') name_list.append(alarm_name) del name_list[0] for value in column_value: filed_value = value.text.encode('utf-8') value_list.append(filed_value) del value_list[0] alarm_gui=dict(zip(name_list,value_list)) del alarm_gui["告警代码"] del alarm_gui["类型代码"] del alarm_gui["类型编号"] return alarm_gui
def check_pm_accurate(ne_info_cfg, counter_info_cfg, server_info_path, str_end_time, number_of_lic, check_rounds=12, me_counter_cfg=None, me_types_cfg=None): ne_info = get_ne_info_from_cfg(ne_info_cfg) counters_pm = get_pm_counters_map(counter_info_cfg) if 12 * number_of_lic != len(counters_pm): test.error('Lines of expected counters should equal 12 multiple number of LICs.') server_info = TrimableProps(server_info_path) dict_browser_chrome = { "browser_type": os.path.normpath(server_info.getProperty('browser_type')), "browser_path": os.path.normpath(server_info.getProperty('browser_path')), "driver_path": os.path.normpath(server_info.getProperty('driver_path')) } host = server_info.getProperty('host') username = server_info.getProperty('username') password = server_info.getProperty('password') port = server_info.getProperty('port') url = server_info.getProperty('url') dict_additinal = { 'number_of_lic': number_of_lic, 'check_rounds': check_rounds } driver = CommonStatic.login_rsnms(dict_browser_chrome, host, username, password, port, url) if driver: try: end_time = datetime.strptime(str_end_time, '%Y-%m-%d %H:%M:%S') rounds = len(counters_pm) / dict_additinal['number_of_lic'] start_time = end_time + timedelta(minutes=-5 * check_rounds) NeCommon.to_ne_management_page_by_url(driver, server_info) dict_ne_info = NeCommon.check_and_add_ne(driver, ne_info) PmCommon.to_pm_management_page_by_url(driver, ne_info['ne_type'], server_info) PmCommon.make_in_correct_tab(driver, ne_info['tab_pre'], '') PmCommon.wait_until_pm_date_show_up(driver, dict_ne_info['ne_name']) PmCommon.init_and_search(driver, dict_ne_info['ne_name'], end_time, start_time) PmCommon.check_pm_rows_updated(driver, dict_ne_info['ne_type'], counters_pm, 10, dict_additinal) if ne_info.has_key('tab_me') and me_counter_cfg is not None and me_types_cfg is not None: test.info('Found ME Tab information, will check ME counters.') dict_me_add = { 'rows_each_period': 1, 'check_rounds': check_rounds } me_counters = get_pm_counters_map(me_counter_cfg) me_types = get_me_types_map(me_types_cfg) if 12 * dict_me_add['rows_each_period'] != len(me_counters): test.error('Expected ME counters mis-match.') PmCommon.make_in_correct_tab(driver, ne_info['tab_me'], '') PmCommon.wait_until_pm_date_show_up(driver, dict_ne_info['ne_name']) PmCommon.init_and_search(driver, dict_ne_info['ne_name'], end_time, start_time) # PmCommon.wait_until_rounds_ok(driver, len(me_counters), 10, dict_me_add) PmCommon.check_me_counters(driver, dict_ne_info['ne_name'], me_counters, 10, dict_me_add, me_types) CommonStatic.logout_rsnms(driver) finally: CommonStatic.quite_driver(driver)
def __init__(self,alarm_mapping_cfg): if(not os.path.exists(alarm_mapping_cfg)): test.error("The alarm mapping cfg files: " + alarm_mapping_cfg + " not existed") mapping_info = Properties(alarm_mapping_cfg) self.dict_mapping_info = {} for key in mapping_info.dict_info().keys(): self.dict_mapping_info[key] = mapping_info.getProperty(key)
def execute(self, sqltext): if self.conn == None: test.error("will exit for DB connection Failure") else: cursor = self.conn.cursor() cursor.execute(sqltext) cursor.close() self.conn.commit()
def execute(self,sqltext): if self.conn == None: test.error("will exit for DB connection Failure") else: cursor = self.conn.cursor() cursor.execute(sqltext) cursor.close() self.conn.commit()
def check_notify_accuracy(ne_info_cfg,server_info_cfg,mapping_info_cfg): dict_ne_info,dict_server_info,dict_browser_chrome = data_init(ne_info_cfg,server_info_cfg) server_info = Properties(server_info_cfg) mysqlInst = PyMysql.PyMysql() driver = CommonStatic.login_rsnms(dict_browser_chrome,dict_server_info["host"],dict_server_info["username"],dict_server_info["password"],dict_server_info["port"],dict_server_info["url"]) if driver: try: NeCommon.to_ne_management_page_by_url(driver,server_info) new_ne_info=NeCommon.check_and_add_ne(driver,dict_ne_info) ne_name = new_ne_info["ne_name"] #ne_name = 'IMSHSS-9A8ACC8039B1B283' quitDriver(driver) mappingInstance = AlarmMapping.alarmMapping(mapping_info_cfg) mysqlInst.newConnection(dict_server_info["host"],'root','root','xoam') nodeid = get_nodeid_by_nename(ne_name,mysqlInst) if dict_ne_info["ne_type"] == "LTEHSS" or dict_ne_info["ne_type"] == "IMSHSS": snmp_auth_info = [] snmp_auth_info.append(dict_ne_info["usm_user"]) snmp_auth_info.append(dict_ne_info["auth_password"]) snmp_auth_info.append(dict_ne_info["priv_password"]) else: snmp_auth_info = None alarmtypes = mappingInstance.dict_mapping_info["alarm_types"] alarm_type_list = [] if type(alarmtypes) is types.StringType: alarm_type_list.append(alarmtypes) else: alarm_type_list = alarmtypes for alarm_type in alarm_type_list: test.info("send and get NBI notification for " + dict_ne_info["ne_type"] + ":" + alarm_type + "...") #alarm_raw = getNBINotification(dict_ne_info["ne_ip"], 7070, 'xoambaseserver',dict_ne_info["ne_type"],alarm_type,dict_server_info["host"],snmp_auth_info) alarm_raw = base_clint_for_selenium.send_trap_nbi(dict_ne_info["ne_ip"],7070,'xoambaseserver',dict_ne_info["ne_type"],alarm_type,dict_server_info["host"],auth_info=snmp_auth_info) error_code = int(alarm_raw["code"]) if error_code==1: alarm_trap = alarm_raw["trap"] nbi_notif = alarm_raw["nbi"] test.info("get TrapInfo is:" + str(alarm_trap) + " and NotifInfo is:" + str(nbi_notif)) test.info("start to check " + alarm_type) check_notif_items = mappingInstance.get_property("notif_attr_names") attr_list = [] if type(check_notif_items) is types.StringType: attr_list.append(check_notif_items) else: attr_list = check_notif_items check_attr_accuracy(mappingInstance,alarm_trap,nbi_notif,ne_name,nodeid,attr_list,mysqlInst) else: test.failed(dict_ne_info["ne_type"] + ":" + alarm_type + " accuracy test failed, reason:sending alarm trap failed, the error msg is:" + alarm_raw["msg"]) mysqlInst.closeConnection() except Exception as e: mysqlInst.closeConnection() test.error(e.message)
def check_and_add_ne(driver, dict_ne_info): ne_exist, ne_name = check_ne_exist(driver, dict_ne_info["ne_type"], dict_ne_info["ne_ip"]) if 2 == ne_exist: test.error("A ne with the given IP named: " + ne_name + " already exist.") sys.exit(0) elif 1 == ne_exist: dict_ne_info["ne_name"] = ne_name elif 1 > ne_exist: dict_ne_info["ne_name"] = add_new_ne(driver, dict_ne_info) refresh_ne_management_page(driver) return dict_ne_info
def check_me_single_row(driver, id_table, index_row, ne_type, dict_counters, rows_of_page, list_headers, me_types): test.info('Start to check ME row: ' + str(index_row)) make_sure_is_correct_page(driver, index_row, rows_of_page) try: gui_index_row = rows_of_page if 0 == index_row % rows_of_page else index_row % rows_of_page id_tr = (By.XPATH, ".//tbody/tr[" + str(gui_index_row) + "]") table = find_single_widget(driver, 10, id_table) time.sleep(.5) tr = find_single_widget(table, 10, id_tr) gui_str_time = find_single_widget( tr, 10, (By.XPATH, ".//td[2]")).get_attribute('innerHTML').encode('utf-8') gui_time = datetime.strptime(gui_str_time.strip(), "%Y-%m-%d %H:%M") except_counter_id = str(gui_time.minute) # id_lic_name = (By.XPATH, ".//td[3]") # lic_name = find_single_widget(tr, 5, id_lic_name).get_attribute('innerHTML').encode('utf-8') list_row = dict_counters[except_counter_id].split(',') list_types = me_types['counter_types'].split(',') for i in range(len(list_row)): try: id_counter = (By.XPATH, ".//td[" + str(i + 3) + "]") gui_counter = find_single_widget( tr, 5, id_counter).get_attribute('innerHTML').encode('utf-8') # i_gui_counter = int(gui_counter) if 'int' == list_types[i].lower().strip() if 'int' == list_types[i].lower().strip(): i_gui_counter = int(gui_counter) i_expected = int(list_row[i].strip()) elif 'float' == list_types[i].lower().strip(): i_gui_counter = float(gui_counter) i_expected = float(list_row[i].strip()) else: test.error('Unknown counter type of me counters.') except Exception as e: i_gui_counter = None if i_expected == i_gui_counter: msg = list_headers[1] + ": " + gui_str_time.strip() + ",\t" + "; " + list_headers[i + 2] + ", GUI is " \ + str(i_gui_counter) + ",\tExpected is " + str(list_row[i]) + "." test.passed(msg) else: msg = list_headers[1] + ": " + gui_str_time.strip() + ",\t" + "; " + list_headers[i + 2] + ", GUI is " \ + str(i_gui_counter) + ",\tExpected is " + str(list_row[i]) + "." test.failed(msg) return gui_time except Exception as e: test.error("Test failed, ERROR: " + str(e))
def wait_until_pm_date_show_up(driver, ne_name, wait_time=720): select_given_ne_name(driver, ne_name) end_time = datetime.now() + timedelta(seconds=wait_time) while datetime.now() < end_time: id_query_btn = (By.ID, "idBtn-search") find_single_widget(driver, 10, id_query_btn).click() id_body_date = (By.XPATH, "//div[@class='ebTabs']/div[2]/div/div/div/div/table/tbody") try: find_single_widget(driver, 10, id_body_date) test.passed('Successfully found the PM datas.') return except TimeoutException: pass test.error('Wait for ' + str(wait_time) + ' seconds but cannot find any PM datas.')
def query(self, sqltext, mode="one"): if self.conn == None: test.error("will exit for DB connection Failure") else: cursor = self.conn.cursor() cursor.execute(sqltext) if mode == "one": result = cursor.fetchone() elif mode == "all": result = cursor.fetchall() else: test.error("query mode error") cursor.close() return (cursor.rowcount, result)
def query(self,sqltext,mode="one"): if self.conn == None: test.error("will exit for DB connection Failure") else: cursor = self.conn.cursor() cursor.execute(sqltext) if mode=="one": result = cursor.fetchone() elif mode == "all": result = cursor.fetchall() else: test.error("query mode error") cursor.close() return (cursor.rowcount,result)
def make_sure_in_pm_page(driver): # btn id: ebBtnSearch id_btn_interface = (By.ID, 'ebBtnSearch') try: find_single_widget(driver, 5, id_btn_interface) test.error('Page redirect to the interface management page, critical error!') except TimeoutException: id_query_btn = (By.ID, "idBtn-search") try: pm_query_btn = find_single_widget(driver, 10, id_query_btn) if pm_query_btn: test.passed('Found the query button of PM Management page, check passed.') except TimeoutException: test.failed('Cannot find the query button of PM Management page.')
def check_and_add_ne(driver, dict_ne_info): ne_exist, ne_name = check_ne_exist_by_type(driver, dict_ne_info["ne_type"], dict_ne_info["ne_ip"]) if 2 == ne_exist: test.error('A ne with the given IP named: ' + ne_name + ' already exist.') FmCommon.quitDriver(driver) sys.exit(0) elif 1 == ne_exist: dict_ne_info["ne_name"] = ne_name elif 1 > ne_exist: ne_name = add_new_ne(driver, dict_ne_info) dict_ne_info["ne_name"] = ne_name refresh_ne_management_page(driver) test.info("NE:" + ne_name + " added successfully") return dict_ne_info
def login_first_page(driver, host, username, password, port, url): index = 'http://' + str(host) + ':' + str(port) + url test.info('Web page: ' + str(index)) driver.get(index) driver.find_element_by_id('loginUsername').clear() driver.find_element_by_id('loginUsername').send_keys(username) driver.find_element_by_id('loginPassword').clear() driver.find_element_by_id('loginPassword').send_keys(password) driver.find_element_by_id('submit').click() try: WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "ebBtnSearch"))) test.info('Login to the InterfaceManagement page successfully.') except Exception as e: test.error('Login to the InterfaceManagement page failed. ERROR: ' + str(e)) return None
def check_pm_by_row(driver, id_table, index_row, ne_type, dict_counters, rows_of_page, list_headers, is_m_lics): test.info('Start to check row: ' + str(index_row)) make_sure_is_correct_page(driver, index_row, rows_of_page) try: gui_index_row = rows_of_page if 0 == index_row % rows_of_page else index_row % rows_of_page id_tr = (By.XPATH, ".//tbody/tr[" + str(gui_index_row) + "]") table = find_single_widget(driver, 10, id_table) time.sleep(.5) tr = find_single_widget(table, 10, id_tr) gui_str_time = find_single_widget( tr, 10, (By.XPATH, ".//td[2]")).get_attribute('innerHTML').encode('utf-8') gui_time = datetime.strptime(gui_str_time.strip(), "%Y-%m-%d %H:%M") except_counter_id = str(gui_time.minute) id_lic_name = (By.XPATH, ".//td[3]") lic_name = find_single_widget( tr, 5, id_lic_name).get_attribute('innerHTML').encode('utf-8') if is_m_lics: except_counter_id = str(gui_time.minute) + '-' + lic_name list_row = dict_counters[except_counter_id].split(',') for i in range(len(list_row)): try: id_counter = (By.XPATH, ".//td[" + str(i + 4) + "]") gui_counter = find_single_widget( tr, 5, id_counter).get_attribute('innerHTML').encode('utf-8') i_gui_counter = int(gui_counter) except Exception as e: i_gui_counter = None if int(list_row[i].strip()) == i_gui_counter: msg = list_headers[1] + ": " + gui_str_time.strip() + ",\t" + list_headers[2] + ": " + lic_name + "; " \ + list_headers[i + 3] + ", GUI is " + str(i_gui_counter) + ",\tExpected is " + str(list_row[i]) \ + "." test.passed(msg) else: msg = list_headers[1] + ": " + gui_str_time.strip() + ",\t" + list_headers[2] + ": " + lic_name + "; " \ + list_headers[i + 3] + ", GUI is " + str(i_gui_counter) + ",\tExpected is " + str(list_row[i]) \ + "." test.failed(msg) return [gui_time, lic_name] except Exception as e: test.error("Test failed, ERROR: " + str(e))
def wait_until_pm_date_show_up(driver, ne_name, wait_time=720): select_given_ne_name(driver, ne_name) end_time = datetime.now() + timedelta(seconds=wait_time) while datetime.now() < end_time: id_query_btn = (By.ID, "idBtn-search") find_single_widget(driver, 10, id_query_btn).click() id_body_date = ( By.XPATH, "//div[@class='ebTabs']/div[2]/div/div/div/div/table/tbody") try: find_single_widget(driver, 10, id_body_date) test.passed('Successfully found the counters data.') return except TimeoutException: pass test.error('Wait for ' + str(wait_time) + ' seconds but cannot find any PM datas.')
def login_first_page(driver, host, username, password, port, url): index = 'http://' + str(host) + ':' + str(port) + url test.info('Web page: ' + str(index)) driver.get(index) driver.find_element_by_id('loginUsername').clear() driver.find_element_by_id('loginUsername').send_keys(username) driver.find_element_by_id('loginPassword').clear() driver.find_element_by_id('loginPassword').send_keys(password) driver.find_element_by_id('submit').click() try: WebDriverWait(driver, 20).until( EC.element_to_be_clickable((By.ID, "ebBtnSearch"))) test.info('Login to the InterfaceManagement page successfully.') except Exception as e: test.error('Login to the InterfaceManagement page failed. ERROR: ' + str(e)) return None
def make_sure_in_pm_page(driver): # btn id: ebBtnSearch id_btn_interface = (By.ID, 'ebBtnSearch') try: find_single_widget(driver, 5, id_btn_interface) test.error( 'Page redirect to the interface management page, critical error!') except TimeoutException: id_query_btn = (By.ID, "idBtn-search") try: pm_query_btn = find_single_widget(driver, 10, id_query_btn) if pm_query_btn: test.passed( 'Found the query button of PM Management page, check passed.' ) except TimeoutException: test.failed('Cannot find the query button of PM Management page.')
def check_pm_by_row(driver, id_table, index_row, ne_type, dict_counters, rows_of_page, list_headers, is_m_lics): test.info('Start to check row: ' + str(index_row)) make_sure_is_correct_page(driver, index_row, rows_of_page) try: gui_index_row = rows_of_page if 0 == index_row % rows_of_page else index_row % rows_of_page id_tr = (By.XPATH, ".//tbody/tr[" + str(gui_index_row) + "]") table = find_single_widget(driver, 10, id_table) time.sleep(.5) tr = find_single_widget(table, 10, id_tr) gui_str_time = find_single_widget(tr, 10, (By.XPATH, ".//td[2]")).get_attribute('innerHTML').encode('utf-8') gui_time = datetime.strptime(gui_str_time.strip(), "%Y-%m-%d %H:%M") except_counter_id = str(gui_time.minute) id_lic_name = (By.XPATH, ".//td[3]") lic_name = find_single_widget(tr, 5, id_lic_name).get_attribute('innerHTML').encode('utf-8') if is_m_lics: except_counter_id = str(gui_time.minute) + '-' + lic_name list_row = dict_counters[except_counter_id].split(',') for i in range(len(list_row)): try: id_counter = (By.XPATH, ".//td[" + str(i + 4) + "]") gui_counter = find_single_widget(tr, 5, id_counter).get_attribute('innerHTML').encode('utf-8') i_gui_counter = int(gui_counter) except Exception as e: i_gui_counter = None if int(list_row[i].strip()) == i_gui_counter: msg = list_headers[1] + ": " + gui_str_time.strip() + ",\t" + list_headers[2] + ": " + lic_name + "; " \ + list_headers[i + 3] + ", GUI is " + str(i_gui_counter) + ",\tExpected is " + str(list_row[i]) \ + "." test.passed(msg) else: msg = list_headers[1] + ": " + gui_str_time.strip() + ",\t" + list_headers[2] + ": " + lic_name + "; " \ + list_headers[i + 3] + ", GUI is " + str(i_gui_counter) + ",\tExpected is " + str(list_row[i]) \ + "." test.failed(msg) return [gui_time, lic_name] except Exception as e: test.error("Test failed, ERROR: " + str(e))
def checkAcked(tr, dt, driver, filePath): time.sleep(5) # tds = tr.find_elements_by_xpath(".//td") tds = WebDriverWait(tr, 10).until(EC.presence_of_all_elements_located((By.XPATH, ".//td"))) # tds[5].get_attribute("innerHTML").encode('utf-8').strip() if ("?????" == tds[6].get_attribute("innerHTML").encode('utf-8').strip()): logCommon.info('Success: ACK the alarm successfully, ID: ' + tds[1].get_attribute("innerHTML").encode( 'utf-8') + ', ACK time: ' + tds[12].get_attribute("innerHTML").encode('utf-8')) else: logCommon.error('Failed: ACK the alarm failed.') '''logCommon.info(filePath + 'acked_0.png') if(os.path.isfile(filePath + 'acked_0.png')): os.remove(filePath + 'acked_0.png') driver.save_screenshot(filePath + 'acked_0.png')''' snap_1 = os.path.normpath(filePath + os.path.sep + 'acked_1.png') driver.execute_script("arguments[0].scrollIntoView(true);", tds[12]) if (os.path.isfile(snap_1)): os.remove(snap_1) driver.save_screenshot(snap_1)
def check_pm_accurate(ne_info_cfg, counter_info_cfg, server_info_path, str_end_time): ne_info = get_ne_info_from_cfg(ne_info_cfg) counters_pm = get_pm_counters_map(counter_info_cfg) server_info = Properties(server_info_path) dict_browser_chrome = { "browser_type": server_info.getProperty('browser_type'), "browser_path": server_info.getProperty('browser_path'), "driver_path": server_info.getProperty('driver_path') } host = server_info.getProperty('host') username = server_info.getProperty('username') password = server_info.getProperty('password') port = server_info.getProperty('port') url = server_info.getProperty('url') dict_additinal = { 'number_of_lic': 4 } driver = CommonStatic.login_rsnms(dict_browser_chrome, host, username, password, port, url) if driver: try: NeCommon.to_ne_management_page_by_url(driver, server_info) dict_ne_info = NeCommon.check_and_add_ne(driver, ne_info) PmCommon.to_pm_management_page_by_url(driver, ne_info['ne_type'], server_info) PmCommon.make_in_correct_tab(driver, ne_info['tab_pre'], '') PmCommon.wait_until_pm_date_show_up(driver, dict_ne_info['ne_name']) end_time = datetime.strptime(str_end_time, '%Y-%m-%d %H:%M:%S') if 0 != len(counters_pm) % dict_additinal['number_of_lic']: test.error('Expected couters config file mismatch with the lic number.') else: start_time = end_time + timedelta(minutes=-5 * len(counters_pm) / dict_additinal['number_of_lic']) PmCommon.init_and_search(driver, dict_ne_info['ne_name'], end_time, start_time) PmCommon.wait_until_rounds_ok(driver, len(counters_pm), 10, dict_additinal) PmCommon.check_pm_rows_updated(driver, dict_ne_info['ne_type'], counters_pm, 10, dict_additinal) CommonStatic.logout_rsnms(driver) finally: CommonStatic.quite_driver(driver)
def wait_until_rounds_ok(driver, rows, rows_of_page, dict_additional): ''' This function will check the number of rows that we need to check the PM. :param driver: :param rows: :param rows_of_page: :param dict_additional: :param ne_type: :return: None ''' id_tbdoy_trs = (By.XPATH, "//div[@class='ebTabs']/div[2]/div/div/div/div/table/tbody/tr") if dict_additional.has_key('check_rows'): rows = dict_additional['check_rows'] if not 0 == rows % dict_additional['number_of_lic']: test.error('Number of checked rows should be integer multiples of number of LICs.') t_start = datetime.now() # Note that most of the PM need T2-T1, for Node like SBC, we may wait 5 minutes more since SBC don't need T2-T1 t_end = t_start + timedelta(minutes=5 * (rows // dict_additional['number_of_lic'] + 1) + 2) while datetime.now() < t_end: # click the query button id_query_btn = (By.ID, "idBtn-search") find_single_widget(driver, 10, id_query_btn).click() time.sleep(.2) try: i_page = rows / rows_of_page tgt_page_number = i_page if 0 == rows % rows_of_page else i_page + 1 id_tgt_pager = (By.XPATH, ("//div[@class='page']/ul/li[2]/ul/li[" + str(tgt_page_number) + "]")) tgt_pager = find_single_widget(driver, 10, id_tgt_pager) if not tgt_pager.get_attribute('class').find('ebPagination-entryAnchor_current') > -1: tgt_pager.click() trs = find_all_widgets(driver, 20, id_tbdoy_trs) if rows % rows_of_page <= len(trs): test.passed('All the data that we need are ready now.') return except TimeoutException: pass time.sleep(.5) test.failed('It seems that the the data we need has not been collected as expectes, case may fail later steps.')
def findLineOfCertainStatus(driver, status): try: WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.XPATH, "//div[@class='table']/div/div/table/tbody"))) except TimeoutException as e: logCommon.error('None unacked records in the table.') tbody = driver.find_element_by_xpath( "//div[@class='table']/div/div/table/tbody") trs = WebDriverWait(tbody, 10).until( EC.presence_of_all_elements_located((By.XPATH, ".//tr"))) # trs = tbody.find_elements_by_xpath(".//tr") for tr in trs: # tds = tr.find_elements_by_xpath(".//td") tds = WebDriverWait(tr, 10).until( EC.presence_of_all_elements_located((By.XPATH, ".//td"))) if (0 == status): if ("��???" == tds[5].get_attribute("innerHTML").encode( 'utf-8').strip()): print "?��????" + tds[1].get_attribute("innerHTML").encode( 'utf-8') + " ��???" return tr elif (2 == status): if ("��???" == tds[6].get_attribute("innerHTML").encode( 'utf-8').strip()): # print "?��????" + tds[1].get_attribute("innerHTML").encode('utf-8') + " ��???" logCommon.info( "ID: " + str(tds[1].get_attribute("innerHTML").encode('utf-8')) + " not acked") return tr elif (4 == status): if ("��???" == tds[6].get_attribute("innerHTML").encode( 'utf-8').strip() and "��???" == tds[5].get_attribute( "innerHTML").encode('utf-8').strip()): print "?��????" + tds[1].get_attribute("innerHTML").encode( 'utf-8') + " ��??????��???" return tr return False
def check_sbc_pm(ne_info_cfg, counter_info_cfg, server_info_path, number_of_lic, check_rounds=4, me_counter_cfg=None): ne_info = get_ne_info_from_cfg(ne_info_cfg) counters_pm = get_pm_counters_map(counter_info_cfg) server_info = TrimableProps(server_info_path) dict_browser_chrome = { "browser_type": server_info.getProperty('browser_type'), "browser_path": server_info.getProperty('browser_path'), "driver_path": server_info.getProperty('driver_path') } host = server_info.getProperty('host') username = server_info.getProperty('username') password = server_info.getProperty('password') port = server_info.getProperty('port') url = server_info.getProperty('url') dict_additinal = { 'number_of_lic': number_of_lic, 'check_rounds': check_rounds } driver = CommonStatic.login_rsnms(dict_browser_chrome, host, username, password, port, url) if driver: try: NeCommon.to_ne_management_page_by_url(driver, server_info) dict_ne_info = NeCommon.check_and_add_ne(driver, ne_info) PmCommon.to_pm_management_page_by_url(driver, ne_info['ne_type'], server_info) PmCommon.make_in_correct_tab(driver, ne_info['tab_pre'], '') PmCommon.wait_until_pm_date_show_up(driver, dict_ne_info['ne_name']) if 12 * dict_additinal['number_of_lic'] != len(counters_pm): test.error('Expected counters file error.') PmCommon.init_and_search(driver, dict_ne_info['ne_name']) # PmCommon.wait_until_rounds_ok(driver, len(counters_pm), 10, dict_additinal) PmCommon.check_pm_rows_updated(driver, dict_ne_info['ne_type'], counters_pm, 10, dict_additinal) CommonStatic.logout_rsnms(driver) finally: CommonStatic.quite_driver(driver)
def checkAcked(tr, dt, driver, filePath): time.sleep(5) # tds = tr.find_elements_by_xpath(".//td") tds = WebDriverWait(tr, 10).until( EC.presence_of_all_elements_located((By.XPATH, ".//td"))) # tds[5].get_attribute("innerHTML").encode('utf-8').strip() if ("?????" == tds[6].get_attribute("innerHTML").encode('utf-8').strip()): logCommon.info('Success: ACK the alarm successfully, ID: ' + tds[1].get_attribute("innerHTML").encode('utf-8') + ', ACK time: ' + tds[12].get_attribute("innerHTML").encode('utf-8')) else: logCommon.error('Failed: ACK the alarm failed.') '''logCommon.info(filePath + 'acked_0.png') if(os.path.isfile(filePath + 'acked_0.png')): os.remove(filePath + 'acked_0.png') driver.save_screenshot(filePath + 'acked_0.png')''' snap_1 = os.path.normpath(filePath + os.path.sep + 'acked_1.png') driver.execute_script("arguments[0].scrollIntoView(true);", tds[12]) if (os.path.isfile(snap_1)): os.remove(snap_1) driver.save_screenshot(snap_1)
def selected_given_nename(driver, nename): ne_param = find_single_widget(driver, 10, (By.XPATH, "//input[@class='ebInputNe']")) if ne_param.get_attribute('value'): ne_param.click() find_single_widget(driver, 10, (By.XPATH, "//div[@id='btnAllLeft']")).click() else: ne_param.click() input_ne = find_single_widget(driver, 10, ( By.XPATH, "//table[@class='ebTable elWidgets-Table-body']/thead/tr[2]/th[2]/input" )) input_ne.clear() input_ne.send_keys(nename) time.sleep(1) found_ne = find_single_widget( driver, 10, (By.XPATH, "//table[@class='ebTable elWidgets-Table-body']/tbody/tr")) if found_ne: ne_check_box = find_single_widget(found_ne, 10, (By.XPATH, "./td/div/div/input")) if not ne_check_box.is_selected(): ne_check_box.click() else: logCommon.error("the given nename: " + nename + " not found") right_arrow = find_single_widget(driver, 10, (By.XPATH, "//div[@id='btnRight']")) right_arrow.click() confirm_btn = find_single_widget( driver, 10, (By.XPATH, "//div[@class='choose']/button")) confirm_btn.click()
def __init__(self,mapping_cfg): if not os.path.exists(mapping_cfg): test.error("the mapping.cfg:" + mapping_cfg + " not exist") self.tree = ET.parse(mapping_cfg)
def check_alarm_data_accuracy(ne_info_cfg,server_info_cfg,alarm_mapping_cfg): server_info = Properties(server_info_cfg) dict_browser_chrome = { "browser_type": server_info.getProperty('browser_type'), "browser_path": server_info.getProperty('browser_path'), "driver_path": server_info.getProperty('driver_path') } ne_info = Properties(ne_info_cfg) dict_ne_info = { "ne_name": ne_info.getProperty("ne_name"), "ne_user": ne_info.getProperty("ne_user"), "ne_type": ne_info.getProperty("ne_type"), "ne_ip" : ne_info.getProperty("ne_ip"), "ne_password" : ne_info.getProperty("ne_password"), "pm_path": ne_info.getProperty("pm_path"), "log_path": ne_info.getProperty("log_path"), "alarm_path": ne_info.getProperty("alarm_path"), "ne_port": ne_info.getProperty("ne_port"), "sftp_port": ne_info.getProperty("sftp_port"), "snmp_port": ne_info.getProperty("snmp_port"), "usm_user": ne_info.getProperty("usm_user"), "auth_password": ne_info.getProperty("auth_password"), "priv_password": ne_info.getProperty("priv_password"), "app_user": ne_info.getProperty("app_user"), "app_password": ne_info.getProperty("app_password"), "li_pwd": ne_info.getProperty("li_pwd"), "fro_id": ne_info.getProperty("fro_id") } mappingInstance = AlarmMapping.alarmMapping(alarm_mapping_cfg) host = server_info.getProperty("host") username = server_info.getProperty("username") password = server_info.getProperty("password") port = server_info.getProperty("port") url = server_info.getProperty("url") driver = CommonStatic.login_rsnms(dict_browser_chrome,host,username,password,port,url) if driver: try: NeCommon.to_ne_management_page_by_url(driver,server_info) new_ne_info=NeCommon.check_and_add_ne(driver, dict_ne_info) ne_name = new_ne_info["ne_name"] FmCommon.toAlarmManagement_by_url(driver,server_info) time.sleep(10) FmCommon.init_and_search(driver,ne_name) alarmtypes = mappingInstance.dict_mapping_info["alarm_types"] alarm_type_list = [] if type(alarmtypes) is types.StringType: alarm_type_list.append(alarmtypes) else: alarm_type_list = alarmtypes if dict_ne_info["ne_type"] == "LTEHSS" or dict_ne_info["ne_type"] == "IMSHSS": snmp_auth_info = [] snmp_auth_info.append(dict_ne_info["usm_user"]) snmp_auth_info.append(dict_ne_info["auth_password"]) snmp_auth_info.append(dict_ne_info["priv_password"]) else: snmp_auth_info = None for alarm_type in alarm_type_list: test_logger.info("send alarm trap: " + dict_ne_info["ne_type"] + ":" + alarm_type + "...") alarm_from_ne = base_clint_for_selenium.send_trap(dict_ne_info["ne_ip"], 7070, 'xoambaseserver',dict_ne_info["ne_type"],alarm_type,host,snmp_auth_info) error_code = int(alarm_from_ne["code"]) if error_code==1: alarm_trap=alarm_from_ne["trap"] test_logger.info("alarm sent successfully" + str(alarm_trap)) alarm_expected=alarm_converter(dict_ne_info["ne_type"],ne_name,alarm_type,alarm_trap,mappingInstance) alarm_on_gui=FmCommon.fetch_alarm_on_gui(driver,dict_ne_info["ne_type"],alarm_trap,mappingInstance,alarm_type) if alarm_on_gui != None: test_logger.info("start to check alarm type: " + dict_ne_info["ne_type"] + ":" + alarm_type) alarm_compare(alarm_expected,alarm_on_gui) else: test_logger.failed(dict_ne_info["ne_type"] + ":" + alarm_type + " accuracy test failed," + "reason:alarm not received on GUI") elif error_code < 0: test_logger.failed(dict_ne_info["ne_type"] + ":" + alarm_type + " accuracy test failed, reason:sending alarm trap failed, the error msg is:" + alarm_from_ne["msg"]) FmCommon.quitDriver(driver) except Exception as e: FmCommon.quitDriver(driver) test_logger.error(str(e))
def check_pm_rows_updated(driver, ne_type, dict_counters, rows_of_page, dict_additional): ''' The main function that check the PM Data accurate, it will first check the data of each row, then check the GUI time's minutes is multiple of 5, then check the Lics if the node has many LICs. :param ne_type: the ne's type :param dict_counters: the base counter values in dictionary :param rows_of_page: how many rows each page has on the GUI, default is 10 :param dict_additional: additional information that used for special nodes, (number_of_lic: how many lics of a no de), (check_rows: how many rows that will be checked, if this value exist, will only check this number of rows, otherwise the number of rows will checked is equal the size of dict_counters) :return: None ''' is_m_lics = True if dict_additional['number_of_lic'] > 1 else False list_returns = [] id_table = (By.XPATH, "//div[@class='ebTabs']/div[2]/div/div/div/div/table") id_header_trs = (By.XPATH, "//div[@class='ebTabs']/div[2]/div/div/div/div/table/thead/tr/th") ths = find_all_widgets(driver, 20, id_header_trs) list_headers = [] for th in ths: list_headers.append(th.get_attribute('innerHTML').encode('utf-8').strip()) number_of_rows_be_checked = len(dict_counters) if dict_additional.has_key('check_rounds'): number_of_rows_be_checked = dict_additional['check_rounds'] if not 0 == number_of_rows_be_checked % dict_additional['number_of_lic']: test.error('Number of checked rows should be integer multiples of number of LICs.') for row_index in range(1, number_of_rows_be_checked + 1): # check_pm_by_row returns [gui_datettime, lic_name] in List list_returns.append(check_pm_by_row(driver, id_table, row_index, ne_type, dict_counters, rows_of_page, list_headers, is_m_lics)) # check GUI time and lic_name lic_from_gui = [] if number_of_rows_be_checked != len(list_returns): test.failed('Number of rows need to be checked mis-match with the number we expected.') else: number_of_lic = dict_additional['number_of_lic'] for i in range(0, len(list_returns), number_of_lic): for j in range(number_of_lic): lic_from_gui.append(list_returns[i + j][1]) gui_time_and_lic_name = list_returns[i + j] if gui_time_and_lic_name[0] is not None and 0 == gui_time_and_lic_name[0].minute % 5: test.passed('Row ' + str(i + j) + ' GUI time is correct, is: ' + gui_time_and_lic_name[0].strftime('%Y-%m-%d %H:%M')) else: test.failed('Row ' + str(i + j) + ' GUI time is not multiple of 5, is: ' + gui_time_and_lic_name[0].strftime('%Y-%m-%d %H:%M')) if is_m_lics: msg = 'Node has more than one LIC, ' if list_returns[i][0] == list_returns[i + j][0]: msg += ' different LICs have the same report time.' test.passed(msg) else: msg += ' different LICs don\'t have the same report time.' test.failed(msg) if i + number_of_lic < len(list_returns): # the pre-condition of this check point is: GUI list data decent by datetime if 300 == (list_returns[i][0] - list_returns[i + number_of_lic][0]).seconds: test.passed('Report delta time is 5 minutes.') else: test.failed('Report delta time is not 5 minutes.') # if checked 1 hour PM and node has many LICs, will check the LIC if 12 == int(number_of_rows_be_checked / dict_additional['number_of_lic']): if is_m_lics: expected_lic = [t.split('-', 1)[1].strip() for t in sorted(dict_counters)] if compare_lists(expected_lic, lic_from_gui): test.passed('Lic check passed.') else: test.failed('Lic check failed, E: ' + str(expected_lic) + ', G: ' + str(lic_from_gui))
def __init__(self, mapping_cfg): if not os.path.exists(mapping_cfg): test.error("the mapping.cfg:" + mapping_cfg + " not exist") self.tree = ET.parse(mapping_cfg)