def should_not_see_id(step, element_id): try: elem = world.browser.find_element_by_xpath(str('id("%s")' % element_id)) assert_true(step, not elem.is_displayed()) except NoSuchElementException: pass
def select_multi_items(step, selectId): with AssertContextManager(step): # show dropdown dd = world.browser.find_element_by_xpath( str('(//fieldset[@class="propertyType"]//img[@class="LMIDDArrow"])[2]') ) dd.click() time.sleep(5) # parse desired options options = step.multiline.split('\n') # make sure dropdown is present dropdown = world.browser.find_element_by_id(selectId) assert_true(step, dropdown) # clear before selecting clear = world.browser.find_element_by_link_text("clear all") clear.click() for opt in options: try: world.browser.find_element_by_xpath( str('//div[@id="'+selectId+'"]//input[@value="'+opt+'"]') ).click() except NoSuchElementException: print "\tERROR: no such option in "+selectId+" dropdown" return False
def wait_for_content(step, browser, content, timeout=15): start = time.time() while time.time() - start < timeout: if content in world.browser.page_source: return time.sleep(0.2) assert_true(step, content in world.browser.page_source)
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 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 wait_for_content(step, browser, content, timeout=15): start = time.time() while time.time() - start < timeout: if contains_content(world.browser, content): return time.sleep(0.2) assert_true(step, contains_content(world.browser, content))
def test_raise_assertion(self): self.stub.will_return_after_timeout() try: self.stub.decodated_method(PING) assert_true(False, "should raise Assertion Error") except AssertionError as e: assert_equal(ASSERTION_ERROR, e.__str__()) assert_equal(CALL_WITH_TIMEOUT, self.stub.calls_counter, "Should call only %s time(s)" % CALL_WITH_TIMEOUT)
def createSgClient(step): world.sgc = sendgrid.SendGridClient(world.username, world.password) # established sendgrid client assert_true(step, world.sgc.host == 'https://api.sendgrid.com') assert_true(step, world.sgc.port == '443') assert_true(step, world.sgc.endpoint == '/api/mail.send.json') assert_true(step, world.sgc.username == world.username) assert_true(step, world.sgc.password == world.password)
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 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 element_focused(step, id): """ Check if the element is focused """ elem = world.browser.find_element_by_xpath(str('id("{id}")'.format(id=id))) focused = world.browser.switch_to_active_element() assert_true(step, elem == focused)
def select_by_selector(step, selector): option = find_element_by_jquery(step, world.browser, selector) selectors = find_parents_by_jquery(world.browser, selector) assert_true(step, len(selectors) > 0) selector = selectors[0] selector.click() time.sleep(0.3) option.click() assert_true(step, option.is_selected())
def no_see_tooltip(step, tooltip): """ Press a button having a given tooltip. """ elem = world.browser.find_elements_by_xpath( str('//*[@title="%(tooltip)s" or @data-original-title="%(tooltip)s"]' % dict(tooltip=tooltip)) ) elem = [e for e in elem if e.is_displayed()] assert_true(step, not elem)
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 select_by_selector(step, selector): option = find_element_by_jquery(step, world.browser, selector) selectors = find_parents_by_jquery(world.browser, selector) assert_true(step, len(selectors) > 0) selector = selectors[0] selector.click() sleep(0.3) option.click() assert_true(step, option.is_selected())
def no_see_tooltip(step, tooltip): """ Press a button having a given tooltip. """ elem = world.browser.find_elements_by_xpath( str('//*[@title="%(tooltip)s" or @data-original-title="%(tooltip)s"]' % dict(tooltip=tooltip))) elem = [e for e in elem if e.is_displayed()] assert_true(step, not elem)
def test_raise_timeout(self): self.stub.will_return_after_first_call() self.stub.will_execute_one_call_longer_than_timeout() try: self.stub.decodated_method(PING) assert_true(False, "should raise Timeout Error") except TimeoutError as e: assert_equal(TIMEOUT_OCCURRED, e.__str__()) assert_equal(FIRST_CALL, self.stub.calls_counter, "Should call only %s time(s)" % FIRST_CALL)
def verify_cell_content(row_index, name, value): col_index, is_fixed = find_col_index(name) block_selector = '.ember-table-right-table-block' if is_fixed: block_selector = '.ember-table-left-table-block' col_value = world.browser.execute_script( "return $('.ember-table-body-container " + block_selector + " .ember-table-table-row:eq(" + str(row_index) + ") .ember-table-cell:eq(" + str(col_index) + ") span').text().trim()") assert_true(step, str(col_value) == str(value))
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 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 placeholder_contains(self, step, element_id, value): """ Check that the element identified but the given id contains the placeholder given. :param step: current Lettuce step. :param id_element: id of the element to be checked. :param value: expected placeholder of the element to be checked. """ elem = world.browser.find_element_by_xpath('//*[@id="%s"]' % element_id) assert_true(step, value in elem.get_attribute('placeholder'))
def checkResults(step, location): results = world.browser.find_elements_by_xpath("//div[@id='searchResultsTbl']//div[@class='vcard']//a") for title in results: try: assert_true(step, title.text.index(location) > -1) except ValueError: print "\tNote: found a result with location cut-off: '" + title.text + "'" print "\tChecking for partial match ..." keywords = [x.lstrip() for x in location.split(',')] confirmed = filter(lambda x: x in title.text, keywords) assert_true(step, len(confirmed) > 0) print "\tMatch found for search keyword '" + ", ".join(confirmed) + "'"
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 fill_in_textfield(step, field_name, value): with AssertContextManager(step): date_field = find_any_field(world.browser, DATE_FIELDS, field_name) if date_field: field = date_field else: field = find_any_field(world.browser, TEXT_FIELDS, field_name) assert_true(step, field, 'Can not find a field named "%s"' % field_name) if date_field: field.send_keys(Keys.DELETE) else: field.clear() field.send_keys(value)
def assert_multi_selected(step, select_name): with AssertContextManager(step): # Ensure its not selected unless its one of our options option_names = step.multiline.split('\n') select_box = find_field(world.browser, 'select', select_name) option_elems = select_box.find_elements_by_xpath(str('./option')) for option in option_elems: if option.get_attribute('id') in option_names or \ option.get_attribute('name') in option_names or \ option.get_attribute('value') in option_names or \ option.text in option_names: assert_true(step, option.is_selected()) else: assert_true(step, not option.is_selected())
def get_column_cursor(step, column_name): with AssertContextManager(step): cursor_css = "body.ember-application" action_chains = ActionChains(world.browser) element = world.browser.execute_script( "return $('.ember-table-header-container .ember-table-content:contains(" + column_name + ")').parent().parent().children()[1]") action_chains.drag_and_drop_by_offset(element, 10, 0).release().perform() cursor = find_elements_by_css(world.browser, cursor_css) style = cursor[0].get_attribute("style") assert_true(step, ("auto" in style) or ("resize" in style) or ("pointer" in style)) action_chains.release() world.browser.refresh()
def assert_multi_selected(step, select_name): with AssertContextManager(step): # Ensure its not selected unless its one of our options option_names = step.multiline.split('\n') select_box = find_field(world.browser, 'select', select_name) option_elems = select_box.find_elements_by_xpath('./option') for option in option_elems: if option.get_attribute('id') in option_names or \ option.get_attribute('name') in option_names or \ option.get_attribute('value') in option_names or \ option.text in option_names: assert_true(step, option.is_selected()) else: assert_true(step, not option.is_selected())
def assert_multi_selected(step, select_name): with AssertContextManager(step): # Ensure its not selected unless its one of our options option_names = step.multiline.split("\n") select_box = find_field(world.browser, "select", select_name) option_elems = select_box.find_elements_by_xpath("./option") for option in option_elems: if ( option.get_attribute("id") in option_names or option.get_attribute("name") in option_names or option.get_attribute("value") in option_names or option.text in option_names ): assert_true(step, option.is_selected()) else: assert_true(step, not option.is_selected())
def then_page_title_should_be(step, text): try: WebDriverWait(world.driver, 120).until(EC.title_contains(text)) assert_true(step, text in world.driver.title) assert_true(step, world.driver.find_element_by_id("id_username")) assert_true(step, world.driver.find_element_by_id("id_password")) finally: world.driver.quit()
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 checkResponse(step, result, message): if result == "success": print "\tRESPONSE: " + world.response + " | CODE: " + str(world.status) assert_true(step, world.status == 200 and "success" in world.response) else: print "\tRESPONSE: " + world.response + " | CODE: " + str(world.status) assert_true(step, world.status == 400 and "error" in world.response) # check message for error assert_true(step, message in world.response)
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 verify_grouped_row(index, row): indicator = row['indicator'] if indicator == '-': assert_true(step, is_the_row_expanded(index)) elif indicator == '+': assert_true(step, not is_the_row_expanded(index)) elif indicator == '': assert_true(step, is_the_leaf_node(index)) for field in row: if field != 'indicator': verify_cell_content(index, field, row[field])
def check_column_width(step, column_name, pixel): with AssertContextManager(step): if str(column_name) == "GroupingColumn": assert_true(step, int(bo.get_col_width_by_index(world.browser, 0)) == int(pixel)) else: assert_true(step, int(bo.get_col_width(world.browser, column_name)) == int(pixel))
def check_reorder_column(step, index, name): with AssertContextManager(step): if name == "GroupingColumn": assert_true(step, bo.get_col_name_by_index(world.browser, index) == "") else: assert_true(step, bo.get_col_name_by_index(world.browser, index) == name)
def check_grouping_fixed_num(step, num): with AssertContextManager(step): grouping_fixed_col_num = world.browser.execute_script( "return $('.ember-table-table-fixed-wrapper > div:eq(0) span').length") assert_true(step, int(num) == int(grouping_fixed_col_num))
def check_grouping_fixed_should_not_scroll(step): with AssertContextManager(step): grouping_fixed_scroll_left = world.browser.execute_script( "return $('.lazy-list-container:eq(0)').scrollLeft()") assert_true(step, int(grouping_fixed_scroll_left) == 0)
def check_columns_numbers(step, num): with AssertContextManager(step): col_count = world.browser.execute_script( "return $('.ember-table-content-container .ember-table-content').length") assert_true(step, int(col_count) == int(num))