def cleanup(): go_to(urls.DEVICES) # cleanup assumes the user is logged in, otherwise we get a circular # dependency between helpers and devices msg = 'Can not cleanup devices if user is not logged in.' assert '+login' not in get_current_url(), msg while get_elements_by_css('#device-list td.name'): name = get_elements_by_css('#device-list td.name')[0].text print 'Deleting a device:', name delete_device()
def wait_write(text_to_write, attempts=10, ps=None, flash='#', index=0, css_select=None, *args, **kwargs): """ writes to a text field text_to_write: text intended to be written to text field type text_to_write: string attempts: number of tries, seperated by a 1 second sleep to get the elements type attempts: int 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 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' """ if css_select: wait_for_element(css_select=css_select) else: wait_for_element(*args, **kwargs) while attempts > 0: try: if css_select: write_textfield(get_elements_by_css(css_select)[index], text_to_write) assert_text(get_elements_by_css(css_select)[index], text_to_write) break else: write_textfield(get_elements(*args, **kwargs)[index], text_to_write) assert_text(get_elements(*args, **kwargs)[index], text_to_write) break except Exception as e: attempts -= 1 sleep(1) if attempts == 0: raise e if ps: test_print(ps, flash)
def _get_paper_device_codes(counter): url = get_current_url() restore = False if not re.match(r'.*/device-print/\d+$', url): assert_url('/device-list') click_link(get_element(tag='a', text='View Codes')) restore = True codes = [e.text for e in get_elements_by_css('ol.codelist li')][counter:] if restore: go_to('/device-list') return codes
def wait_click_url(ps=None, flash='#', attempts=10, index=0, element=None, css_select=None, *args, **kwargs): """ clicks url AND waits for url to change 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' """ chk_url = get_current_url() counter = 1 while chk_url == get_current_url(): if element: wait_for(click_element, element) elif css_select: try: wait_for(click_element, get_elements_by_css(css_select)[index]) except Exception as e: if counter > 2: test_print('ERROR: "{0}". Attempt {1} of {2}'.format(e, counter, attempts)) else: try: wait_for(click_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)) if counter == attempts: raise Exception('Error: The url did not change after {0} attempts'.format(attempts)) break else: sleep(1) counter += 1 if ps: test_print(ps, flash)
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 delete_device(): go_to(urls.DEVICES) # Fetch the name of the device we will be deleting name = get_elements_by_css('#device-list td.name')[0].text # Click on the delete button click_delete_button() # if we need to 2F auth this action if exists_element(id='id_oath_token'): authenticate() # Click on ok click_button(get_element(tag='button', text='Delete this device')) remove_device(name) # Check we are back on the device-list page assert_url('/device-list') # Check that our device has been deleted fails(get_element, 'device-list')
def get_field_labels(): return [ x.text for x in get_elements_by_css('.sr-only.control-label') if x.text not in (None, '') ]
assert_title, browser, click_button, get_element, get_elements_by_css, get_link_url, go_to, ) from u1testutils.sst import config from acceptance import helpers, urls config.set_base_url_from_env(default_to='https://login.ubuntu.com/') helpers.production_only() helpers.login_to_test_account() go_to("https://one.ubuntu.com/services/plan/subscribe_basic/") if 'Confirm Subscription' in browser.title: click_button(get_element(type='submit', name='subscribe')) assert_title("Ubuntu One : Dashboard") go_to(urls.HOME) link = get_elements_by_css('#visited-sites tbody td a')[0] assert get_link_url(link) == "https://one.ubuntu.com/"
def get_field_labels(): return [x.text for x in get_elements_by_css('.sr-only.control-label') if x.text not in (None, '')]