def fetch_alarm_on_gui(driver, ne_type, alarm_trap, mappingInstance, alarm_type): nowtime = pydate.datetime.now() endtime = nowtime + pydate.timedelta(seconds=30) id_button = (By.XPATH, "//button[@id='idBtn-search']") search_button = find_single_widget(driver, 10, id_button) while (pydate.datetime.now() < endtime): search_button.click() try: alarm_data = get_1st_row_on_gui(driver) except TimeoutException: time.sleep(5) continue if ne_type == 'OCGAS': specific_problem = mappingInstance.get_property( "specific_problem")[alarm_type] else: specific_problem = alarm_trap["specificProblem"] if (specific_problem == alarm_data["问题描述"]): logCommon.info("alarm received on GUI:" + alarm_type) return alarm_data else: time.sleep(10) return None
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 init_and_search(driver, ne_name, end_time=None, start_time=None): # select the given nename select_given_ne_name(driver, ne_name) # select the correct time if end_time is not None: test.info('Query end time point set to: ' + end_time.strftime('%H%M%S')) id_end_time = (By.XPATH, "//div[@class='endtime']/div/span/input") find_single_widget(driver, 10, id_end_time).click() set_time_for_query(driver, end_time) if start_time is not None: test.info('Query start time point set to: ' + start_time.strftime('%H%M%S')) id_start_time = (By.XPATH, "//div[@class='starttime']/div/span/input") find_single_widget(driver, 10, id_start_time).click() set_time_for_query(driver, start_time) # click the query button id_query_btn = (By.ID, "idBtn-search") find_single_widget(driver, 10, id_query_btn).click() # wait for the notification, maximum 20 seconds id_body_date = ( By.XPATH, "//div[@class='ebTabs']/div[2]/div/div/div/div/table/tbody") find_single_widget(driver, 20, id_body_date)
def findBtnReturnComfirmBtn(driver, btnClick): if (0 == btnClick): # btnClickEle = driver.find_element_by_id("idBtn-search") btnClickEle = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "idBtn-search"))) return btnClickEle elif (1 == btnClick): # btnClickEle = driver.find_element_by_id("idBtn-ack") logCommon.info('Click ACK button') btnClickEle = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "idBtn-ack"))) btnClickEle.click() # ebDialogBox-actionBlock btn = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.XPATH, "//div[@class='ebDialogBox-actionBlock']/button[1]"))) logCommon.info('Found the confirm button and will click next.') return btn elif (2 == btnClick): # btnClickEle = driver.find_element_by_id("idBtn-clear") btnClickEle = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "idBtn-clear"))) btnClickEle.click() # ebDialogBox-actionBlock btn = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.XPATH, "//div[@class='ebDialogBox-actionBlock']/button[1]"))) return btn elif (3 == btnClick): # idBtn-manual # btnClickEle = driver.find_element_by_id("idBtn-manual") btnClickEle = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "idBtn-manual"))) btnClickEle.click() # ebDialogBox-actionBlock btn = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.XPATH, "//div[@class='ebDialogBox-actionBlock']/button[1]"))) return btn
def login_rsnms(dict_browser, host, username='******', password='******', port=8686, url='/XOAM/login/index.html'): """ The function mainly init the browser driver, return the instance of the selenium driver. :param password: the password of the RSNMS system. :param username: the username of the RSNMS system. :param dict_browser: A Dict that contains the browser information, type, path, driver_path. :param host: The host of the URL that try to open. :param port: The port number of the URL that try to open. :return: return the selenium driver instance so that can used in followed test steps. """ test.info('Will start the web browser and perform test case.') # first edition only support the chrome on windows platform if 'Windows' == osutils.get_os_type(): if 'chrome' == dict_browser['browser_type']: return windows_chrome_login_rsnms(dict_browser['browser_path'], dict_browser['driver_path'], host, username, password, port, url) elif 'firefox' == dict_browser['browser_type']: return windows_firefox_login_rsnms(dict_browser['browser_path'], dict_browser['driver_path'], host, username, password, port, url)
def wait_noti_widget_show(driver, wait_time=10): id_div = (By.XPATH, "//div[@class='noti']/div") try: find_single_widget(driver, wait_time, id_div) test.info('Query result notification shown up.') except TimeoutException: test.warning('Query result notification did not shown up, case may or may not fail later.')
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 check_common_accuracy(attr_name,dict_nbi_notif,expected_value): notif_value = {} if dict_nbi_notif.has_key(attr_name): notif_value[attr_name] = dict_nbi_notif[attr_name] test.info("check '" + attr_name + "',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value, expected_value) else: test.failed("get '" + attr_name + "' from nbi notification Failed")
def init_and_search(driver,nename): logCommon.info("Query alarm for NE: " + nename + "...") selected_given_nename(driver,nename) search_btn = find_single_widget(driver, 10, (By.XPATH,"//button[@id='idBtn-search']")) search_btn.click() tips = find_single_widget(driver,10,(By.XPATH,"//div[@class='tip']")).get_attribute('innerHTML').encode('utf-8') if tips: logCommon.info("Alarm queried successfully")
def windows_firefox_login_rsnms(browser_path, driver_path, host, username, password, port, url): browser_path = os.path.normpath(browser_path) test.info('Browser path: ' + str(browser_path)) firfox_bin = webdriver.firefox.firefox_binary.FirefoxBinary(browser_path) driver = webdriver.Firefox(firefox_binary=firfox_bin) driver.maximize_window() login_first_page(driver, host, username, password, port) return driver
def toAlarmManagement(driver): logCommon.info('To the AlarmManagement page...') # driver.find_element_by_xpath("//span[@class='ebBreadcrumbs-arrow']").click() WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.XPATH, "//span[@class='ebBreadcrumbs-arrow']"))).click() WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.XPATH, "//div[@class='ebBreadcrumbs-list']/ul/li[4]/a"))).click() time.sleep(10)
def wait_noti_widget_show(driver, wait_time=10): id_div = (By.XPATH, "//div[@class='noti']/div") try: find_single_widget(driver, wait_time, id_div) test.info('Query result notification shown up.') except TimeoutException: test.warning( 'Query result notification did not shown up, case may or may not fail later.' )
def get_element_hierachy(self,attr_name): dict = {} node = self.tree.find(attr_name) if node != None: c_dict = self.get_children_element(node,{},[],[]) dict[attr_name] = c_dict else: test.info("the attribute:" + attr_name + " can't be found in mapping.cfg") return dict
def make_in_correct_tab(driver, prefix, postfix): id_tabs = (By.XPATH, "//div[@class='ebTabs']/div[1]/div[2]/div") tabs = find_all_widgets(driver, 10, id_tabs) for tab in tabs: if prefix + postfix == tab.get_attribute('innerHTML').encode('utf-8').strip(): if not tab.get_attribute('class').encode('utf-8').find('ebTabs-tabItem_selected_true') > -1: tab.click() wait_noti_widget_show(driver) test.info('Switch to the TAB: ' + prefix + postfix)
def get_element_hierachy(self, attr_name): dict = {} node = self.tree.find(attr_name) if node != None: c_dict = self.get_children_element(node, {}, [], []) dict[attr_name] = c_dict else: test.info("the attribute:" + attr_name + " can't be found in mapping.cfg") return dict
def to_ne_management_page_by_url(driver, server_info, url_add="#network-overview/ne-management"): test.info("Will Navigate to the NeManagement page...") base_url = ( "http://" + server_info.getProperty("host") + ":" + str(server_info.getProperty("port")) + server_info.getProperty("preurl") ) test.info("Base URL is: " + base_url) driver.get(base_url + url_add)
def make_in_correct_tab(driver, prefix, postfix): id_tabs = (By.XPATH, "//div[@class='ebTabs']/div[1]/div[2]/div") tabs = find_all_widgets(driver, 10, id_tabs) for tab in tabs: if prefix + postfix == tab.get_attribute('innerHTML').encode( 'utf-8').strip(): if not tab.get_attribute('class').encode('utf-8').find( 'ebTabs-tabItem_selected_true') > -1: tab.click() wait_noti_widget_show(driver) test.info('Now in TAB: ' + prefix + postfix)
def init_and_search(driver, nename): logCommon.info("Query alarm for NE: " + nename + "...") selected_given_nename(driver, nename) search_btn = find_single_widget(driver, 10, (By.XPATH, "//button[@id='idBtn-search']")) search_btn.click() tips = find_single_widget( driver, 10, (By.XPATH, "//div[@class='tip']")).get_attribute('innerHTML').encode('utf-8') if tips: logCommon.info("Alarm queried successfully")
def toAlarmManagement(driver): logCommon.info('To the AlarmManagement page...') # driver.find_element_by_xpath("//span[@class='ebBreadcrumbs-arrow']").click() WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.XPATH, "//span[@class='ebBreadcrumbs-arrow']"))).click() WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.XPATH, "//div[@class='ebBreadcrumbs-list']/ul/li[4]/a"))).click() time.sleep(10)
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 to_pm_management_page(driver): ''' This function has been abandoned. :param driver: :return: ''' test.info('To the PmManagement page...') identifier = (By.XPATH, "//div[@class='ebLayout-Navigation']/div/div[1]/span") find_single_widget(driver, 10, identifier).click() identifier = (By.XPATH, "//div[@class='ebBreadcrumbs-list']/ul/li[3]/a") find_single_widget(driver, 10, identifier).click()
def send_an_alarm(host, ne_type, alarm_type): logCommon.info("Send alarm: " + ne_type + ":" + alarm_type) return { "alarmLevel": 2, "timeStamp": "2016-03-04 16:18:58", "alarmSource": "licId01", "alarmCategory": 3, "alarmDescription": "Cannot connect to X2 remote address. remote ip [192.168.20.10] port [7790]. errno [67] error description [Address already in use]" }
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_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 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 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_is_correct_page(driver, row_index, rows_of_page): """ This function handle the situation that we need to paginate to different to check the PM datas. :param rows_of_page: how many rows each page has :param driver: selenium instance :param row_index: row index of the GUI :return: None """ i_page = row_index / rows_of_page tgt_page_number = i_page if 0 == row_index % 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() # wait for the notification, maximum 10 seconds id_body_date = (By.XPATH, "//div[@class='ebTabs']/div[2]/div/div/div/div/table/tbody") find_single_widget(driver, 10, id_body_date) test.info('Now in page ' + str(tgt_page_number) + '.')
def findBtnReturnComfirmBtn(driver, btnClick): if (0 == btnClick): # btnClickEle = driver.find_element_by_id("idBtn-search") btnClickEle = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "idBtn-search"))) return btnClickEle elif (1 == btnClick): # btnClickEle = driver.find_element_by_id("idBtn-ack") logCommon.info('Click ACK button') btnClickEle = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "idBtn-ack"))) btnClickEle.click() # ebDialogBox-actionBlock btn = WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.XPATH, "//div[@class='ebDialogBox-actionBlock']/button[1]"))) logCommon.info('Found the confirm button and will click next.') return btn elif (2 == btnClick): # btnClickEle = driver.find_element_by_id("idBtn-clear") btnClickEle = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "idBtn-clear"))) btnClickEle.click() # ebDialogBox-actionBlock btn = WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.XPATH, "//div[@class='ebDialogBox-actionBlock']/button[1]"))) return btn elif (3 == btnClick): # idBtn-manual # btnClickEle = driver.find_element_by_id("idBtn-manual") btnClickEle = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "idBtn-manual"))) btnClickEle.click() # ebDialogBox-actionBlock btn = WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.XPATH, "//div[@class='ebDialogBox-actionBlock']/button[1]"))) return btn
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 to_ne_management_page_by_url(driver, server_info, url_add='#network-overview/ne-management'): test.info("To the NE Management page...") base_url = 'http://' + server_info.getProperty('host') + ':' + str(server_info.getProperty('port')) + \ server_info.getProperty('preurl') test.info('NeMgt URL is: ' + base_url + url_add) driver.get(base_url + url_add) test.info("Login to the NeManagement page successfully")
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 make_sure_is_correct_page(driver, row_index, rows_of_page): """ This function handle the situation that we need to paginate to different to check the PM datas. :param rows_of_page: how many rows each page has :param driver: selenium instance :param row_index: row index of the GUI :return: None """ i_page = row_index / rows_of_page tgt_page_number = i_page if 0 == row_index % 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() # wait for the notification, maximum 10 seconds id_body_date = ( By.XPATH, "//div[@class='ebTabs']/div[2]/div/div/div/div/table/tbody") find_single_widget(driver, 10, id_body_date) test.info('Now in page ' + str(tgt_page_number) + '.')
def windows_chrome_login_rsnms(browser_path, driver_path, host, username, password, port, url): """ init selenium driver for chrome on windows platform. :param browser_path: chrome installation path :param driver_path: selenium path :param host: host ip of target rsnms server :param username: username that to login to the rsnms server :param password: password that to login to the rsnms server :param port: port number of target url :return: the driver instance of the selenium """ chrome_driver = os.path.normpath(driver_path) test.info('Browser driver path: ' + str(chrome_driver)) os.environ["webdriver.chrome.driver"] = chrome_driver opts = Options() opts.binary_location = os.path.normpath(browser_path) test.info('Browser path: ' + str(browser_path)) driver = webdriver.Chrome(chrome_driver, chrome_options=opts) # driver.set_window_size(1024, 600) driver.maximize_window() login_first_page(driver, host, username, password, port, url) return 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 fetch_alarm_on_gui(driver,ne_type,alarm_trap,mappingInstance,alarm_type): nowtime=pydate.datetime.now() endtime=nowtime + pydate.timedelta(seconds=30) id_button=(By.XPATH,"//button[@id='idBtn-search']") search_button=find_single_widget(driver,10,id_button) while(pydate.datetime.now()< endtime): search_button.click() try: alarm_data=get_1st_row_on_gui(driver) except TimeoutException: time.sleep(5) continue if ne_type == 'OCGAS': specific_problem = mappingInstance.get_property("specific_problem")[alarm_type] else: specific_problem = alarm_trap["specificProblem"] if(specific_problem == alarm_data["问题描述"]): logCommon.info("alarm received on GUI:" + alarm_type) return alarm_data else: time.sleep(10) return None
def to_pm_management_page_by_url(driver, ne_type, server_info, to_url_pre='#network-overview/pm-management/'): test.info('Will Navigate to the PMManagement page...') base_url = 'http://' + server_info.getProperty('host') + ':' + str(server_info.getProperty('port')) + \ server_info.getProperty('preurl') test.info('Base URL is: ' + base_url) to_url = base_url + (to_url_pre + 'pm-' + ne_category_by_ne_type(ne_type) + '/' + 'pm-' + ne_type).lower() test.info('To URL: ' + to_url) driver.get(to_url) make_sure_in_pm_page(driver)
def init_and_search(driver, ne_name, end_time=None, start_time=None): # select the given nename select_given_ne_name(driver, ne_name) # select the correct time if end_time is not None: test.info('Query end time point set to: ' + end_time.strftime('%H%M%S')) id_end_time = (By.XPATH, "//div[@class='endtime']/div/span/input") find_single_widget(driver, 10, id_end_time).click() set_time_for_query(driver, end_time) if start_time is not None: test.info('Query start time point set to: ' + start_time.strftime('%H%M%S')) id_start_time = (By.XPATH, "//div[@class='starttime']/div/span/input") find_single_widget(driver, 10, id_start_time).click() set_time_for_query(driver, start_time) # click the query button id_query_btn = (By.ID, "idBtn-search") find_single_widget(driver, 10, id_query_btn).click() # wait for the notification, maximum 20 seconds id_body_date = (By.XPATH, "//div[@class='ebTabs']/div[2]/div/div/div/div/table/tbody") find_single_widget(driver, 20, id_body_date)
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 toAlarmManagement_by_url( driver, server_info, url_add="#network-overview/fault-mgt/fault-management"): logCommon.info("To the AlarmManagement page...") url = "http://" + server_info.getProperty("host") + ":" + str( server_info.getProperty("port")) + server_info.getProperty( "preurl") + url_add logCommon.info("The AlarmMgt URL is: " + url) driver.get(url) logCommon.info("Login AlarmManagement page successfully")
def to_pm_management_page_by_url( driver, ne_type, server_info, to_url_pre='#network-overview/pm-management/'): test.info('Will Navigate to the PMManagement page...') base_url = 'http://' + server_info.getProperty('host') + ':' + str(server_info.getProperty('port')) + \ server_info.getProperty('preurl') test.info('Base URL is: ' + base_url) to_url = base_url + (to_url_pre + 'pm-' + ne_category_by_ne_type(ne_type) + '/' + 'pm-' + ne_type).lower() test.info('To URL: ' + to_url) driver.get(to_url) make_sure_in_pm_page(driver)
def toAlarmManagement_by_url(driver,server_info,url_add = "#network-overview/fault-mgt/fault-management"): logCommon.info("To the AlarmManagement page...") url="http://" + server_info.getProperty("host") + ":" + str(server_info.getProperty("port")) + server_info.getProperty("preurl") + url_add logCommon.info("The AlarmMgt URL is: " + url) driver.get(url) logCommon.info("Login AlarmManagement page successfully")
def send_an_alarm(host,ne_type,alarm_type): logCommon.info("Send alarm: " + ne_type + ":" + alarm_type) return {"alarmLevel":2,"timeStamp":"2016-03-04 16:18:58","alarmSource":"licId01","alarmCategory":3,"alarmDescription":"Cannot connect to X2 remote address. remote ip [192.168.20.10] port [7790]. errno [67] error description [Address already in use]"}
def newConnection(self,host,user,passwd,defaultdb): try: self.conn = connector.connect(user=user, password = passwd, host = host, database=defaultdb) except Exception as e: test.info(e.msg)
def check_attr_accuracy(mappingInstance,alarm_trap,dict_nbi_notif,nename,nodeid,attrs,mysqlInst): for a in attrs: expected_value = {} notif_value = {} if 'event_name' == a: if dict_nbi_notif.has_key('event_name'): notif_value['event_name'] = dict_nbi_notif['event_name'] mapped_event_name = mappingInstance.convert_event_type(alarm_trap['alarmCategory']) if mapped_event_name != None: expected_value['event_name'] = '"' + mapped_event_name + '"' test.info("check 'event_name',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value,expected_value) else: test.failed("get 'event_name' from nbi notification Failed") elif "event_type" == a: if dict_nbi_notif.has_key("event_type"): notif_value['event_type'] = dict_nbi_notif["event_type"] type_name = '"' + mappingInstance.dict_mapping_info["type_name"] + '"' expected_value = {'event_type':{'none':{'domain_name':'"Alarm IRP V3.0.0"','type_name':type_name}}} test.info("check 'event_type',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value, expected_value) else: test.failed("get 'event_type' from nbi notification Failed") elif 'd' == a: if dict_nbi_notif.has_key("d"): notif_value['d'] = dict_nbi_notif["d"] object_class = '"' + mappingInstance.dict_mapping_info['object_class'] + '"' expected_value = {'d':{'value':{'CORBA::String':object_class}}} test.info("check 'objectClass',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value, expected_value) else: test.failed("get 'd' from nbi notification Failed") elif "e" == a: if dict_nbi_notif.has_key("e"): notif_value['e'] = dict_nbi_notif["e"] dn = mappingInstance.convert_object_instance(nodeid,nename) if dn != None: expected_value = {'e':{'value':{'CORBA::String':'"' + dn + '"'}}} test.info("check 'objectInstance',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value,expected_value) else: test.failed("get 'e' from nbi notification Failed") elif "b" == a: if dict_nbi_notif.has_key("b"): notif_value["b"] = dict_nbi_notif["b"] mapped_event_time = mappingInstance.convert_event_time(alarm_trap["timeStamp"]) if mapped_event_time!= None: expected_value = {'b':{'value':{'TimeBase::UtcT':{'none':{'time':mapped_event_time,'inacclo':'0','inacchi':'0','tdf':'480'}}}}} test.info("check 'eventTime',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value, expected_value) else: test.failed("get 'b' from nbi notification Failed") elif "c" == a: expected_value = {'c':{'value':{'CORBA::String':'"DC=Ericsson,SubNetwork=1,ManagementNode=1,IRPAgent=1"'}}} check_common_accuracy('c', dict_nbi_notif, expected_value) elif "jj" == a: if dict_nbi_notif.has_key("jj"): notif_value["jj"] = dict_nbi_notif["jj"] specific_problem = alarm_trap["specificProblem"] alarmtypeid = mappingInstance.convert_alarmtype_id(specific_problem) if alarmtypeid != None: mapped_vender_specificAlarmType = '"' + alarmtypeid + "||" + specific_problem + '"' expected_value = {'jj':{'value':{'CORBA::String':mapped_vender_specificAlarmType}}} test.info("check 'vendorSpecificAlarmType',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value,expected_value) else: test.failed("get 'jj' from nbi notification Failed") elif "g" == a: if dict_nbi_notif.has_key("g"): notif_value["g"] = dict_nbi_notif["g"] mapped_probable_cause = mappingInstance.convert_probable_cause(alarm_trap["probableCause"]) if mapped_probable_cause != None: expected_value = {'g':{'value':{'CORBA::Short':mapped_probable_cause}}} test.info("check 'probableCause',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value, expected_value) else: test.failed("get 'g' from nbi notification Failed") elif "h" == a: if dict_nbi_notif.has_key("h"): notif_value['h'] = dict_nbi_notif['h'] mapped_alarm_severity = mappingInstance.convert_alarm_severity(alarm_trap["alarmLevel"]) if mapped_alarm_severity != None: expected_value = {'h':{'value':{'CORBA::Short':mapped_alarm_severity}}} test.info("check 'perceivedSeverity',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value, expected_value) else: test.failed("get 'h' from nbi notification Failed") elif "a" == a: if dict_nbi_notif.has_key("a"): notif_value["a"] = dict_nbi_notif["a"] '''X use CORBA:LongLong although CORBA::Long is required in spec''' notif_id = dict_nbi_notif["a"]["value"]["CORBA::LongLong"] test.info("check 'notificationId',the nbi notification result is " + str(notif_value) ) sqltext = ('SELECT notificationId from alarms where notificationId = "%s"'%notif_id) is_unique=check_unique_id(sqltext,mysqlInst) if is_unique == 0: test.failed("the notificationId of " + notif_id + " not existed in database") elif is_unique == 1: test.passed("the notificationId of " + notif_id + " is unique in database") elif is_unique > 1: test.failed("more than one notificationId of " + notif_id + "found in database") else: test.failed("get 'a' from nbi notification Failed") elif "w" == a: if dict_nbi_notif.has_key("w"): notif_value["w"] = dict_nbi_notif["w"] dn = '"' + mappingInstance.convert_object_instance(nodeid,nename) + '"' if dn != None: notification_id = dict_nbi_notif["a"]["value"]["CORBA::LongLong"] expected_value = {'w':{'value':{'AlarmIRPConstDefs::CorrelatedNotification':{'none':{'source':dn,'notif_id_set':{'none':notification_id}}}}}} test.info("check 'correlatedNotifications',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value, expected_value) else: test.failed("get 'w' from nbi notification Failed") elif "p" == a: expected_value = {'p':{'value':{'CORBA::Boolean':'FALSE'}}} check_common_accuracy('p',dict_nbi_notif,expected_value) elif "q" == a: expected_value = {'q':{'value':{'CORBA::String':'"NULL"'}}} check_common_accuracy('q', dict_nbi_notif, expected_value) elif "s" == a: expected_value = {'s':{'value':{'AlarmIRPConstDefs::TrendIndication':'NO_CHANGE'}}} check_common_accuracy('s', dict_nbi_notif, expected_value) elif "v" == a: expected_value = {'v':{'value':{'CORBA::String':'""'}}} check_common_accuracy('v', dict_nbi_notif, expected_value) elif "j" == a: if dict_nbi_notif.has_key("j"): notif_value ["j"] = dict_nbi_notif["j"] additionaltext = '"' + alarm_trap["alarmDescription"] + '"' expected_value = {'j':{'value':{'CORBA::String':additionaltext}}} test.info("check 'additionalText',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value, expected_value) else: test.failed("get 'j' from nbi notification Failed") elif "ai_vs_threshold" == a: expected_value = {'ai_vs_threshold':{'value':{'CORBA::String':'""'}}} check_common_accuracy('ai_vs_threshold', dict_nbi_notif, expected_value) elif "ai_ps" == a: if dict_nbi_notif.has_key("ai_ps"): notif_value["ai_ps"] = dict_nbi_notif["ai_ps"] mapped_alarm_severity = '"' + mappingInstance.convert_alarm_severity(alarm_trap["alarmLevel"]) + '"' if mapped_alarm_severity != None: expected_value = {'ai_ps':{'value':{'CORBA::String':mapped_alarm_severity}}} test.info("check 'AI_VS_PERCEIVED_SEVERITY',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value, expected_value) else: test.failed("get 'ai_ps' from nbi notification Failed") elif "ai_at" == a: if dict_nbi_notif.has_key('ai_at'): notif_value['ai_at'] = dict_nbi_notif['ai_at'] mapped_event_name = '"' + mappingInstance.convert_event_type(alarm_trap['alarmCategory']) + '"' if mapped_event_name != None: expected_value['ai_at'] = expected_value = {'ai_at':{'value':{'CORBA::String':mapped_event_name}}} test.info("check 'AI_VS_ALARM_TYPE',the nbi notification result is " + str(notif_value) + ",and the expected result is " + str(expected_value)) compare_data(notif_value,expected_value) else: test.failed("get 'ai_at' from nbi notification Failed") elif "f" == a: if dict_nbi_notif.has_key("f"): notif_value["f"] = dict_nbi_notif["f"] alarm_id = notif_value["f"]["value"]["CORBA::String"] sqltext = ("SELECT id from alarms where id = %s"%alarm_id) is_unique=check_unique_id(sqltext,mysqlInst) if is_unique == 0: test.failed("alarmId of " + alarm_id + " not existed in database") elif is_unique == 1: test.passed("the alarmId of " + alarm_id + " is unique in database") elif is_unique > 1: test.failed("more than one alarmId of " + alarm_id + "found in database") else: test.failed("get 'f' from nbi notification Failed")
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 add_new_ne(driver, dict_ne_info): find_single_widget(driver, 10, (By.ID, "idBtn-create")).click() sleep(.5) # choose the correct ne_type id_select_ne_type = (By.XPATH, "//div[@id='i_netype']/div/button") find_single_widget(driver, 10, id_select_ne_type).click() # id_ne_type_list = (By.XPATH, "//div[@id='i_netype']/div/div/div[" + # str(ne_type_index_add_ne_page(dict_ne_info["ne_type"])) + "]") ne_type = dict_ne_info["ne_type"] id_ne_type_list = (By.XPATH, "//div[@id='i_netype']/div/div/div[@title='" + ne_type + "']") find_single_widget(driver, 10, id_ne_type_list).click() sleep(.5) # insert the common part id_ne_name = (By.ID, "i_nename") id_ne_ip = (By.ID, "i_neip") id_ne_user = (By.ID, "i_neuser") id_password = (By.ID, "i_nepassword") id_ne_port = (By.ID, "i_neport") id_sftp_port = (By.ID, "i_nesftpport") id_pm_path = (By.ID, "i_nepmfilepath") id_log_path = (By.ID, "i_nelogfilepath") id_alarm_path = (By.ID, "i_nefmfilepath") id_li_pwd = (By.ID, "i_nelipwd") id_fro_id = (By.ID, "i_nefroid") #add for HSS id_snmp_port = (By.ID, "i_snmpport") id_usmusername = (By.ID, "i_usmusername") id_i_authpwd = (By.ID, "i_authpwd") id_i_privpwd = (By.ID, "i_privpwd") id_i_appuser = (By.ID, "i_serviceusername") id_i_apppwd = (By.ID, "i_servicepwd") ne_name = dict_ne_info["ne_type"] + "-" + str( binascii.hexlify(os.urandom(8))).upper() w_ne_name = find_single_widget(driver, 10, id_ne_name) w_ne_name.clear() w_ne_name.send_keys(ne_name) w_ne_ip = find_single_widget(driver, 10, id_ne_ip) w_ne_ip.clear() w_ne_ip.send_keys(dict_ne_info["ne_ip"]) w_ne_user = find_single_widget(driver, 10, id_ne_user) w_ne_user.clear() w_ne_user.send_keys(dict_ne_info["ne_user"]) w_ne_password = find_single_widget(driver, 10, id_password) w_ne_password.clear() w_ne_password.send_keys(dict_ne_info["ne_password"]) w_ne_port = find_single_widget(driver, 10, id_ne_port) w_ne_port.clear() w_ne_port.send_keys(dict_ne_info["ne_port"]) if 'SBC' == dict_ne_info["ne_type"]: w_li_pwd = find_single_widget(driver, 10, id_li_pwd) w_li_pwd.clear() w_li_pwd.send_keys(dict_ne_info["li_pwd"]) w_fro_id = find_single_widget(driver, 10, id_fro_id) w_fro_id.clear() w_fro_id.send_keys(dict_ne_info["fro_id"]) else: w_sftp_port = find_single_widget(driver, 10, id_sftp_port) w_sftp_port.clear() w_sftp_port.send_keys(dict_ne_info["sftp_port"]) w_pm_path = find_single_widget(driver, 10, id_pm_path) w_pm_path.clear() w_pm_path.send_keys(dict_ne_info["pm_path"]) w_log_path = find_single_widget(driver, 10, id_log_path) w_log_path.clear() w_log_path.send_keys(dict_ne_info["log_path"]) if 'IMSHSS' == dict_ne_info["ne_type"] or 'LTEHSS' == dict_ne_info[ "ne_type"]: w_snmp_port = find_single_widget(driver, 10, id_snmp_port) w_snmp_port.clear() w_snmp_port.send_keys(dict_ne_info["snmp_port"]) w_usm_user = find_single_widget(driver, 10, id_usmusername) w_usm_user.clear() w_usm_user.send_keys(dict_ne_info["usm_user"]) w_auth_pwd = find_single_widget(driver, 10, id_i_authpwd) w_auth_pwd.clear() w_auth_pwd.send_keys(dict_ne_info["auth_password"]) w_priv_pwd = find_single_widget(driver, 10, id_i_privpwd) w_priv_pwd.clear() w_priv_pwd.send_keys(dict_ne_info["priv_password"]) w_app_user = find_single_widget(driver, 10, id_i_appuser) w_app_user.clear() w_app_user.send_keys(dict_ne_info["app_user"]) w_app_pwd = find_single_widget(driver, 10, id_i_apppwd) w_app_pwd.clear() w_app_pwd.send_keys(dict_ne_info["app_password"]) elif 'OCGAS' == dict_ne_info["ne_type"]: w_alarm_path = find_single_widget(driver, 10, id_alarm_path) w_alarm_path.clear() w_alarm_path.send_keys(dict_ne_info["alarm_path"]) id_submit_btn = (By.ID, "idBtn-save") find_single_widget(driver, 10, id_submit_btn).click() try: id_dialog_confirm = ( By.XPATH, "//div[@class='ebDialogBox-actionBlock']/button[1]") find_single_widget(driver, 10, id_dialog_confirm).click() except Exception as e: test.info('There is no duplicated NEs.') test.info('Successfully added an NE: ' + str(ne_name)) return ne_name
def newConnection(self, host, user, passwd, defaultdb): try: self.conn = connector.connect(user=user, password=passwd, host=host, database=defaultdb) except Exception as e: test.info(e.msg)
# -*- coding: utf-8 -*- from com.ericsson.xn.commons import test_logger import Mod if __name__ == '__main__': test_logger.init('pm_main', 'pm') test_logger.info('This is info testing.') Mod.foo() test_logger.finish()
def add_new_ne(driver, dict_ne_info): find_single_widget(driver, 10, (By.ID, "idBtn-create")).click() sleep(.5) # choose the correct ne_type id_select_ne_type = (By.XPATH, "//div[@id='i_netype']/div/button") find_single_widget(driver, 10, id_select_ne_type).click() # id_ne_type_list = (By.XPATH, "//div[@id='i_netype']/div/div/div[" + # str(ne_type_index_add_ne_page(dict_ne_info["ne_type"])) + "]") ne_type = dict_ne_info["ne_type"] id_ne_type_list = (By.XPATH, "//div[@id='i_netype']/div/div/div[@title='" + ne_type + "']") find_single_widget(driver, 10, id_ne_type_list).click() sleep(.5) # insert the common part id_ne_name = (By.ID, "i_nename") id_ne_ip = (By.ID, "i_neip") id_ne_user = (By.ID, "i_neuser") id_password = (By.ID, "i_nepassword") id_ne_port = (By.ID, "i_neport") id_sftp_port = (By.ID, "i_nesftpport") id_pm_path = (By.ID, "i_nepmfilepath") id_log_path = (By.ID, "i_nelogfilepath") id_alarm_path = (By.ID, "i_nefmfilepath") id_li_pwd = (By.ID, "i_nelipwd") id_fro_id = (By.ID, "i_nefroid") #add for HSS id_snmp_port = (By.ID,"i_snmpport") id_usmusername = (By.ID,"i_usmusername") id_i_authpwd = (By.ID,"i_authpwd") id_i_privpwd = (By.ID,"i_privpwd") id_i_appuser = (By.ID,"i_serviceusername") id_i_apppwd = (By.ID,"i_servicepwd") ne_name = dict_ne_info["ne_type"] + "-" + str(binascii.hexlify(os.urandom(8))).upper() w_ne_name = find_single_widget(driver, 10, id_ne_name) w_ne_name.clear() w_ne_name.send_keys(ne_name) w_ne_ip = find_single_widget(driver, 10, id_ne_ip) w_ne_ip.clear() w_ne_ip.send_keys(dict_ne_info["ne_ip"]) w_ne_user = find_single_widget(driver, 10, id_ne_user) w_ne_user.clear() w_ne_user.send_keys(dict_ne_info["ne_user"]) w_ne_password = find_single_widget(driver, 10, id_password) w_ne_password.clear() w_ne_password.send_keys(dict_ne_info["ne_password"]) w_ne_port = find_single_widget(driver, 10, id_ne_port) w_ne_port.clear() w_ne_port.send_keys(dict_ne_info["ne_port"]) if 'SBC' == dict_ne_info["ne_type"]: w_li_pwd = find_single_widget(driver, 10, id_li_pwd) w_li_pwd.clear() w_li_pwd.send_keys(dict_ne_info["li_pwd"]) w_fro_id = find_single_widget(driver, 10, id_fro_id) w_fro_id.clear() w_fro_id.send_keys(dict_ne_info["fro_id"]) else: w_sftp_port = find_single_widget(driver, 10, id_sftp_port) w_sftp_port.clear() w_sftp_port.send_keys(dict_ne_info["sftp_port"]) w_pm_path = find_single_widget(driver, 10, id_pm_path) w_pm_path.clear() w_pm_path.send_keys(dict_ne_info["pm_path"]) w_log_path = find_single_widget(driver, 10, id_log_path) w_log_path.clear() w_log_path.send_keys(dict_ne_info["log_path"]) if 'IMSHSS' == dict_ne_info["ne_type"] or 'LTEHSS' == dict_ne_info["ne_type"]: w_snmp_port = find_single_widget(driver, 10, id_snmp_port) w_snmp_port.clear() w_snmp_port.send_keys(dict_ne_info["snmp_port"]) w_usm_user = find_single_widget(driver, 10, id_usmusername) w_usm_user.clear() w_usm_user.send_keys(dict_ne_info["usm_user"]) w_auth_pwd = find_single_widget(driver, 10, id_i_authpwd) w_auth_pwd.clear() w_auth_pwd.send_keys(dict_ne_info["auth_password"]) w_priv_pwd = find_single_widget(driver, 10, id_i_privpwd) w_priv_pwd.clear() w_priv_pwd.send_keys(dict_ne_info["priv_password"]) w_app_user = find_single_widget(driver, 10, id_i_appuser) w_app_user.clear() w_app_user.send_keys(dict_ne_info["app_user"]) w_app_pwd = find_single_widget(driver, 10, id_i_apppwd) w_app_pwd.clear() w_app_pwd.send_keys(dict_ne_info["app_password"]) elif 'OCGAS' == dict_ne_info["ne_type"]: w_alarm_path = find_single_widget(driver, 10, id_alarm_path) w_alarm_path.clear() w_alarm_path.send_keys(dict_ne_info["alarm_path"]) id_submit_btn = (By.ID, "idBtn-save") find_single_widget(driver, 10, id_submit_btn).click() try: id_dialog_confirm = (By.XPATH, "//div[@class='ebDialogBox-actionBlock']/button[1]") find_single_widget(driver, 10,id_dialog_confirm).click() except Exception as e: test.info('There is no duplicated NEs.') test.info('Successfully added an NE: ' + str(ne_name)) return ne_name