def generate_cable_template(self, typeTemplate, serialNumber): """- typeTemplate: H1LCDuplex-T1LCDuplex-AtoB, H1LCDuplex-T1LCDuplex-AtoA, H1MPO12-T6LCDuplex-STRAIGHT, H2MPO12-T2MPO12-STRAIGHT , H1MPO12-T1MPO12-STRAIGHT, H1MPO12-T1MPO12-FLIPPED, H1MPO24-T1MPO24-STRAIGHT, H1MPO24-T1MPO24-FLIPPED, H2MPO24-T2MPO24-STRAIGHT , H1LCSimplex-T1LCSimplex, H4MPO12-T4MPO12-STRAIGHT, H1RJ45-T1RJ45 - serialNumber: number not string""" self._go_to_sub_page("Cable Templates") self.cableTemplateCbb.select_from_list_by_label(typeTemplate) self.cableSerialNumberTxt.input_text(serialNumber) self.generateBtn.click_visible_element() self.headsTextarea.wait_until_element_is_visible() totalHeads = self.headsTextarea.get_element_count() totalTails = self.tailsTextarea.get_element_count() listHeads = [] listTails = [] for i in range(totalHeads): headsXpath = self.headsTextarea.locator() + "[%s]" % str(i + 1) headsValue = Element(headsXpath).get_element_attribute("value") listHeads.append(headsValue) for i in range(totalTails): tailsXpath = self.tailsTextarea.locator() + "[%s]" % str(i + 1) tailsValue = Element(tailsXpath).get_element_attribute("value") listTails.append(tailsValue) return [listHeads, listTails]
def toggle_layout_item_expand_state(self, paneXpath, item, state): """state: expand, collapse""" itemElement = self.build_layout_item_element(paneXpath, "Source", item) collapsedItem = itemElement.locator() + "/ancestor::div[1 and @isshow = '0']" expandedItem = itemElement.locator() + "/ancestor::div[1 and @isshow = '1']" if (Element(collapsedItem).is_element_existed() and state == "expand") or (Element(expandedItem).is_element_existed() and state == "collapse"): itemElement.click_visible_element()
def _click_table_cell(self, row, column, mode="single"): dynamicCellXpath = self.locator() + "//tr[" + str( row) + "]//td[" + str(column) + "]" Element(dynamicCellXpath).set_focus_to_element() if mode == "double": Element(dynamicCellXpath).double_click_element() else: Element(dynamicCellXpath).click_visible_element()
def click_tree_node_check_box(self, path, delimiter="/"): if path == "": self.rootNodeChk.click_visible_element() else: node = self._expand(path, delimiter) self.wait_for_tree_load() nodeChk = Element(node.locator() + "//ins[@class='jstree-checkbox']") if nodeChk is not None: nodeChk.click_element() else: raise NoSuchElementException(path)
def _sort_column_by_name(self, column, typeSort="asc"): """type: asc(small->big), desc(big->small)""" dynamicColumn = self.locator( ) + "/preceding::table[1]//th[*[normalize-space(text())='" + column + "']]" dynamicDisabledSortSpan = self.locator( ) + "/preceding::table[1]//th[*[normalize-space(text())='" + column + "']]//span[@sort='" + typeSort + "' and contains(@class,'disabled')]" dynamicEnabledSortSpan = self.locator( ) + "/preceding::table[1]//th[*[normalize-space(text())='" + column + "']]//span[@sort='" + typeSort + "' and not(contains(@class,'disabled'))]" while (Element(dynamicDisabledSortSpan).is_element_present() and not Element(dynamicEnabledSortSpan).is_element_existed()): Element(dynamicColumn).click_visible_element()
def _check_event_details(self, eventDetails, eventDescription, eventDateTime=None, position=1, delimiter="/"): textDetailsList = eventDetails.split(delimiter) detailsXpath = self.detailsBridgeXpath.locator() eventPos = self._build_event_xpath(eventDescription, eventDateTime, position) self.secondIframe.wait_until_page_contains_element() self._select_iframe(self.secondIframe, self.eventLogTbl) self.selectItemCbb.wait_until_element_is_visible() self.selectItemCbb.select_from_list_by_label(1000) self._expand_events() for text in textDetailsList: subDetails = detailsXpath self.dynamicTextXpath.arguments = [text] strTextXpath = self.dynamicTextXpath.locator() detailsXpath = subDetails + strTextXpath fullDetailsXpath = eventPos.locator() + detailsXpath SeleniumAssert.element_should_be_visible(Element(fullDetailsXpath)) driver.unselect_frame()
def _check_tree_node_selected(self, treeDiv, treeNode, delimiter="/"): buildXpath = self._build_tree_node_xpath(treeDiv, treeNode, delimiter) expectedNode = buildXpath + "[@class='jstree-clicked']" observedResult = Element( expectedNode).return_wait_for_element_visible_status(1) Assert.should_be_true(observedResult == True, "Tree node is not selected")
def _check_table_row_map_with_header_checkbox_selected( self, headers, values, delimiter=","): row = self._work_on_table_row_map_with_header(headers, values, False, None, delimiter) dynamicChkBxRowXpath = self.locator() + "//tr[" + str(row) + "]//input" eleChk = Element(dynamicChkBxRowXpath) SeleniumAssert.checkbox_should_be_selected(eleChk)
def remove_layout_items(self, pane, items, delimiter=","): """pane: Header, Content, Footer""" self._select_iframe(self.uniqueIframe, self.editLayoutHeaderFooterLeftDiv) paneXpath = self.define_layout_pane_xpath(pane) listItem = items.split(delimiter) for item in listItem: itemElement = self.build_layout_item_element(paneXpath, "Source", item) removeBtnXpath = itemElement.locator() + "/following::input[1]" Element(removeBtnXpath).click_visible_element() driver.unselect_frame()
def check_work_order_priority_color(self, woName, color): self._select_iframe(workOrders.woQueueIframe, self.markCompleteBtn) returnRow = self.get_table_row_map_with_header_on_wo_queue_table( "Work Order", woName) dynamicCellXpath = self.woQueueTbl.locator() + "//tr[" + str( returnRow ) + "]/td[@aria-describedby='WorkOrderQueueGrid_Priority']/div" eleCell = Element(dynamicCellXpath) SeleniumAssert.element_attribute_value_should_contain( eleCell, "style", color) driver.unselect_frame()
def get_performance_view_report(self): self._select_iframe(self.uniqueIframe, report.viewBtn) startCountTime = time.time() report.viewBtn.click_visible_element() self._wait_for_processing() Element("//table[@id='resultGrid']//tr[2]").wait_until_element_is_visible() stopCountTime = time.time() duration = stopCountTime - startCountTime driver.unselect_frame() if duration > 3: logger.warn("This report displays slowly. Please double-check.") return duration
def check_email_exist(self, emailSubject, details=None, timeout=constants.SELENPY_EMAIL_RECEIVED_TIMEOUT, delimiter=","): self.wait_until_email_received(emailSubject, timeout) if details is not None: detailsXpath = "" emailDetailslist = details.split(delimiter) for textDetails in emailDetailslist: self.dynamicEmailDetails.arguments = [textDetails] detailsXpath += self.dynamicEmailDetails.locator() fullEmailDetailsXpath = self.emailDetailsDiv.locator( ) + detailsXpath SeleniumAssert.element_should_be_visible( Element(fullEmailDetailsXpath))
def check_event_report_exist (self, eventInformation, eventDetails, delimiter=","): self._select_iframe(self.uniqueIframe, self.reportContentTbl) self._wait_for_processing(3) textInformationList = eventInformation.split(delimiter) textDetailsList = eventDetails.split(delimiter) eventRowDiv = self.headEventReportRow.locator() infoXpath = "" detailsXpath = "" for textInfo in textInformationList: self.dynamicEventReportInfo.arguments = [textInfo] infoXpath += self.dynamicEventReportInfo.locator() fullInfoXpath = eventRowDiv + infoXpath for textDetails in textDetailsList: self.dynamicEventReportDetails.arguments = [textDetails] detailsXpath += self.dynamicEventReportDetails.locator() fullEventReportXpath = fullInfoXpath + detailsXpath SeleniumAssert.element_should_be_visible(Element(fullEventReportXpath)) driver.unselect_frame()
def _work_on_table_row_map_with_header(self, headers, values, check=False, row=None, delimiter=","): dynamicFinalRowXpath = self._build_row_xpath(headers, values, row, delimiter) isRowExisted = Element( dynamicFinalRowXpath).return_wait_for_element_visible_status( constants.SELENPY_DEFAULT_TIMEOUT) if check is not False: Assert.should_be_true(isRowExisted, dynamicFinalRowXpath + " is not existed") else: if isRowExisted: rowIndex = self._get_row_index(dynamicFinalRowXpath) else: rowIndex = 0 return rowIndex
def _work_on_tree_node(self, divTree, treeNode, delimiter, click=True): treeNodeXpath = self._build_tree_node_xpath(divTree, treeNode, delimiter) eleExpectedNode = Element(treeNodeXpath) if eleExpectedNode.is_element_existed(): if click: eleExpectedNode.click_visible_element() return True else: nodeList = treeNode.split(delimiter) lastNode = len(nodeList) currentXpath = divTree.locator() temp = 1 for node in nodeList: dynamicNodeXpath = self.element("dynamicNodeXpath") dynamicNodeXpath.arguments = [node] currentXpath = currentXpath + dynamicNodeXpath.locator() dynamicEleCollapse = self.element("dynamicEleCollapse") dynamicEleCollapse.arguments = [currentXpath] if dynamicEleCollapse.return_wait_for_element_visible_status( 1) and temp != lastNode: dynamicExpandNodeBtn = self.element("dynamicExpandNodeBtn") dynamicExpandNodeBtn.arguments = [currentXpath] self._wait_for_loading_tree() dynamicExpandNodeBtn.click_visible_element() self._wait_for_loading_tree() if temp == lastNode: dynamicEleCurrentNode = self.element( "dynamicEleCurrentNode") dynamicEleCurrentNode.arguments = [currentXpath] if click: eleExpectedNode.click_visible_element() self._wait_for_loading_tree() return dynamicEleCurrentNode.is_element_existed() temp += 1
def wait_for_object_disappear_on_table(self, headers, values, delimiter=","): rowXpath = self._build_row_xpath(headers, values, None, delimiter) Element(rowXpath).wait_until_element_is_not_visible()
def does_tree_node_checkbox_exist(self, path, delimiter="/"): node = self._expand(path, delimiter) nodeChk = Element(node.locator() + "//ins[@class='jstree-checkbox']") return False if nodeChk is None else nodeChk.is_element_existed()
def _get_header_index(self, headerTable, headerName): dynamicListPreviousTh = headerTable + "//th[*[normalize-space(text())='" + headerName + "']]//preceding-sibling::th" countColumn = Element(dynamicListPreviousTh).get_element_count() return countColumn + 1
class TreeNodeElement(Element): def __init__(self, locator): super().__init__(locator) self.treeIcon = Element("/ins[@class='jstree-icon']", self) self.nodeName = Element("/a", self) self.children = Element("/ul/li", self) self.jstSelected = Element("/div[@class='jstreeSelect']", self) def _wait_for_selected(self, timeout=constants.SELENPY_OBJECT_WAIT_PROBE): def __is_selected(nodeName, jstSelected): attr = nodeName.get_element_attribute("class") return "jstree-clicked" in attr and jstSelected.is_element_existed() waitingKeywords._wait_until( lambda: __is_selected(self.nodeName, self.jstSelected), "Tree node '%s' still not selected" % self.locator()), timeout def _wait_for_children(self, timeout=constants.SELENPY_OBJECT_WAIT_PROBE): waitingKeywords._wait_until( lambda: self.children.get_element_count() > 0, "Tree node '%s' doesn't have any children" % self.locator()), timeout def _wait_for_toggle_status(self, status, timeout=constants.SELENPY_OBJECT_WAIT_PROBE): curStatus = "" def __get_current_status(): curStatus = self.get_tree_icon_status() return curStatus == status waitingKeywords._wait_until( lambda: __get_current_status(), "Element '%s' status to be '%s'. Current status: '%s'" % (self.locator(), status, curStatus)), timeout def get_tree_icon_status(self): self.treeIcon.wait_until_element_is_visible() status = driver.execute_javascript("return window.getComputedStyle(arguments[0]).backgroundPositionX", self.treeIcon.get_webelement()) if status == "-54px": return "collapsed" elif status == "-72px": return "expanded" else: return "empty" def click_element(self, modifier=False, action_chain=False): self.nodeName.wait_until_element_is_visible() self.nodeName.mouse_over() temp = 0 while(not "jstree-hovered" in self.nodeName.get_element_attribute("class") and temp < constants.SELENPY_DEFAULT_TIMEOUT): self.nodeName.mouse_over() self.nodeName.wait_until_element_attribute_contains("class", "hover") temp += 1 self.nodeName.click_element(modifier,action_chain) count = 0 while not "jstree-clicked" in self.nodeName.get_element_attribute("class") and count < constants.SELENPY_DEFAULT_TIMEOUT: self.nodeName.click_element(modifier,action_chain) count += 1 self._wait_for_selected() def is_leaf(self): attr = self.get_element_attribute("class") return "jstree-leaf" in attr def toggle(self, expand): curStatus = self.get_tree_icon_status() if expand: if curStatus == "expanded": return else: self._wait_for_toggle_status("collapsed") else: if curStatus == "collapsed": return else: self._wait_for_toggle_status("expanded") self.treeIcon.click_visible_element() if not self.is_leaf(): self._wait_for_toggle_status("expanded" if expand else "collapsed") self._wait_for_children() self.wait_for_element_outer_html_not_change()
def _get_row_index(self, rowXpath): dynamicListPreviousTr = rowXpath + "/preceding-sibling::tr" countRow = Element(dynamicListPreviousTr).get_element_count() return countRow + 1
def __init__(self, locator): super().__init__(locator) self.treeIcon = Element("/ins[@class='jstree-icon']", self) self.nodeName = Element("/a", self) self.children = Element("/ul/li", self) self.jstSelected = Element("/div[@class='jstreeSelect']", self)