コード例 #1
0
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)
コード例 #2
0
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
コード例 #3
0
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)
コード例 #4
0
    get_element_by_css,
    go_to,
    skip,
    sleep,
    write_textfield,
)
from u1testutils.sst import config

from acceptance import urls

from identityprovider.utils import get_current_brand


if get_current_brand() != 'ubuntuone':
    skip('Test only compatible with ubuntuone brand')

config.set_base_url_from_env()

go_to(urls.NEW_ACCOUNT)
assert_url(urls.NEW_ACCOUNT)
assert_title('Create account')

elem = get_element_by_css('.yui3-passwordmeter-indicatorNode p')

write_textfield('id_password', password)

# wait for animation
sleep(1)

assert_text(elem, error)
コード例 #5
0
    write_textfield,
    wait_for,
)
from sst import config as sst_config
from u1testutils import mail
from u1testutils.sst import config

from acceptance import helpers

if 'allow_unverified' in sst_config.flags:
    skip("allow_unverified means this test is irrelevant")

config.set_base_url_from_env()

email_address_for_token = mail.make_unique_test_email_address()
token = helpers.register_account(email_address_for_token)

# Now we create a second account and try to use the original
# verification code/token.
another_email = mail.make_unique_test_email_address()
helpers.logout()
helpers.register_account(another_email, verify=False)
write_textfield(get_element(name='confirmation_code'), token)
sleep(1)  # we have no idea why this is needed but bad things happen if omitted
click_button(get_element(css_class='btn'))

# We are still on the 'Enter confirmation code' page, and have been told
# that the confirmation code we used is unknown.
wait_for(assert_title_contains, 'Enter confirmation code')
exists_element(id='confirmation_code_error')