def input_text(step,field_name,value,clear=None): with AssertContextManager(step): text_field = find(world.browser, field_name) if clear: text_field.clear() text_field.send_keys(value) time.sleep(1)
def check_fields_class_by_css(step): with AssertContextManager(step): assert_true(step, "text-red" in bo.get_grouped_column_css(world.browser, "Group1")) assert_true(step, "text-blue" in bo.get_grouped_column_css(world.browser, "Activity")) assert_true(step, "bg-gray" in bo.get_grouped_column_css(world.browser, "Activity")) assert_true(step, "text-blue" in bo.get_grouped_column_css(world.browser, "status")) assert_true(step, "bg-lightgray" in bo.get_grouped_column_css(world.browser, "status"))
def drag_scroll_bar(step, top_or_bottom): with AssertContextManager(step): offsety = 60 if top_or_bottom == "bottom": bo.drag_scroll_to_bottom(world.browser, offsety) else: bo.drag_scroll_to_top(world.browser, -int(offsety))
def get_reorder_indicator(step, pixel): with AssertContextManager(step): style = world.browser.execute_script( "return $('.ember-table-column-sortable-indicator.active').attr(\"style\")") indicator = str(style).split("left:")[1].split("px")[0].strip() assert_true(step, int(indicator) == int(pixel))
def page_title(step, title): """ Check that the page title matches the given one. """ with AssertContextManager(step): assert_equals(world.browser.title, title)
def check_row_indicator(step, index, indicator): with AssertContextManager(step): if indicator == 'collapse': assert_true(step, is_the_row_expanded(index)) elif indicator == 'expand': assert_true(step, (not is_the_row_expanded(index)) and (not is_the_leaf_node(index))) else: assert_true(step, is_the_leaf_node(index))
def Debo_ver_que_el_elemento_con_clase(step, element_class, title): with AssertContextManager(step): elements = world.browser.find_elements_by_class_name(element_class) lst = [] for e in elements: lst.append(e.text) assert title not in lst
def then_the_element_with_the_class_not_contains(step, element_class, title): with AssertContextManager(step): elements = world.browser.find_elements_by_class_name(element_class) lst = [] for e in elements: lst.append(e.text) assert title not in lst
def check_column_is_fixed(step, col_name): with AssertContextManager(step): col_names = world.browser.execute_script( "return $('.ember-table-table-fixed-wrapper > div:eq(0) span').text()") if str(col_name) == "GroupingColumn": assert_true(step, str("") in str(col_names)) else: assert_true(step, str(col_name) in str(col_names))
def check_row_indicator(step, row_name, indicator): with AssertContextManager(step): row = world.browser.execute_script( "return $('.ember-table-content:contains(" + str(row_name) + ")').siblings()") if indicator == "expand": assert_true(step, ("unfold" not in row[0].get_attribute("class")) and is_the_row_custom(row_name)) else: assert_true(step, ("unfold" in row[0].get_attribute("class")) and is_the_row_custom(row_name))
def check_grouped_row_wrap(step, col_name): with AssertContextManager(step): indicator_offset = world.browser.execute_script( "return $('.grouping-column-cell .ember-table-content:contains(" + col_name + ")').siblings().eq(1).offset().left") name_offset = world.browser.execute_script( "return $('.grouping-column-cell .ember-table-content:contains(" + col_name + ")').offset().left") assert_true(step, int(indicator_offset) < int(name_offset))
def click_on_label(step, label): """ Click on a label """ with AssertContextManager(step): elem = world.browser.find_element_by_xpath( str('//label[normalize-space(text()) = "%s"]' % label)) elem.click()
def check_loaded_chunk(step, num): with AssertContextManager(step): get_url(world.browser, "http://localhost:4200/lazy-loaded-loans?totalCount=" + str(num)) text = requests.get("http://localhost:2525/imposters/8888").json() dump_text = json.dumps(text) to_json = json.loads(dump_text)['requests'] assert_true(step, len(to_json) == 1) assert_true(step, to_json[0]['query']['section'] == "1")
def goto(self, step, url): """ Navigate to the given url. :param step: current Lettuce step. :param url: destination URL. """ url = self.parse_variables(url) with AssertContextManager(step): world.browser.get(url)
def fill_in_textfield(step, field_name, value): with AssertContextManager(step): text_field = find_field(world.browser, 'text', field_name) or \ find_field(world.browser, 'textarea', field_name) or \ find_field(world.browser, 'password', field_name) assert_false(step, text_field is False, 'Can not find a field named "%s"' % field_name) text_field.clear() text_field.send_keys(value)
def check_default_loading_indicator(step, num, timeout=5): with AssertContextManager(step): start = time.time() while time.time() - start < timeout: indicator = world.browser.execute_script("return $('.row-loading-indicator.loading')") if len(indicator) == int(num): return time.sleep(0.2) raise AssertionError
def input_has_value(step, field_name, value): """ Check that the form input element has given value. """ with AssertContextManager(step): text_field = find_any_field(world.browser, DATE_FIELDS + TEXT_FIELDS, field_name) assert_false(step, text_field is False, 'Can not find a field named "%s"' % field_name) assert_equals(text_field.get_attribute('value'), value)
def drag_hold_column(step, column_name, left_or_right, offsetx): with AssertContextManager(step): chains = ActionChains(world.browser) wait_for_elem(world.browser, "return $('.ember-table-content-container')") element = world.browser.execute_script( "return $('.ember-table-content-container .ember-table-content:contains(" + column_name + ")')") if left_or_right == "left": chains.click_and_hold(element[0]).move_by_offset(-int(offsetx), 0).perform() else: chains.click_and_hold(element[0]).move_by_offset(int(offsetx), 0).perform()
def check_sort_indicator(step, column_name, sort): with AssertContextManager(step): class_content = world.browser.execute_script( "return $('.ember-table-header-container .ember-table-content:contains(" + column_name + ")').parent().parent().attr(\'class\')") options = {"none": "", "asc": "sort-indicator-icon sort-indicator-icon-up", "desc": "sort-indicator-icon sort-indicator-icon-down", } if options.get(sort) == "none": assert_true(step, "sort-indicator-icon" not in class_content) assert_true(step, options.get(sort) in class_content)
def check_header_scroll_left(step, name): with AssertContextManager(step): start = time.time() flag = False while time.time() - start < 20: if int(bo.get_head_block_scroll_left(world.browser)) == int(bo.get_body_scroll_left(world.browser)): flag = flag or True break time.sleep(0.2) assert_true(step, flag)
def click_on_button(step): with AssertContextManager(step): element = WebDriverWait(world.browser, 30).until( EC.presence_of_element_located( (MobileBy.ID, "com.example.android.basicnetworking:id/test_action"))) element.click() WebDriverWait(world.browser, 30).until( EC.presence_of_element_located( (MobileBy.CLASS_NAME, "android.widget.TextView")))
def drag_element_offset(step, className, index, rightOrLeft, offsetx): with AssertContextManager(step): originalWidth = bo.get_column_width_by_class_name(world.browser, index) drag_element_by_offset_class_name(world.browser, className, index, rightOrLeft, offsetx) changedWidth = bo.get_column_width_by_class_name(world.browser, index) if str(rightOrLeft) == "left": assert_true(step, (int(changedWidth) - int(originalWidth)) == (-int(offsetx) - int(spanWidthPix))) else: assert_true(step, (int(changedWidth) - int(originalWidth)) == (int(offsetx) - int(spanWidthPix)))
def input_has_value(step, field_name, value): """ Check that the form input element has given value. """ with AssertContextManager(step): text_field = find_field(world.browser, 'text', field_name) or \ find_field(world.browser, 'textarea', field_name) or \ find_field(world.browser, 'password', field_name) assert_false(step, text_field is False, 'Can not find a field named "%s"' % field_name) assert_equals(text_field.get_attribute('value'), value)
def check_sort_column(step, record_index, record_content): with AssertContextManager(step): if record_index == "first": result = bo.get_record_content(world.browser, 0) assert_true(step, str(result) == record_content) elif record_index == "last": result = bo.get_record_content(world.browser, 1) assert_true(step, str(result) == record_content) else: result = bo.get_record_content(world.browser, 3) assert_true(step, str(result) == record_content)
def prepare_no_sort_col(step, fully_or_partial): with AssertContextManager(step): if "fully" in fully_or_partial: prepare_grouped_loans(step.hashes) step.given('Presenting "grouping column"') elif "lazily" in fully_or_partial: prepare_lazy_loaded_grouped_loans(step.hashes) step.given('Presenting "grouping column present partial loaded children"') elif "grouper" in fully_or_partial: prepare_lazy_loaded_grouped_loans(step.hashes) step.given('Presenting "grouper sort"')
def collapse_expanded_rows(step): with AssertContextManager(step): row = find_elements_by_css(world.browser, ".ember-table-toggle.ember-table-collapse") array = [] for i in range(0, len(row)): row_name = world.driver.execute_script( "return $('.ember-table-toggle.ember-table-collapse:eq(" + str(i) + ")').siblings().text().trim()") array.append(row_name) for i in range(2, array.__len__())[::-1]: element = world.driver.execute_script( "return $('.ember-table-content:contains(" + str(array[i - 1]) + ")').siblings()") element[0].click()
def search_with_keyword(step, keyword): with AssertContextManager(step): search_element = WebDriverWait(world.browser, 10).until( EC.presence_of_element_located( (MobileBy.ACCESSIBILITY_ID, "Search Wikipedia"))) search_element.click() search_input = WebDriverWait(world.browser, 30).until( EC.element_to_be_clickable( (MobileBy.ID, "org.wikipedia.alpha:id/search_src_text"))) search_input.send_keys(keyword) time.sleep(5)
def click_grouper(step, name, direction): with AssertContextManager(step): element = world.browser.execute_script("return $('.sort-grouper:contains(" + name + ")')") if direction == 'ASC' or direction == 'DESC': while direction.lower() not in world.browser.execute_script( "return $('.sort-grouper:contains(" + name + ")').text()"): element[0].click() else: while ('asc' in world.browser.execute_script( "return $('.sort-grouper:contains(" + name + ")').text()")) or ( 'desc' in world.browser.execute_script( "return $('.sort-grouper:contains(" + name + ")').text()")): element[0].click()
def check_grouping_column_should_not_scroll(step, column_name): with AssertContextManager(step): columns = world.browser.execute_script( "return $('.ember-table-header-container .ember-table-content').parent().parent()") for index, col in enumerate(columns): name = world.browser.execute_script( "return $('.ember-table-header-container .ember-table-content:eq(" + str(index) + ")').text().trim()") if name == column_name: num = index grouping_column_scroll_left = world.browser.execute_script( "return $('.lazy-list-container:eq(" + str(num) + ")').scrollLeft()") assert_true(step, int(grouping_column_scroll_left) == 0)
def press_by_tooltip(step, tooltip): """ Press a button having a given tooltip. """ with AssertContextManager(step): for button in world.browser.find_elements_by_xpath( str('//*[@title="%(tooltip)s" or @data-original-title="%(tooltip)s"]' % dict(tooltip=tooltip))): try: button.click() break except Exception: pass