def testCreateNewInviteCode(self): """Test that creating a new invite code actually generates a new one.""" landing_page = LandingPage(self.driver) # Create test user and get it. landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'], BaseTest.TEST_USER_AS_DICT['email'], self.args.server_url) self.assertTestUserPresenceOnPage(True) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) # Navigate to details dialog. details_dialog = landing_page.getDetailsDialogForItem(test_user_item) # Get the initial invite code. initial_invite_code = details_dialog.find_element( *LandingPage.USER_INVITE_CODE_TEXT).get_attribute('value') # Click new invite code on that user. get_invite_code_button = details_dialog.find_element( *LandingPage.USER_ROTATE_KEYS_BUTTON) get_invite_code_button.click() # Wait for post to finish, can take a while. WebDriverWait(self.driver, LandingPage.DEFAULT_TIMEOUT).until( EC.invisibility_of_element_located( ((LandingPage.USER_DETAILS_SPINNER)))) # Renavigate to the landing page to ensure the backend changed vs just a # UI update if specified. self.driver.get(self.args.server_url + flask.url_for('landing')) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) # Set the container element to find the disable/enable button and text on. # Will be either the item within the listbox or the overall details dialog. details_dialog = landing_page.getDetailsDialogForItem(test_user_item) # Check the invite code text changed. final_invite_code = details_dialog.find_element( *LandingPage.USER_INVITE_CODE_TEXT).get_attribute('value') self.assertNotEquals(initial_invite_code, final_invite_code) landing_page.tryToCloseDetailsDialogAndRefreshIfFail( self.args.server_url)
def testCreateNewInviteCode(self): """Test that creating a new invite code actually generates a new one.""" landing_page = LandingPage(self.driver) # Create test user and get it. landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'], BaseTest.TEST_USER_AS_DICT['email'], self.args.server_url) self.assertTestUserPresenceOnPage(True) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) # Navigate to details dialog. details_dialog = landing_page.getDetailsDialogForItem(test_user_item) # Get the initial invite code. initial_invite_code = details_dialog.find_element( *LandingPage.USER_INVITE_CODE_TEXT).get_attribute('value') # Click new invite code on that user. get_invite_code_button = details_dialog.find_element( *LandingPage.USER_ROTATE_KEYS_BUTTON) get_invite_code_button.click() # Wait for post to finish, can take a while. WebDriverWait(self.driver, LandingPage.DEFAULT_TIMEOUT).until( EC.invisibility_of_element_located((( LandingPage.USER_DETAILS_SPINNER)))) # Renavigate to the landing page to ensure the backend changed vs just a # UI update if specified. self.driver.get(self.args.server_url + flask.url_for('landing')) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) # Set the container element to find the disable/enable button and text on. # Will be either the item within the listbox or the overall details dialog. details_dialog = landing_page.getDetailsDialogForItem(test_user_item) # Check the invite code text changed. final_invite_code = details_dialog.find_element( *LandingPage.USER_INVITE_CODE_TEXT).get_attribute('value') self.assertNotEquals(initial_invite_code, final_invite_code) landing_page.tryToCloseDetailsDialogAndRefreshIfFail(self.args.server_url)
def assertTestUserPresenceOnPage(self, is_present, go_to_landing=True): """Helper to assert whether a user is present on the landing page. Args: is_present: True for the user is present and false for not present. go_to_landing: True to get the landing page again (effectively a refresh if the page is already on the landing) and False to use whatever page the test is already on. """ if go_to_landing: self.driver.get(self.args.server_url + flask.url_for('landing')) landing_page = LandingPage(self.driver) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) if is_present: self.assertIsNotNone(test_user_item) self.assertTrue(test_user_item.is_displayed()) else: self.assertIsNone(test_user_item)
def assertUserCanBeDisabledAndThenEnabled(self, should_use_listbox, should_refresh_page): """Helper method for testing disabling and enabling a user. Args: should_use_listbox: If true, it will disable and enable a user from the user listbox. Otherwise, it will use the details dialog. should_refresh_page: If true, it will refresh the login page in between to check that the backend updates with the UI. """ landing_page = LandingPage(self.driver) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) # Set the container element to find the disable/enable button and text on. # Will be either the item within the listbox or the overall details dialog. container_element = landing_page.getContainerElementForItem( test_user_item, should_use_listbox) # Get the initial enable/disable text. initial_disabled_enabled_button_text = container_element.find_element( *LandingPage.USER_DISABLE_ENABLE_BUTTON).text # Click disable on that user. landing_page.clickDisableEnableOnUserElement(container_element) # Renavigate to the landing page to ensure the backend changed vs just a # UI update if specified. if should_refresh_page: self.driver.get(self.args.server_url + flask.url_for('landing')) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) # Set the container element to find the disable/enable button and text on. # Will be either the item within the listbox or the overall details dialog. container_element = landing_page.getContainerElementForItem( test_user_item, should_use_listbox) # Check the enable/disable text changed. changed_disabled_enabled_button_text = container_element.find_element( *LandingPage.USER_DISABLE_ENABLE_BUTTON).text self.assertNotEquals(initial_disabled_enabled_button_text, changed_disabled_enabled_button_text) # Flip back to enable. landing_page.clickDisableEnableOnUserElement(container_element) # Renavigate to the landing page to ensure the backend changed vs just a # UI update if specified. if should_refresh_page: self.driver.get(self.args.server_url + flask.url_for('landing')) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) # Set the container element to find the disable/enable button and text on. container_element = landing_page.getContainerElementForItem( test_user_item, should_use_listbox) # Check the enable/disable text changed back to the initial. final_disabled_enabled_button_text = container_element.find_element( *LandingPage.USER_DISABLE_ENABLE_BUTTON).text self.assertNotEquals(changed_disabled_enabled_button_text, final_disabled_enabled_button_text) self.assertEquals(initial_disabled_enabled_button_text, final_disabled_enabled_button_text)
def assertUserCanBeDisabledAndThenEnabled(self, should_use_listbox, should_refresh_page): """Helper method for testing disabling and enabling a user. Args: should_use_listbox: If true, it will disable and enable a user from the user listbox. Otherwise, it will use the details dialog. should_refresh_page: If true, it will refresh the login page in between to check that the backend updates with the UI. """ landing_page = LandingPage(self.driver) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) # Set the container element to find the disable/enable button and text on. # Will be either the item within the listbox or the overall details dialog. container_element = landing_page.getContainerElementForItem( test_user_item, should_use_listbox) # Get the initial enable/disable text. initial_disabled_enabled_button_text = container_element.find_element( *LandingPage.USER_DISABLE_ENABLE_BUTTON).text # Click disable on that user. landing_page.clickDisableEnableOnUserElement(container_element) # Renavigate to the landing page to ensure the backend changed vs just a # UI update if specified. if should_refresh_page: self.driver.get(self.args.server_url + flask.url_for('landing')) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) # Set the container element to find the disable/enable button and text on. # Will be either the item within the listbox or the overall details dialog. container_element = landing_page.getContainerElementForItem( test_user_item, should_use_listbox) # Check the enable/disable text changed. changed_disabled_enabled_button_text = container_element.find_element( *LandingPage.USER_DISABLE_ENABLE_BUTTON).text self.assertNotEquals(initial_disabled_enabled_button_text, changed_disabled_enabled_button_text) # Flip back to enable. landing_page.clickDisableEnableOnUserElement(container_element) # Renavigate to the landing page to ensure the backend changed vs just a # UI update if specified. if should_refresh_page: self.driver.get(self.args.server_url + flask.url_for('landing')) test_user_item = landing_page.findTestUser( BaseTest.TEST_USER_AS_DICT['name']) # Set the container element to find the disable/enable button and text on. container_element = landing_page.getContainerElementForItem( test_user_item, should_use_listbox) # Check the enable/disable text changed back to the initial. final_disabled_enabled_button_text = container_element.find_element( *LandingPage.USER_DISABLE_ENABLE_BUTTON).text self.assertNotEquals(changed_disabled_enabled_button_text, final_disabled_enabled_button_text) self.assertEquals(initial_disabled_enabled_button_text, final_disabled_enabled_button_text)