def delete_products(self): self.navigate('Catalog', 'Manage Products') if a.get_elements_by_xpath("//td[text()='No records found.']"): return click_link_by_text('Select All') a.set_dropdown_value('productGrid_massaction-select', 'Delete') self.click_magento_button('Submit', wait=False) a.accept_alert('Are you sure?')
def wait_for_element(ps=None, flash='#', index=0, attempts=10, xpath=None, css_select=None, *args, **kwargs): """ Waits for one specific elements. Returns an element ps: logging message of your choosing type ps: string flash: accentuates your print statement in the console type flash: string index: will return the elment you specify by index type index: int attempts: number of tries, seperated by a 1 second sleep to get the elements type attempts: int xpath: an xpath like you would pass into get_element_by_xpath() type xpath: string css_select: a css selector like you would pass into get_element_by_css() type css_select: string *args, **kwargs: any element pair you would pass into get_element() e.g tag='some_tag_type', css_class='some_class_name' """ some_element = None counter = 1 while not some_element: try: if xpath: some_element = get_elements_by_xpath(xpath)[index] elif css_select: some_element = get_elements_by_css(css_select)[index] else: some_element = get_elements(*args, **kwargs)[index] except Exception as e: if counter > 2: test_print('ERROR: {0}. Attempt {1} of {2}'.format(e, counter, attempts)) sleep(1) counter += 1 if counter > attempts and not some_element: raise e break if some_element and ps: test_print(ps, flash) return some_element
def click_element_by_xpath(xpath, multiple=False, wait=True): """ Click the element given by the xpath. @param multiple: if True, allow multiple elements and click the first one. @param wait: if True, wait for a page with body element available. """ elements = a.get_elements_by_xpath(xpath) if len(elements) == 0: raise AssertionError, "Could not identify element: 0 elements found" if len(elements) > 1 and not multiple: raise AssertionError, \ "Could not identify element: %d elements found" % len(elements) element = elements[0] a.click_element(element, wait=wait)
set_radio_value(radio_fullname) set_radio_value(radio_email) set_radio_value(radio_language) click_button(get_element(value='Begin')) wait_for(assert_title, 'Log in') write_textfield('id_email', settings.SSO_TEST_ACCOUNT_EMAIL) write_textfield('id_password', settings.SSO_TEST_ACCOUNT_PASSWORD) click_button(get_element_by_css('*[data-qa-id="ubuntu_login_button"]')) wait_for(assert_title_contains, 'Authenticate to') # Check the elements specified in the .csv list if toggled_elements is not None: for optional_sreg_element in toggled_elements: toggle_checkbox(optional_sreg_element) if disabled_elements is not None: for required_sreg_element in disabled_elements: assert_element(id=required_sreg_element, disabled="disabled") click_button(get_element(name='yes')) wait_for(assert_title, 'Django OpenID Example Consumer') assert_text_contains(get_element(tag='div', css_class='message success'), 'OpenID authentication succeeded') count = 0 # Check correct sreg data was returned from the list in the .csv if returned_sreg is not None: for sreg_element in returned_sreg: assert_text(get_elements_by_xpath("//li")[count], sreg_element) count = count + 1
skip_production, ) config.set_base_url_from_env() skip_production() # XXX: skip if staging until the test can be made to reliably pass if is_staging(): skip() resulting_teams = ast.literal_eval(resulting_teams) go_to(urls.CONSUMER) wait_for(assert_title, 'Django OpenID Example Consumer') toggle_checkbox('id_teams') write_textfield('id_request_teams', team_names) click_button(get_element(value='Begin')) login_from_redirect() wait_for(assert_title, 'Django OpenID Example Consumer') assert_text_contains(get_element(tag='div', css_class='message success'), 'OpenID authentication succeeded') # Check the results of the team requests from the list in the .csv for i, team in enumerate(resulting_teams): assert_text(get_elements_by_xpath("//li")[i], team)