def configure_getfinancing(self, merch_id=None, username=None, password=None, postback_username=None, postback_password=None): if not merch_id: merch_id = os.getenv('GF_MERCH_ID') if not username: username = os.getenv('GF_USERNAME') if not password: password = os.getenv('GF_PASSWORD') if not postback_username: postback_username = os.getenv('GF_POSTBACK_USERNAME') if not postback_password: postback_password = os.getenv('GF_POSTBACK_PASSWORD') self.navigate('System', 'Configuration') self.navigate_configuration('Payment Methods') # GetFinancing could be open already try: a.assert_displayed('payment_getfinancing_active') except AssertionError: common.click_link_by_text('GetFinancing') a.set_dropdown_value('payment_getfinancing_active', 'Yes') a.write_textfield('payment_getfinancing_merch_id', merch_id) a.write_textfield('payment_getfinancing_username', username) a.write_textfield('payment_getfinancing_password', password) a.write_textfield('payment_getfinancing_postback_username', postback_username) a.write_textfield('payment_getfinancing_postback_password', postback_password) self.click_save_config() self.allow_symlinks() self.enable_log()
def fill_user_form(user, version=None): monkey_patch_sst() keys = user.keys() # for 1.8 and possibly lower, country needs to be filled before region_id # is a dropdown keys.sort() for key in keys: (vtype, value) = user[key] print 'fill', key, vtype, value try: el = a.get_element(id=key) except AssertionError: continue # before 1.9 region was a text field #if version < (1, 9, 0, 0) and key == 'region_id': # el = a.get_element(id='region') # a.write_textfield(el, value) if vtype == 'text': a.write_textfield(el, value) elif vtype == 'password': a.write_textfield(el, value, check=False) elif vtype == 'option': a.wait_for(a.assert_displayed, el) a.set_dropdown_value(el, value)
def rename_device(name, new_name): click_link(get_element(tag='a', text_regex='Rename')) # find name textfield elem = get_element(tag='input', name='name', value=name) # and update it write_textfield(elem, new_name) # and submit the form click_button(get_element(tag='button', text='Rename'))
def authenticate(name=None): cache = _get_device_cache() if name is None: # Just pick the first device we find name = cache.keys()[0] device = cache[name] if device.codes is None: otp = hotp.hotp(device.aes_key, device.counter) device.counter += 1 else: otp = device.codes.pop(0) write_textfield('id_oath_token', otp) click_button(get_element(type='submit'))
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 add_device(name='My device'): # Go to the authentication devices page go_to(urls.DEVICES) # Click on "Add a new authentication device" link click_add_new_device_link() # Choose "Generic HOTP device" and click add device set_radio_value('type_generic') click_add_device_button() # Add correctly generated OTP key aes_key = get_element(name='hex_key').get_attribute('value') valid_otp = hotp.hotp(aes_key, 0) write_textfield(get_element(tag='input', name='otp'), valid_otp) # Add a name write_textfield(get_element(tag='input', name='name'), name) # Click "Add device" click_add_device_button() store_device(name, aes_key) return aes_key
from u1testutils.sst import config from acceptance import helpers, urls from identityprovider.utils import get_current_brand if get_current_brand() == 'ubuntuone': skip( 'The ubuntuone brand does client side validation' ) config.set_base_url_from_env() # Create and verify account A helpers.register_account() # Add and verify 2nd email go_to(urls.EMAILS) wait_for(assert_title_contains, "'s email addresses") write_textfield('id_newemail', address) click_button(get_element(name='continue')) # Check the outcome if valid: wait_for(assert_title, 'Validate your email address') mail.delete_msgs_sent_to(address) else: wait_for(assert_title, 'Add an email') assert_text_contains(get_element(name='newemailform'), 'Invalid email.')
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)
password = '******' # Create an account email_address = helpers.register_account(password=password) # Login with the api to get a token response = client.login(email=email_address, password=password, token_name='test') assert_equal(response.status_code, 201) login_token = response.json() # Add a new email go_to(urls.EMAILS) assert_title_contains("email addresses") new_email = mail.make_unique_test_email_address() write_textfield('id_newemail', new_email) click_button(get_element(name='continue')) # Find the invalidation link link = sso_mail.get_invalidation_link_for_address(new_email) assert link is not None, 'Invalidation link should not be None.' # Invalidate the new email address go_to(link) assert_title_contains('Email invalidation') click_button(get_element(name='invalidate')) assert_title_contains('Email invalidated') # The login token should now be invalid, meaning we can only get public data response = client.account_details(login_token['openid'], login_token)
write_textfield, wait_for, ) from u1testutils.sso import mail from u1testutils.sst import config from acceptance import helpers config.set_base_url_from_env() # Register a new account and request a password reset. email_address = helpers.register_account(displayname="Fred Jones", verify=True) helpers.request_password_reset(email_address) # Fetch and verify the confirmation code. link = mail.get_verification_link_for_address(email_address) go_to(link) # Reset the password and verify that we're logged in. assert_title('Reset password') write_textfield('id_password', "Admin007") write_textfield('id_passwordconfirm', "Admin007") click_button(get_element(name='continue')) assert_element(**{'data-qa-id': 'edit_account'}) # Now try to use the link a second time. helpers.logout() go_to(link) wait_for(assert_title, "Unauthorized confirmation code")
set_wait_timeout(20) config.set_base_url_from_env() helpers.skip_unless_staging_or_production() helpers.login_to_test_account() go_to("http://askubuntu.com/users/authenticate/") if exists_element(id='more-options-link'): get_element(id='more-options-link').click() def openid_input_is_displayed(): return get_element(id='openid_identifier').is_displayed() wait_for(openid_input_is_displayed) write_textfield('openid_identifier', get_base_url()) click_button('submit-button') wait_for(get_element, type='submit', name='yes', css_class='btn') click_button(get_element(type='submit', name='yes', css_class='btn')) wait_for(assert_url_contains, 'askubuntu.com') if exists_element(type="submit", value="Confirm and Create New Account"): click_button(get_element(type="submit", value="Confirm and Create New Account")) wait_for(assert_title, "Ask Ubuntu - Stack Exchange") go_to(urls.HOME) link = get_elements_by_css('#visited-sites tbody td a')[0] assert get_link_url(link) == "http://askubuntu.com/users/authenticate/"
config.set_base_url_from_env() edit_account_anchor = {'data-qa-id': 'edit_account'} # Create an account and logout. email_address = helpers.register_account( displayname="Fred Jones", verify=True ) helpers.logout() # Request the password reset. go_to(urls.HOME) assert_title('Log in') click_link('forgotpw-link') write_textfield('id_email', email_address) # Even though the recaptcha field is ignored for our tests, we do # want to verify that it is on the page. write_textfield('recaptcha_response_field', 'ignored') click_button(get_element(name='continue')) assert_element(**{'data-qa-id': 'forgot_password_step_2'}) # Fetch and verify the confirmation code. vcode = mail.get_verification_code_for_address(email_address) write_textfield(get_element(name='confirmation_code'), vcode) click_button(get_element(css_class='btn')) # Reset the password and verify that we're logged in. assert_title('Reset password') write_textfield('id_password', "Other008")
account_password = '******' go_to(urls.NEW_ACCOUNT) assert_title('Create account') helpers.register_account(email_address, password=account_password) wait_for(assert_element, **{'data-qa-id': 'edit_account'}) # Depending whether we're on Production or Staging different tests if get_base_url() == 'https://login.ubuntu.com': # Production # shop go_to('http://shop.canonical.com') wait_for(assert_title, 'Canonical Store') click_link(get_element(href="https://shop.canonical.com/login.php")) wait_for(get_element, id='id_email') write_textfield('id_email', email_address) write_textfield('id_password', account_password) click_button(get_element(name='continue')) click_button(get_element(name='yes')) wait_for(get_element, name='email_address') assert_element(value=email_address) # launchpad go_to('https://launchpad.net/~canonical-isd-hackers/+archive/internal-qa/' '+index') click_button(get_element(name='yes')) assert_element(tag='h1', text='Not allowed here') # wiki go_to('http://wiki.canonical.com') click_link(get_element(id="login"))
def add_product(self, name, price, sku): self.navigate('Catalog', 'Manage Products') self.click_magento_button('Add Product') self.click_magento_button('Continue') a.write_textfield('name', name) a.write_textfield('description', name) a.write_textfield('short_description', name) a.write_textfield('sku', sku) a.write_textfield('weight', '1') a.set_dropdown_value('status', 'Enabled') self.click_save_and_continue() a.set_dropdown_value('tax_class_id', 'None') a.write_textfield('price', price) self.click_save_and_continue() self.wait_for_product_saved() # Clicking reset clears the message; allowing us to assert again later # to make sure the change is made self.click_magento_button('Reset') click_link_by_title('Inventory') a.write_textfield('inventory_qty', '9999999') a.set_dropdown_value('inventory_stock_availability', 'In Stock') self.click_magento_button('Save') self.wait_for_product_saved()
get_element_by_css, go_to, wait_for, write_textfield, ) from u1testutils.sst import config from acceptance import urls config.set_base_url_from_env() go_to(urls.HOME) wait_for(assert_title, 'Log in') if email: print 'Sending e-mail' write_textfield('id_email', '*****@*****.**') if password: print 'Sending password' write_textfield('id_password', 'bogus') click_button(get_element_by_css('*[data-qa-id="ubuntu_login_button"]')) wait_for(assert_title, 'Log in') el = get_element(id='login-form') els = el.find_elements_by_class_name('error') els = [e for e in els if e.text == 'Required field.'] assert len(els) == errors
# This test ensures that changing the full name for an account works. from sst.actions import ( assert_element, click_button, get_element, go_to, write_textfield, ) from u1testutils.sst import config from acceptance import helpers, urls config.set_base_url_from_env() # Create an account and login. helpers.register_account(displayname="Fred Jones") # Update the full name and verify the title change. go_to(urls.EDIT) write_textfield('id_displayname', 'Fred Jones Jnr') click_button(get_element(name='update')) assert_element(**{'data-qa-id': 'edit_account'})
get_element, go_to, skip, write_textfield, ) from u1testutils.sst import config from acceptance import helpers, urls if not exists_element(id='recaptcha_response_field'): skip("Test skipped - no captcha present") config.set_base_url_from_env() helpers.skip_unless_staging_or_production() go_to(urls.NEW_ACCOUNT) assert_title('Create account') # explicitly don't set captcha email_address = '*****@*****.**' write_textfield('id_displayname', "My Name") write_textfield('id_email', email_address) write_textfield('id_password', "Admin007") write_textfield('id_passwordconfirm', "Admin007") # Even though the recaptcha field is ignored for our tests, we do want to # verify that it is on the page. In response to Defect #839216 we click once # before to ensure captcha is still displayed click_button(get_element(name='continue')) assert_displayed('recaptcha_response_field')
wait_for, write_textfield, ) from u1testutils import mail from u1testutils.sso import mail as sso_mail from u1testutils.sst import config from acceptance import helpers, urls config.set_base_url_from_env() NAME = 'Some Name' # Register the primary account. primary_email = helpers.register_account(displayname=NAME) # Register a secondary email, and grab the link from the email sent to # the secondary address. secondary_email = mail.make_unique_test_email_address() go_to(urls.EMAILS) wait_for(assert_title_contains, "'s email addresses") write_textfield('id_newemail', secondary_email) click_button(get_element(name='continue')) link = sso_mail.get_verification_link_for_address(secondary_email) # Follow the link from the email to ensure it verifies the secondary # address. go_to(link) click_button(get_element(name='continue')) wait_for(assert_element, **{'data-qa-id': 'edit_account'})
go_to, write_textfield, ) from u1testutils.sst import config from acceptance import helpers, urls helpers.skip_unless_staging_or_production() config.set_base_url_from_env() go_to(urls.NEW_ACCOUNT) assert_title('Create account') email_address = '*****@*****.**' write_textfield('id_displayname', "My Name") write_textfield('id_email', email_address) write_textfield('id_password', "Admin007") write_textfield('id_passwordconfirm', "Admin007") # Even though the recaptcha field is ignored for our tests, we do # want to verify that it is on the page. write_textfield('recaptcha_response_field', 'wrong answer') click_button(get_element(name='continue')) # Make sure we were returned to the form, for not answering the # Captcha correctly. assert_title('Create account') assert_element(id='recaptcha_response_field')
get_element, write_textfield, ) from u1testutils.sst import config from acceptance import helpers # Set to Production, Staging, VPS, Developer etc.. config.set_base_url_from_env() # Login so we can change the password helpers.login( settings.SSO_TEST_ACCOUNT_EMAIL, settings.SSO_TEST_ACCOUNT_PASSWORD) # Change the password on the account and logout write_textfield('id_password', new_password) write_textfield('id_passwordconfirm', new_password) click_button(get_element(name="update")) assert_element(text='Your account details have been successfully updated') click_link('logout-link') # Login with the new password helpers.login(settings.SSO_TEST_ACCOUNT_EMAIL, password=new_password) # Change the password back write_textfield('id_password', settings.SSO_TEST_ACCOUNT_PASSWORD) write_textfield('id_passwordconfirm', settings.SSO_TEST_ACCOUNT_PASSWORD) click_button(get_element(name="update")) assert_element(text='Your account details have been successfully updated')
from sst.actions import ( assert_text_contains, assert_title, assert_title_contains, click_button, get_element, go_to, wait_for, write_textfield, ) from u1testutils.sst import config from acceptance import helpers, urls config.set_base_url_from_env() # Create and verify account A helpers.register_account() # Add and verify 2nd email go_to(urls.EMAILS) wait_for(assert_title_contains, "'s email addresses") write_textfield('id_newemail', '') click_button(get_element(name='continue')) # Check for error message wait_for(assert_title, 'Add an email') assert_text_contains(get_element(name='newemailform'), 'Required field.')
def enter_otp(otp): write_textfield('id_oath_token', otp) click_button(get_element(type='submit'))
) from u1testutils.sst import config from acceptance import helpers, urls config.set_base_url_from_env() # Create an account with a specific password. initial_password = "******" email_address = helpers.register_account(displayname="Fred Jones", password=initial_password) edit_account_anchor = {'data-qa-id': 'edit_account'} # Change the password and save. go_to(urls.EDIT) new_password = "******" assert_element(**edit_account_anchor) write_textfield('id_password', new_password) write_textfield('id_passwordconfirm', new_password) click_button(get_element(name='update')) # Now try logging in with the old password - which fails. helpers.logout() helpers.login(email_address, initial_password) assert_title("Log in") # But logging in with the new password works. helpers.login(email_address, new_password) assert_element(**edit_account_anchor)
toggled_elements = ast.literal_eval(toggled_elements) disabled_elements = ast.literal_eval(disabled_elements) returned_sreg = ast.literal_eval(returned_sreg) go_to(urls.CONSUMER) wait_for(assert_title, 'Django OpenID Example Consumer') toggle_checkbox('id_sreg') set_radio_value(radio_nickname) 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'),
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)
from u1testutils.sst import config from acceptance import helpers, urls config.set_base_url_from_env() go_to(urls.NEW_ACCOUNT) assert_title('Create account') email_address = mail.make_unique_test_email_address() helpers.fill_registration_form(email_address) click_button(get_element(name='continue')) if 'allow_unverified' not in sst_config.flags: assert_title_contains('Account creation mail sent') assert_text_contains( get_element(id='content'), r'just emailed .* \(from .*\) to confirm your address\.', regex=True) vcode = sso_mail.get_verification_code_for_address(email_address) write_textfield(get_element(name='confirmation_code'), vcode) click_button(get_element(css_class='btn')) # We know that the confirmation code worked if we are now looking at the # logged-in details page for the user. wait_for(assert_element, **{'data-qa-id': 'edit_account'})
# Logout and back in so we are no longer 2f-authenticated helpers.logout_and_in() # Click on "Add a new authentication device" link click_add_new_device_link() # Authenticate with the first device authenticate('add_two_devices') # Choose "Generic HOTP device" and click add device set_radio_value('type_generic') click_add_device_button() # Add a name for the second device write_textfield(get_element(tag='input', name='name'), 'add_two_devices') # Enter OTP aes_key_2 = get_element(name='hex_key').get_attribute('value') store_device('add_two_devices (1)', aes_key_2) otp_2 = hotp.hotp(aes_key_2, 0) write_textfield(get_element(tag='input', name='otp'), otp_2) # Click "Add device" click_add_device_button() # Check we are returned to the devices-list page assert_url(urls.DEVICES) # Check our new device is now in the table, with the correct name assert_table_has_rows('device-list', 2) # FIXME: remove when sorting is consistent
from u1testutils.sst import config config.set_base_url_from_env() edit_account_anchor = {'data-qa-id': 'edit_account'} # Create an account and logout. email_address = helpers.register_account(displayname="Fred Jones", verify=True) helpers.logout() # Request the password reset. go_to(urls.HOME) assert_title('Log in') click_link('forgotpw-link') write_textfield('id_email', email_address) # Even though the recaptcha field is ignored for our tests, we do # want to verify that it is on the page. write_textfield('recaptcha_response_field', 'ignored') click_button(get_element(name='continue')) assert_element(**{'data-qa-id': 'forgot_password_step_2'}) # Fetch and verify the confirmation link. link = mail.get_verification_link_for_address(email_address) go_to(link) # Reset the password and verify that we're logged in. assert_title('Reset password') write_textfield('id_password', "Other008") write_textfield('id_passwordconfirm', "Other008")
# vi:si:et:sw=4:sts=4:ts=4 from sst import actions as a import common import data common.go_to() a.assert_title_contains('Home page') user = common.User(data.user) user.login() # search for tv a.write_textfield('search', 'tv') common.click_button_by_title('Search') # click it common.click_button_by_title('Add to Cart', multiple=True) common.click_button_by_title('Proceed to Checkout', multiple=True) a.wait_for(a.assert_displayed, 'checkout-step-billing') a.click_button(a.get_element_by_xpath( "//div[@id='checkout-step-billing']" "//button[@title='Continue']")) # in 1.4 it doesn't automatically proceed to shipping method # because Use Billing Address is not active