def _check_vm_provision(self, mgmt_sys_api_clients, provider_key, vm_name): ''' Waits for provision, allows startup, and then deletes provisioned vm/instance''' count = 0 while (count <= 600): try: vm_running = mgmt_sys_api_clients[provider_key]\ .is_vm_running(vm_name) if vm_running: mgmt_sys_api_clients[provider_key].stop_vm(vm_name) time.sleep(30) break except: pass time.sleep(60) count += 60 if count > 600: # We are going to need to see how this goes, I have seen some requests # take 20 minutes to approve. # # TODO: We probably should be watching the request status vs time counting Assert.fail("vm never provisioned after 10 minutes") Assert.true(mgmt_sys_api_clients[provider_key].is_vm_stopped(vm_name), "vm never stopped") # cleanup/delete provisioned vm count = 0 while (count <= 600): vm_stopped = mgmt_sys_api_clients[provider_key]\ .is_vm_stopped(vm_name) if vm_stopped: mgmt_sys_api_clients[provider_key].delete_vm(vm_name) break time.sleep(60) count += 60
def test_hide_email_checkbox_works(self, mozwebqa): home_page = Home(mozwebqa) home_page.login("browserID") Assert.true(home_page.is_the_current_page) Assert.true(home_page.header.is_user_logged_in) view_profile_page = home_page.header.click_view_profile() initial_state = view_profile_page.is_email_field_present edit_profile_page = home_page.header.click_edit_profile() edit_profile_page.change_hide_email_state() edit_profile_page.click_update_account() view_profile_page = home_page.header.click_view_profile() final_state = view_profile_page.is_email_field_present try: Assert.not_equal(initial_state, final_state, 'The initial and final states are the same. The profile change failed.') if final_state is True: credentials = mozwebqa.credentials['default'] Assert.equal(credentials['email'], view_profile_page.email_value, 'Actual value is not equal with the expected one.') except Exception as exception: Assert.fail(exception.msg) finally: if initial_state != final_state: edit_profile_page = home_page.header.click_edit_profile() edit_profile_page.change_hide_email_state() edit_profile_page.click_update_account() view_profile_page = home_page.header.click_view_profile() Assert.equal(view_profile_page.is_email_field_present, initial_state, 'Could not restore profile to initial state.')
def test_that_server_status_page_loads(self, mozwebqa): csp = CrashStatsHomePage(mozwebqa) csstat = csp.click_server_status() try: csstat.at_a_glance() except Exception, e: Assert.fail(str(e))
def test_user_can_edit_page(self, mozwebqa): _edit_text_entered = 'MozWebQA Edit page wiki-test - ' + str(time.time()) home_pg = HomePage(mozwebqa) home_pg.go_to_home_page() home_pg.personal_tools_region.click_log_in_or_create_account() log_in_or_create_account_pg = LogInOrCreateAccountPage(mozwebqa) log_in_or_create_account_pg.log_in() Assert.true(home_pg.is_the_current_page) Assert.true(home_pg.personal_tools_region.is_user_page_visible) home_pg.personal_tools_region.click_user_page() if home_pg.header_region.is_edit_visible: edit_pg = home_pg.header_region.click_edit() Assert.true(edit_pg.is_edit_page_textarea_present) edit_pg.enter_edit_textarea_text(_edit_text_entered) Assert.true(edit_pg.is_edit_page_save_button_present) edit_pg.click_save_button() Assert.true(edit_pg.is_user_entered_text_saved_and_present) Assert.equal(edit_pg.get_user_entered_text, _edit_text_entered) else: Assert.fail("Error - you don't have privileges to edit this page.")
def test_that_purchases_an_app_without_pre_auth_and_requests_a_refund(self, mozwebqa): """Litmus 58166""" user = MockUser() home_page = Home(mozwebqa) home_page.go_to_homepage() home_page.create_new_user(user) home_page.login(user) Assert.true(home_page.is_the_current_page) search_page = home_page.header.search(self._app_name) Assert.true(search_page.is_the_current_page) Assert.not_equal("FREE", search_page.results[0].price) details_page = search_page.results[0].click_name() Assert.true(details_page.is_app_available_for_purchase) pre_aproval_region = details_page.click_purchase() paypal_frame = pre_aproval_region.click_one_time_payment() paypal_popup = paypal_frame.login_to_paypal() Assert.true(paypal_popup.is_user_logged_into_paypal) try: # From this point on we have payed for the app so we have to request a refund paypal_popup.click_pay() paypal_popup.close_paypal_popup() Assert.true(details_page.is_app_installing) except Exception as exception: Assert.fail(exception) finally: self.request_refund_procedure(mozwebqa, self._app_name)
def create_catalog_item( maximized, random_string, provisioning_data, setup_infrastructure_providers, create_service_dialog, svc_catalogs_pg, create_catalog, ): """Fixture to create Catalog item and bundle""" service_dialog_name = create_service_dialog catalog_name = create_catalog new_cat_item_pg = svc_catalogs_pg.click_on_catalog_item_accordion().add_new_catalog_item() new_cat_item_pg.choose_catalog_item_type("VMware") catalog_item_name = "auto_item_" + random_string new_cat_item_pg.fill_basic_info(catalog_item_name, "item_desc_" + random_string, catalog_name, service_dialog_name) req_pg = new_cat_item_pg.click_on_request_info_tab() vm_name = "vm_name" + random_string req_pg.fill_catalog_tab(provisioning_data["template"], vm_name) envt_pg = req_pg.click_on_environment_tab() try: envt_pg.fill_environment_tab(unicode(provisioning_data["host"]), unicode(provisioning_data["datastore"])) except: Assert.fail("Unable to create catalog item, " + "check for duplicate infra providers") names = [service_dialog_name, catalog_name, catalog_item_name, provisioning_data["provider_key"], vm_name] return names
def force_wait(self, wait_time): try: time.sleep(int(wait_time)) except TimeoutException: Assert.fail(TimeoutException) finally: self.selenium.implicitly_wait(self.testsetup.default_implicit_wait)
def test_user_can_edit_page(self, mozwebqa): _edit_text_entered = 'MozWebQA Edit page wiki-test - ' + str( time.time()) home_pg = HomePage(mozwebqa) home_pg.go_to_home_page() home_pg.personal_tools_region.click_log_in_or_create_account() log_in_or_create_account_pg = LogInOrCreateAccountPage(mozwebqa) log_in_or_create_account_pg.log_in() Assert.true(home_pg.is_the_current_page) Assert.true(home_pg.personal_tools_region.is_user_page_visible) home_pg.personal_tools_region.click_user_page() if home_pg.header_region.is_edit_visible: edit_pg = home_pg.header_region.click_edit() Assert.true(edit_pg.is_edit_page_textarea_present) edit_pg.enter_edit_textarea_text(_edit_text_entered) Assert.true(edit_pg.is_edit_page_save_button_present) edit_pg.click_save_button() Assert.true(edit_pg.is_user_entered_text_saved_and_present) Assert.equal(edit_pg.get_user_entered_text, _edit_text_entered) else: Assert.fail("Error - you don't have privileges to edit this page.")
def _check_vm_provision(self, mgmt_sys_api_clients, provider_key, vm_name): """ Waits for provision, allows startup, and then deletes provisioned vm/instance""" count = 0 while count <= 600: try: vm_running = mgmt_sys_api_clients[provider_key].is_vm_running(vm_name) if vm_running: mgmt_sys_api_clients[provider_key].stop_vm(vm_name) time.sleep(30) break except: pass time.sleep(60) count += 60 if count > 600: # We are going to need to see how this goes, I have seen some requests # take 20 minutes to approve. # # TODO: We probably should be watching the request status vs time counting Assert.fail("vm never provisioned after 10 minutes") Assert.true(mgmt_sys_api_clients[provider_key].is_vm_stopped(vm_name), "vm never stopped") # cleanup/delete provisioned vm count = 0 while count <= 600: vm_stopped = mgmt_sys_api_clients[provider_key].is_vm_stopped(vm_name) if vm_stopped: mgmt_sys_api_clients[provider_key].delete_vm(vm_name) break time.sleep(60) count += 60
def test_that_purchases_an_app_without_pre_auth_and_requests_a_refund(self, mozwebqa): """Litmus 58166""" home_page = Home(mozwebqa) home_page.go_to_homepage() home_page.login() Assert.true(home_page.is_the_current_page) search_page = home_page.header.search(self._app_name) Assert.true(search_page.is_the_current_page) Assert.not_equal("FREE", search_page.results[0].price) details_page = search_page.results[0].click_name() Assert.true(details_page.is_app_available_for_purchase) pre_approval_region = details_page.click_purchase() paypal_frame = pre_approval_region.click_one_time_payment() paypal_popup = paypal_frame.login_to_paypal() Assert.true(paypal_popup.is_user_logged_into_paypal) try: # From this point on we have payed for the app so we have to request a refund paypal_popup.click_pay() paypal_popup.close_paypal_popup() Assert.true(details_page.is_app_installing) except Exception as exception: Assert.fail(exception) finally: self.request_refund_procedure(mozwebqa, self._app_name)
def create_catalog_item(maximized, random_string, provisioning_data, setup_infrastructure_providers, create_service_dialog, svc_catalogs_pg, create_catalog): '''Fixture to create Catalog item and bundle''' service_dialog_name = create_service_dialog catalog_name = create_catalog new_cat_item_pg = svc_catalogs_pg.click_on_catalog_item_accordion().\ add_new_catalog_item() new_cat_item_pg.choose_catalog_item_type('VMware') catalog_item_name = "auto_item_" + random_string new_cat_item_pg.fill_basic_info(catalog_item_name, "item_desc_" + random_string, catalog_name, service_dialog_name) req_pg = new_cat_item_pg.click_on_request_info_tab() vm_name = "vm_name" + random_string req_pg.fill_catalog_tab(provisioning_data["template"], vm_name) envt_pg = req_pg.click_on_environment_tab() try: envt_pg.fill_environment_tab(unicode(provisioning_data["host"]), unicode(provisioning_data["datastore"])) except: Assert.fail("Unable to create catalog item, " + "check for duplicate infra providers") names = [ service_dialog_name, catalog_name, catalog_item_name, provisioning_data["provider_key"], vm_name ] return names
def wait_for_element_not_present(self, *locator): self.selenium.implicitly_wait(0) try: WebDriverWait(self.selenium, 10).until(lambda s: len(self._selenium_root.find_elements(*locator)) < 1) except TimeoutException: Assert.fail(TimeoutException) finally: self.selenium.implicitly_wait(self.testsetup.default_implicit_wait)
def test_that_server_status_page_loads(self, testsetup): self.selenium = testsetup.selenium csp = CrashStatsHomePage(testsetup) csstat = csp.click_server_status() try: csstat.at_a_glance() except Exception, e: Assert.fail(str(e))
def test_hosted_app_submission(self, mozwebqa): app = MockApplication() dev_home = Home(mozwebqa) dev_home.go_to_developers_homepage() dev_home.login(user="******") my_apps = dev_home.header.click_my_submissions() dev_agreement = my_apps.click_submit_new_app() """Agree with the developer agreement and continue if it was not accepted in a previous app submit""" manifest_validation_form = dev_agreement.click_continue() # select device type for device in app['device_type']: if device[1]: manifest_validation_form.device_type(device[0]) # submit the app manifest url and validate it manifest_validation_form.type_app_manifest_url(app['url']) manifest_validation_form.click_validate() Assert.true(manifest_validation_form.app_validation_status, msg=manifest_validation_form.app_validation_message) app_details = manifest_validation_form.click_continue() Assert.true(app_details.is_the_current_submission_stage, '\n Expected step is: Details \n Actual step is: %s' % app_details.current_step) # add custom app details for every field app_details.click_change_name() app_details.type_url_end(app['url_end']) app_details.type_description(app['description']) app_details.type_privacy_policy(app['privacy_policy']) app_details.type_homepage(app['homepage']) app_details.type_support_url(app['support_website']) app_details.type_support_email(app['support_email']) for category in app['categories']: # check/uncheck the checkbox according to the app value app_details.select_categories(*category) app_details.screenshot_upload(app['screenshot_link']) try: next_steps = app_details.click_continue() Assert.equal('Almost There!', next_steps.almost_there_message) content_ratings = next_steps.click_continue() Assert.equal('Get My App Rated', content_ratings.get_app_rated_message) except Exception as exception: Assert.fail(exception) finally: # Clean up app edit_app = dev_home.go_to_apps_status_page(app) delete_popup = edit_app.click_delete_app() return delete_popup.delete_app()
def log_in(self, username, password): self.selenium.find_element(*self._username_box_locator).send_keys(username) self.selenium.find_element(*self._password_box_locator).send_keys(password) self.selenium.find_element(*self._log_in_button_locator).click() if not self.header.is_user_logged_in: error = self.selenium.find_element(*self._login_error_locator).text error = "login failed for %s\n" % username + error Assert.fail(error)
def wait_for_element_not_present(self, *locator): self.selenium.implicitly_wait(0) try: WebDriverWait(self.selenium, self.timeout).until( lambda s: len(self._selenium_root.find_elements(*locator)) < 1) except TimeoutException: Assert.fail(TimeoutException) finally: self.selenium.implicitly_wait(self.testsetup.default_implicit_wait)
def wait_for_ajax(self): self.selenium.implicitly_wait(0) try: WebDriverWait(self.selenium, self.timeout).until( lambda s: s.execute_script('return $.active == 0')) except TimeoutException: Assert.fail('wait for AJAX timed out after %s seconds' % self.timeout) finally: self.selenium.implicitly_wait(self.testsetup.default_implicit_wait)
def _wait_for_element_not_present(self, selector): """Wait for an element to become not present.""" try: WebDriverWait(self.driver, TIMEOUT).until( EC.invisibility_of_element_located(selector)) # WebDriverWait(self.driver, timeout).until(lambda s: len(self.driver.find_elements(*selector)) < 1) return True except TimeoutException: Assert.fail(TimeoutException)
def _wait_for_element_present(self, selector): """Wait for an element to become present.""" try: WebDriverWait(self.driver, TIMEOUT).until( EC.visibility_of_element_located(selector)) except TimeoutException: Assert.fail(TimeoutException) finally: # set back to where you once belonged self.driver.implicitly_wait(DRIVER_TIMEOUT)
def wait_for_element_to_be_visible(self, *locator): """Wait for an element to become visible""" self.selenium.implicitly_wait(0) try: WebDriverWait(self.selenium, self.timeout).until( lambda s: self._selenium_root.find_element(*locator).is_displayed()) except TimeoutException: Assert.fail(TimeoutException) finally: self.selenium.implicitly_wait(self.testsetup.default_implicit_wait)
def wait_for_element_not_present(self, *locator): """Wait for the element at the specified locator to be not present in the DOM.""" self.selenium.implicitly_wait(0) try: WebDriverWait(self.selenium, self.timeout).until(lambda s: len(self.find_elements(*locator)) < 1) return True except TimeoutException: Assert.fail(TimeoutException) finally: self.selenium.implicitly_wait(self.testsetup.default_implicit_wait)
def wait_for_element_present(self, *locator): """Wait for an element to become present.""" self.selenium.implicitly_wait(0) try: WebDriverWait(self.selenium, 10).until(lambda s: self._selenium_root.find_element(*locator)) except TimeoutException: Assert.fail(TimeoutException) finally: # set back to where you once belonged self.selenium.implicitly_wait(self.testsetup.default_implicit_wait)
def _head_request(self, url, user_agent=_user_agent_firefox, locale='en-US', params=None): headers = {'user-agent': user_agent, 'accept-language': locale} try: return requests.head(url, headers=headers, verify=False, timeout=15, params=params, allow_redirects=True) except requests.RequestException as e: request_url = self._build_request_url(url, params) Assert.fail('Failing URL: %s.\nError message: %s' % (request_url, e))
def __find_user(self, name=None, emailAddr=None, role=None): #local locators _locUserName = (By.CSS_SELECTOR, "h3.title") _locUserEmail = (By.CSS_SELECTOR, "div.email") _locUserRole = (By.CSS_SELECTOR, "ul.roles") #move to the user page self.__move_to_user_page() #[M] acquire the list of users try: elmntUserList = WebDriverWait(self.selenium,self._TimeOut). \ until(lambda s: self.find_elements(*self._locUserList)) except Exceptions.TimeoutException: Assert.fail(Exceptions.TimeoutException) #failed to obtain a list of users #[M] review the contents of the submission isGivenUserFound = False for i in range(len(elmntUserList)): try: element = elmntUserList[i] #elements userName = WebDriverWait(self.selenium,self._TimeOut). \ until(lambda s: element.find_element(*_locUserName)) userEmail = WebDriverWait(self.selenium,self._TimeOut). \ until(lambda s: element.find_element(*_locUserEmail)) userRole = WebDriverWait(self.selenium,self._TimeOut). \ until(lambda s: element.find_element(*_locUserRole)) #texts userName_text = userName.text userEmail_text = userEmail.text userRole_text = userRole.text #check the attributes isNameMatched = False if name != None and name == userName_text: isNameMatched = True isEmailMatched = False if emailAddr != None and emailAddr == userEmail_text: isEmailMatched = True isRoleMatched = False if role != None and role == userRole_text: isRoleMatched = True isGivenUserFound = isNameMatched if isGivenUserFound == True: break except Exceptions.TimeoutException: print "let us move on..\n" #post-processing if isGivenUserFound == False: element = None return element
def log_in(self, user='******'): credentials = self.testsetup.credentials[user] self.selenium.find_element(*self._username_box_locator).send_keys(credentials['name']) self.selenium.find_element(*self._password_box_locator).send_keys(credentials['password']) self.selenium.find_element(*self._log_in_button_locator).click() if not self.header.is_user_logged_in: error = self.selenium.find_element(*self._login_error_locator).text error = "login failed for %s\n" % credentials['name'] + error Assert.fail(error)
def wait_for_element_to_be_visible(self, *locator): """Wait for an element to become visible""" self.selenium.implicitly_wait(0) try: WebDriverWait( self.selenium, self.timeout).until(lambda s: self._selenium_root.find_element( *locator).is_displayed()) except TimeoutException: Assert.fail(TimeoutException) finally: self.selenium.implicitly_wait(self.testsetup.default_implicit_wait)
def wait_for_attribute_value(self, attribute, attribute_text, locator, max_count=20, delay=0.25): """ Waits for element attribute value to match specified text, until certain deadline """ element = self.driver.find_element(*locator) counter = 0 while element.get_attribute(attribute) != attribute_text: if counter < max_count: time.sleep(delay) counter += 1 else: Assert.fail('"' + attribute_text + '" text did not match "' + element.get_attribute(attribute) + '" after ' + str(counter * delay) + ' seconds') break
def wait_for_text_to_match(self, text, locator, max_count=20, delay=0.25): """ Waits for element text to match specified text, until certain deadline """ element = self.driver.find_element(*locator) counter = 0 while element.text != text: if counter < max_count: time.sleep(delay) counter += 1 else: Assert.fail('"' + text + '" text did not match "' + element.text + '" after ' + str(counter * delay) + ' seconds') break
def wait_for_element_not_present(self, locator, timeout=None): """ Wait for the element at the specified locator not to be present in the DOM. """ timeout = timeout or self.timeout self.driver.implicitly_wait(0) try: WebDriverWait(self.driver, timeout).until(lambda s: len(self.find_elements(*locator)) < 1) return True except TimeoutException: Assert.fail(TimeoutException) finally: self.driver.implicitly_wait(self.default_implicit_wait)
def test_that_snippets_are_well_formed_xml(self, mozwebqa, path): if 'snippets.mozilla.com' not in mozwebqa.base_url: pytest.skip('Only test well formedness on production.') full_url = mozwebqa.base_url + path r = self._get_redirect(full_url) try: dom = parseString(r.content) except ExpatError as e: Assert.fail('Snippets at %s do not contain well formed xml. %s' % (full_url, e.message))
def log_in(self, user='******'): credentials = self.testsetup.credentials[user] self.selenium.find_element(*self._username_box_locator).send_keys( credentials['name']) self.selenium.find_element(*self._password_box_locator).send_keys( credentials['password']) self.selenium.find_element(*self._log_in_button_locator).click() if not self.header.is_user_logged_in: error = self.selenium.find_element(*self._login_error_locator).text error = "login failed for %s\n" % credentials['name'] + error Assert.fail(error)
def test_that_user_can_remove_prepapproval_on_payment_settings_page(self, mozwebqa): # We have to first login to paypal developer to access the paypal sandbox developer_paypal_page = PayPal(mozwebqa) developer_paypal_page.go_to_page() developer_paypal_page.login_paypal(user="******") Assert.true(developer_paypal_page.is_user_logged_in) # Now we start to test the marketplace pages home_page = Home(mozwebqa) home_page.go_to_homepage() home_page.login(user="******") Assert.true(home_page.is_the_current_page) Assert.true(home_page.footer.is_user_logged_in) # go to Payment Settings page settings_page = home_page.footer.click_account_settings() Assert.true(settings_page.is_the_current_page) payment_settings_page = settings_page.click_payment_menu() Assert.true(payment_settings_page.is_the_current_page) Assert.equal('Payment Settings', payment_settings_page.header_title) try: # verify that pre-approval is active Assert.true(payment_settings_page.is_remove_pre_approval_button_visible, "Remove pre-approval button is not available. Pre-approval might be off") # remove pre-approval payment_settings_page.click_remove_pre_approval() Assert.false(payment_settings_page.is_remove_pre_approval_button_visible, "Remove pre-approval button is visible after click_remove_pre_approval") Assert.false(payment_settings_page.is_pre_approval_enabled, "Pre-approval is still enabled") Assert.true(payment_settings_page.is_success_message_visible, "Success message is not visible") except Exception as exception: Assert.fail(exception) finally: # restore the account to the initial state # logging in to paypal sandbox paypal_sandbox = payment_settings_page.click_set_up_pre_approval() paypal_sandbox.click_login_tab() Assert.true(paypal_sandbox.is_login_box_visible, "sandbox login form is not visible") paypal_sandbox.login_paypal_sandbox(user="******") Assert.true(paypal_sandbox.is_user_logged_in) # From this point on we have set up the pre-approval and need to remove this option after we check it paypal_sandbox.click_approve_button() Assert.true(payment_settings_page.is_pre_approval_enabled) Assert.true(payment_settings_page.is_success_message_visible)
def wait_for_element_not_present(self, locator, timeout=None): """ Wait for the element at the specified locator not to be present in the DOM. """ if timeout is None: timeout = self.timeout self.driver.implicitly_wait(0) try: WebDriverWait(self.driver, timeout).until( lambda s: len(self.find_elements(*locator)) < 1) return True except TimeoutException: Assert.fail(TimeoutException) finally: self.driver.implicitly_wait(self.default_implicit_wait)
def test_that_user_can_set_up_pre_approval_on_payment_settings_page(self, mozwebqa): """ Test for Litmus 58172. https://litmus.mozilla.org/show_test.cgi?id=58172 """ # We have to first login to paypal developer to access the paypal sandbox developer_paypal_page = PayPal(mozwebqa) developer_paypal_page.go_to_page() developer_paypal_page.login_paypal(user="******") Assert.true(developer_paypal_page.is_user_logged_in) # Now we start to test the marketplace pages home_page = Home(mozwebqa) home_page.go_to_homepage() home_page.login(user="******") Assert.true(home_page.is_the_current_page) Assert.true(home_page.footer.is_user_logged_in) # go to Payment Settings page settings_page = home_page.footer.click_account_settings() Assert.true(settings_page.is_the_current_page) payment_settings_page = settings_page.click_payment_menu() Assert.equal('Payment Settings', payment_settings_page.header_title) # logging in to paypal sandbox paypal_sandbox = payment_settings_page.click_set_up_pre_approval() paypal_sandbox.click_login_tab() Assert.true(paypal_sandbox.is_login_box_visible, "sandbox login form is not visible") paypal_sandbox.login_paypal_sandbox(user="******") Assert.true(paypal_sandbox.is_user_logged_in) try: # From this point on we have set up the pre-approval and need to remove this option after we check it paypal_sandbox.click_approve_button() Assert.true(payment_settings_page.is_pre_approval_enabled) Assert.true(payment_settings_page.is_success_message_visible) except Exception as exception: Assert.fail(exception) finally: if payment_settings_page.is_remove_pre_approval_button_visible: payment_settings_page.click_remove_pre_approval() Assert.false(payment_settings_page.is_remove_pre_approval_button_visible)
def test_all_links(self, mozwebqa, path): full_url = mozwebqa.base_url + path soup = self._parse_response(self._get_redirect(full_url).content) snippet_links = soup.select("a") Assert.greater(len(snippet_links), 0, "No links found") for link in snippet_links: try: r = self._get_redirect(link['href']) except: Assert.fail("Failed to get URL %s , check its validity" % link['href']) Assert.equal(r.status_code, requests.codes.ok, "Bad URL %s found in %s" %(link['href'], path))
def test_that_selecting_exact_version_doesnt_show_other_versions(self, seleniumsetup): self.selenium = seleniumsetup.selenium csp = CrashStatsHomePage(self.selenium) details = csp.current_details if len(details['versions']) > 0: csp.select_version(details['versions'][1]) Assert.equal(details['product'] + ' ' + details['versions'][1],csp.right_column_heading) try: centre_name = csp.centre_column_heading Assert.fail(centre_name + ' was shown when it shouldnt be there') except Exception, e: pass
def test_user_can_update_profile_information_in_account_settings_page( self, mozwebqa): """ Test for Litmus 11563. https://litmus.mozilla.org/show_test.cgi?id=11563 """ home_page = Home(mozwebqa) home_page.login(method="browserID", user="******") Assert.true(home_page.is_the_current_page) Assert.true(home_page.header.is_user_logged_in) user_edit_page = home_page.header.click_edit_profile() Assert.true(user_edit_page.is_the_current_page) # save initial values to restore them after the test is finished fields_no = len(user_edit_page.profile_fields) - 1 initial_value = [None] * fields_no random_name = "test%s" % random.randrange(1, 100) # enter new values for i in range(0, fields_no): initial_value[i] = deepcopy( user_edit_page.profile_fields[i].field_value) user_edit_page.profile_fields[i].clear_field() user_edit_page.profile_fields[i].type_value(random_name) user_edit_page.click_update_account() Assert.equal(user_edit_page.update_message, "Profile Updated") # using try finally to ensure that the initial values are restore even if the Asserts fail. try: for i in range(0, fields_no): Assert.contains(random_name, user_edit_page.profile_fields[i].field_value) except Exception as exception: Assert.fail(exception.msg) finally: # restore initial values for i in range(0, fields_no): user_edit_page.profile_fields[i].clear_field() user_edit_page.profile_fields[i].type_value(initial_value[i]) user_edit_page.click_update_account()
def __move_to_user_page(self): #[H] click the "Manage" tab try: element = WebDriverWait(self.selenium,self._TimeOut). \ until(lambda s: self.find_element(*self._locManageTab)) except Exceptions.TimeoutException: Assert.fail(Exceptions.TimeoutException) element.click() #[H] click the "Users" tab try: element = WebDriverWait(self.selenium,self._TimeOut). \ until(lambda s: self.find_element(*self._locUsersTab)) except Exceptions.TimeoutException: Assert.fail(Exceptions.TimeoutException) element.click()
def test_that_filter_for_browser_results(self, mozwebqa): #https://www.pivotaltracker.com/story/show/17769047 csp = CrashStatsHomePage(mozwebqa) cs_advanced = csp.header.click_advanced_search() cs_advanced.adv_select_product('Firefox') cs_advanced.adv_select_version('Firefox 13.0a2') cs_advanced.adv_select_os('Windows') cs_advanced.select_radio_button(1) cs_advanced.filter_reports() while not cs_advanced.is_browser_icon_present: try: cs_advanced.click_next() except: Assert.fail('reached the last page and no data was found') Assert.true(cs_advanced.is_browser_icon_visible, cs_advanced.get_url_current_page())
def test_that_filter_for_browser_results(self, mozwebqa): #https://www.pivotaltracker.com/story/show/17769047 csp = CrashStatsHomePage(mozwebqa) cs_advanced = csp.header.click_advanced_search() cs_advanced.adv_select_product('Firefox') cs_advanced.adv_select_version('Firefox 11.0a2') cs_advanced.adv_select_os('Windows') cs_advanced.select_radio_button(1) cs_advanced.filter_reports() while not cs_advanced.is_browser_icon_present: try: cs_advanced.click_next() except: Assert.fail('reached the last page and no data was found') Assert.true(cs_advanced.is_browser_icon_visible, cs_advanced.get_url_current_page())
def test_that_searching_returns_results(self, mozwebqa): home_page = Home(mozwebqa) home_page.go_to_homepage() details_page = home_page.go_to_first_free_app_page() search_term = details_page.title details_page.header.click_back() search_page = home_page.header.search(search_term) results = search_page.results() Assert.greater(len(results), 0) # Check that the results contains the search term for i in range(len(results)): if search_term == results[i].name: return Assert.fail('The search results did not include the app: %s' % search_term)
def test_user_can_update_profile_information_in_account_settings_page(self, mozwebqa): """ Test for Litmus 11563. https://litmus.mozilla.org/show_test.cgi?id=11563 """ home_page = Home(mozwebqa) home_page.login(method="browserID", user="******") Assert.true(home_page.is_the_current_page) Assert.true(home_page.header.is_user_logged_in) user_edit_page = home_page.header.click_edit_profile() Assert.true(user_edit_page.is_the_current_page) # save initial values to restore them after the test is finished fields_no = len(user_edit_page.profile_fields) - 1 initial_value = [None] * fields_no random_name = "test%s" % random.randrange(1, 100) # enter new values for i in range(0, fields_no): initial_value[i] = deepcopy(user_edit_page.profile_fields[i].field_value) user_edit_page.profile_fields[i].clear_field() user_edit_page.profile_fields[i].type_value(random_name) user_edit_page.click_update_account() Assert.equal(user_edit_page.update_message, "Profile Updated") # using try finally to ensure that the initial values are restore even if the Asserts fail. try: for i in range(0, fields_no): Assert.contains(random_name, user_edit_page.profile_fields[i].field_value) except Exception as exception: Assert.fail(exception.msg) finally: # restore initial values for i in range(0, fields_no): user_edit_page.profile_fields[i].clear_field() user_edit_page.profile_fields[i].type_value(initial_value[i]) user_edit_page.click_update_account()
def test_hide_email_checkbox_works(self, mozwebqa): home_page = Home(mozwebqa) home_page.login("browserID") Assert.true(home_page.is_the_current_page) Assert.true(home_page.header.is_user_logged_in) view_profile_page = home_page.header.click_view_profile() initial_state = view_profile_page.is_email_field_present edit_profile_page = home_page.header.click_edit_profile() edit_profile_page.change_hide_email_state() edit_profile_page.click_update_account() view_profile_page = home_page.header.click_view_profile() final_state = view_profile_page.is_email_field_present try: Assert.not_equal( initial_state, final_state, 'The initial and final states are the same. The profile change failed.' ) if final_state is True: credentials = mozwebqa.credentials['default'] Assert.equal( credentials['email'], view_profile_page.email_value, 'Actual value is not equal with the expected one.') except Exception as exception: Assert.fail(exception.msg) finally: if initial_state != final_state: edit_profile_page = home_page.header.click_edit_profile() edit_profile_page.change_hide_email_state() edit_profile_page.click_update_account() view_profile_page = home_page.header.click_view_profile() Assert.equal(view_profile_page.is_email_field_present, initial_state, 'Could not restore profile to initial state.')
def test_edit_profile_fields(self, mozwebqa): home_page = Home(mozwebqa) home_page.login() profile_page = home_page.header.click_profile() user_edit_page = profile_page.click_edit_profile() Assert.true(user_edit_page.is_the_current_page) # save initial values to restore them after the test is finished fields_no = len(user_edit_page.profile_fields) initial_value = [None] * fields_no random_name = "test%s" % random.choice(string.lowercase) # enter new values for i in range(0, fields_no): initial_value[i] = deepcopy( user_edit_page.profile_fields[i].field_value) user_edit_page.profile_fields[i].clear_field() user_edit_page.profile_fields[i].type_value(random_name) user_edit_page.click_save_profile() Assert.true(profile_page.is_update_message_visible) profile_page.click_edit_profile() # using try finally to ensure that the initial values are restore even if the Asserts fail. try: for i in range(0, fields_no): Assert.contains(random_name, user_edit_page.profile_fields[i].field_value) except Exception as exception: Assert.fail(exception) finally: # go back and restore initial values for i in range(0, fields_no): user_edit_page.profile_fields[i].clear_field() user_edit_page.profile_fields[i].type_value(initial_value[i]) user_edit_page.click_save_profile()
def test_that_checks_apps_are_sorted_by_date(self, mozwebqa): dev_home = Home(mozwebqa) dev_home.go_to_developers_homepage() dev_home.login(user="******") dev_submissions = dev_home.header.click_my_apps() dev_submissions.sorter.sort_by('Created') incomplete_apps = False import time previous_app_date = time.gmtime() for i in range(1, dev_submissions.paginator.total_page_number): for app in dev_submissions.submitted_apps: if app.is_incomplete: incomplete_apps = True else: if not incomplete_apps: Assert.greater_equal(previous_app_date, app.date, 'Apps are not sorted ascending. According to Created date.') else: Assert.fail('Apps with a finished submission process are found after apps with the submission process unfinished') dev_submissions.paginator.click_next_page()
def _head_request(self, url, user_agent=_user_agent_firefox, locale='en-US', params=None): headers = { 'user-agent': user_agent, 'accept-language': locale, 'Connection': 'close' } try: r = requests.head(url, headers=headers, verify=False, timeout=15, params=params, allow_redirects=False) except requests.RequestException as e: request_url = self._build_request_url(url, params) Assert.fail('Failing URL: %s.\nError message: %s' % (request_url, e)) if r.status_code == 302 and r.headers['Location']: try: request_url = r.headers['Location'] r = requests.head(request_url, headers=headers, verify=False, timeout=15, allow_redirects=True) except requests.RequestException as e: Assert.fail('Failing URL: %s.\nError message: %s' % (request_url, e)) return r
def test_hosted_paid_app_submission(self, mozwebqa_devhub_logged_in): if '-dev.allizom' in mozwebqa_devhub_logged_in.base_url: env = 'dev' else: env = 'stage' app = MockApplication(env) dev_home = Home(mozwebqa_devhub_logged_in) dev_agreement = dev_home.click_submit_new_app() """Agree with the developer agreement and continue if it was not accepted in a previous app submit""" manifest_validation_form = dev_agreement.click_continue() # select a premium manifest_validation_form.premium_type('paid') # select device type for device in app['device_type']: if device[1]: manifest_validation_form.device_type(device[0], 'paid') # submit the app manifest url and validate it manifest_validation_form.type_app_manifest_url(app['url']) manifest_validation_form.click_validate() Assert.true(manifest_validation_form.app_validation_status, msg=manifest_validation_form.app_validation_message) try: app_details = manifest_validation_form.click_continue() Assert.true(app_details.is_the_current_submission_stage, '\n Expected step is: Details \n Actual step is: %s' % app_details.current_step) # add custom app details for every field app_details.click_change_name() app_details.type_url_end(app['url_end']) app_details.type_description(app['description']) app_details.type_privacy_policy(app['privacy_policy']) app_details.type_homepage(app['homepage']) app_details.type_support_url(app['support_website']) app_details.type_support_email(app['support_email']) for category in app['categories']: # check/uncheck the checkbox according to the app value app_details.select_categories(*category) app_details.screenshot_upload(app['screenshot_link']) next_steps = app_details.click_continue() Assert.equal('Almost There!', next_steps.almost_there_message) content_ratings = next_steps.click_continue() Assert.equal('Get My App Rated', content_ratings.get_app_rated_message) # insert Submission ID and Security code to get app rated content_ratings.fill_in_app_already_rated_info(app['submission_id'], app['security_code']) content_ratings.click_submit() Assert.equal('Content ratings successfully saved.', content_ratings.saved_ratings_message) # setup payments payments = content_ratings.click_setup_payments() # select payment account payments.select_payment_account() # setup price tier app_price = '0.99 USD' payments.select_price(app_price) payments.click_payments_save_changes() Assert.true(payments.is_update_notification_visible) Assert.equal(payments.app_price, app_price, '\n Expected price is: %s \n Actual price is: %s' % (app_price, payments.app_price)) except Exception as exception: Assert.fail(exception) finally: # Clean up app edit_app = dev_home.go_to_app_status_page(app) delete_popup = edit_app.click_delete_app() delete_popup.delete_app()
def test_check_submission_of_an_app_with_XSS_in_its_app_name(self, mozwebqa_devhub_logged_in): if '-dev.allizom' in mozwebqa_devhub_logged_in.base_url: env = 'dev' else: env = 'stage' app = MockApplication(env, app_type='xss_app') dev_home = Home(mozwebqa_devhub_logged_in) dev_agreement = dev_home.click_submit_new_app() """Agree with the developer agreement and continue if it was not accepted in a previous app submit""" manifest_validation_form = dev_agreement.click_continue() # select device type for device in app['device_type']: if device[1]: manifest_validation_form.device_type(device[0]) manifest_validation_form.app_type(app['app_type']) # submit the app manifest url and validate it manifest_validation_form.type_app_manifest_url(app['url']) manifest_validation_form.click_validate() Assert.true(manifest_validation_form.app_validation_status, msg=manifest_validation_form.app_validation_message) try: app_details = manifest_validation_form.click_continue() Assert.true(app_details.is_the_current_submission_stage, '\n Expected step is: Details \n Actual step is: %s' % app_details.current_step) # add custom app details for every field app_details.click_change_name() app_details.type_url_end(app['url_end']) app_details.type_description(app['description']) app_details.type_privacy_policy(app['privacy_policy']) app_details.type_homepage(app['homepage']) app_details.type_support_url(app['support_website']) app_details.type_support_email(app['support_email']) for category in app['categories']: # check/uncheck the checkbox according to the app value app_details.select_categories(*category) app_details.screenshot_upload(app['screenshot_link']) next_steps = app_details.click_continue() Assert.equal('Almost There!', next_steps.almost_there_message) content_ratings = next_steps.click_continue() Assert.equal('Get My App Rated', content_ratings.get_app_rated_message) # insert Submission ID and Security code to get app rated content_ratings.fill_in_app_already_rated_info(app['submission_id'], app['security_code']) content_ratings.click_submit() Assert.equal('Congratulations, your app submission is now complete and will be reviewed shortly!', content_ratings.saved_ratings_message) # check that xss is in app name edit_listing_page = dev_home.go_to_edit_listing_page(app) Assert.contains(u"<script>alert(‘XSS')</script>", edit_listing_page.page_title) # check that xss name is in my submissions dev_submissions = edit_listing_page.left_nav_menu.click_my_submissions_menu() submitted_app_names = [first_app.name.lower() for first_app in dev_submissions.submitted_apps] Assert.equal(u"<script>alert(‘xss')</script>", submitted_app_names[0]) except Exception as exception: Assert.fail(exception) finally: # Clean up app edit_app = dev_home.go_to_app_status_page(app) delete_popup = edit_app.click_delete_app() delete_popup.delete_app()
def test_packaged_app_submission(self, mozwebqa, login): if '-dev.allizom' in mozwebqa.base_url: env = 'dev' else: env = 'stage' app = MockApplication(env, app_type='packaged') dev_home = Home(mozwebqa) dev_agreement = dev_home.click_submit_new_app() """Agree with the developer agreement and continue if it was not accepted in a previous app submit""" manifest_validation_form = dev_agreement.click_continue() # select device type for device in app['device_type']: if device[1]: manifest_validation_form.device_type(device[0]) # select app type manifest_validation_form.app_type(app['app_type']) # submit the hosted app and validate it manifest_validation_form.upload_file(app['app_path']) manifest_validation_form.wait_for_app_validation() Assert.true(manifest_validation_form.app_validation_status, msg=manifest_validation_form.app_validation_message) app_details = manifest_validation_form.click_continue() Assert.true( app_details.is_the_current_submission_stage, '\n Expected step is: Details \n Actual step is: %s' % app_details.current_step) # add custom app details for every field app_details.click_change_name() app_details.type_url_end(app['url_end']) app_details.type_description(app['description']) app_details.type_privacy_policy(app['privacy_policy']) app_details.type_homepage(app['homepage']) app_details.type_support_url(app['support_website']) app_details.type_support_email(app['support_email']) for category in app['categories']: # check/uncheck the checkbox according to the app value app_details.select_categories(*category) app_details.screenshot_upload(app['screenshot_link']) try: next_steps = app_details.click_continue() Assert.equal('Almost There!', next_steps.almost_there_message) content_ratings = next_steps.click_continue() Assert.equal('Get My App Rated', content_ratings.get_app_rated_message) # insert Submission ID and Security code to get app rated content_ratings.fill_in_app_already_rated_info( app['submission_id'], app['security_code']) content_ratings.click_submit() Assert.equal( 'Congratulations, your app submission is now complete and will be reviewed shortly!', content_ratings.saved_ratings_message) except Exception as exception: Assert.fail(exception) finally: # Clean up app edit_app = dev_home.go_to_app_status_page(app) delete_popup = edit_app.click_delete_app() delete_popup.delete_app()
def test_new_version_submission_for_awaiting_review_app(self, mozwebqa_devhub_logged_in): if '-dev.allizom' in mozwebqa_devhub_logged_in.base_url: env = 'dev' else: env = 'stage' app = MockApplication(env, app_type='packaged') dev_home = Home(mozwebqa_devhub_logged_in) dev_agreement = dev_home.click_submit_new_app() """Agree with the developer agreement and continue if it was not accepted in a previous app submit""" manifest_validation_form = dev_agreement.click_continue() # select device type for device in app['device_type']: if device[1]: manifest_validation_form.device_type(device[0]) # select app type manifest_validation_form.app_type(app['app_type']) # submit the packaged app and validate it manifest_validation_form.upload_file(app['app_path']) manifest_validation_form.wait_for_app_validation() Assert.true(manifest_validation_form.app_validation_status, msg=manifest_validation_form.app_validation_message) app_details = manifest_validation_form.click_continue() try: # add custom app details for every field app_details.click_change_name() app_details.type_url_end(app['url_end']) app_details.type_description(app['description']) app_details.type_privacy_policy(app['privacy_policy']) app_details.type_homepage(app['homepage']) app_details.type_support_url(app['support_website']) app_details.type_support_email(app['support_email']) for category in app['categories']: # check/uncheck the checkbox according to the app value app_details.select_categories(*category) app_details.screenshot_upload(app['screenshot_link']) next_steps = app_details.click_continue() next_steps.click_continue() # Go to the Edit Page and add a new version manage_status = dev_home.go_to_app_status_page(app) new_version = MockApplication(app_type='new_version') manage_status.upload_file(new_version['app_path']) manage_status.wait_for_app_validation() manage_status.click_continue() Assert.equal(manage_status.notification_message, 'New version successfully added.') manage_status.type_release_notes(new_version['description']) manage_status.click_save_changes() Assert.equal(manage_status.notification_message, 'Version successfully edited.') Assert.equal(manage_status.new_packaged_version, '2.0') Assert.equal(manage_status.new_version_status_message, 'Pending approval') Assert.equal(manage_status.previous_version_status_message, 'Obsolete') except Exception as exception: Assert.fail(exception) finally: # Clean up app edit_app = dev_home.go_to_app_status_page(app) delete_popup = edit_app.click_delete_app() delete_popup.delete_app()
def pager(self): try: return self.Pager(self.testsetup, self._root.find_element(*self._pager_locator)) except NoSuchElementException: Assert.fail('Paginator is not available')