def tearDown(self):
   """Teardown for test methods."""
   landing_page = LandingPage(self.driver)
   landing_page.remove_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                                 self.args.server_url,
                                 should_raise_exception=False)
   LoginPage(self.driver).Logout(self.args.server_url)
   super(ErrorNotificationTest, self).tearDown()
  def testDisableAndEnableUserFromListbox(self):
    """Test that disabling and enabling a user works from the listbox."""
    landing_page = LandingPage(self.driver)
    landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                               BaseTest.TEST_USER_AS_DICT['email'],
                               self.args.server_url)
    self.assertTestUserPresenceOnPage(True)

    self.assertUserCanBeDisabledAndThenEnabled(True, True)
Example #3
0
    def testDisableAndEnableUserFromListbox(self):
        """Test that disabling and enabling a user works from the listbox."""
        landing_page = LandingPage(self.driver)
        landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                                   BaseTest.TEST_USER_AS_DICT['email'],
                                   self.args.server_url)
        self.assertTestUserPresenceOnPage(True)

        self.assertUserCanBeDisabledAndThenEnabled(True, True)
  def testManuallyAddUserFromLandingPage(self):
    """Test that manually adding a user shows up on the user listing."""
    landing_page = LandingPage(self.driver)
    self.assertTestUserPresenceOnPage(False)

    landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                               BaseTest.TEST_USER_AS_DICT['email'],
                               self.args.server_url)

    self.assertTestUserPresenceOnPage(True)
 def tearDown(self):
     """Teardown for test methods."""
     # Refresh the page to remove any opened notifications easily.
     self.driver.get(self.args.server_url + flask.url_for('landing'))
     landing_page = LandingPage(self.driver)
     landing_page.remove_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                                   self.args.server_url,
                                   should_raise_exception=False)
     LoginPage(self.driver).Logout(self.args.server_url)
     super(ErrorNotificationTest, self).tearDown()
Example #6
0
    def testManuallyAddUserFromLandingPage(self):
        """Test that manually adding a user shows up on the user listing."""
        landing_page = LandingPage(self.driver)
        self.assertTestUserPresenceOnPage(False)

        landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                                   BaseTest.TEST_USER_AS_DICT['email'],
                                   self.args.server_url)

        self.assertTestUserPresenceOnPage(True)
 def tearDown(self):
     """Teardown for test methods."""
     # Refresh the page to remove any opened notifications easily.
     self.driver.get(self.args.server_url + flask.url_for("landing"))
     landing_page = LandingPage(self.driver)
     landing_page.remove_test_user(
         BaseTest.TEST_USER_AS_DICT["name"], self.args.server_url, should_raise_exception=False
     )
     LoginPage(self.driver).Logout(self.args.server_url)
     super(ErrorNotificationTest, self).tearDown()
 def tearDown(self):
   """Teardown for test methods."""
   landing_page = LandingPage(self.driver)
   landing_page.remove_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                                 self.args.server_url,
                                 should_raise_exception=False)
   landing_page.removeTestServer(BaseTest.TEST_SERVER_AS_DICT['name'],
                                 self.args.server_url,
                                 should_raise_exception=False)
   LoginPage(self.driver).Logout(self.args.server_url)
   super(LandingPageTest, self).tearDown()
  def testDisableAndEnableUserFromDetailsDialog(self):
    """Test that disabling and enabling a user works from the details page."""
    landing_page = LandingPage(self.driver)
    landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                               BaseTest.TEST_USER_AS_DICT['email'],
                               self.args.server_url)
    self.assertTestUserPresenceOnPage(True)

    self.assertUserCanBeDisabledAndThenEnabled(False, True)

    landing_page.tryToCloseDetailsDialogAndRefreshIfFail(self.args.server_url)
    def testLandingPage(self):
        """Test the landing page."""
        title = 'UfO Management Server'
        instruction = ('Click one of the links on the side to login and '
                       'administer the server.')

        self.driver.get(self.args.server_url)

        landing_page = LandingPage(self.driver)
        self.assertEquals(title, landing_page.GetTitle().text)
        self.assertEquals(instruction, landing_page.GetInstruction().text)
        self.assertIsNotNone(landing_page.GetSidebar())
Example #11
0
    def testAddServerFromLandingPage(self):
        """Test that adding a server shows up on the server listing."""
        landing_page = LandingPage(self.driver)
        self.assertTestServerPresenceOnPage(False)

        landing_page.add_test_server(
            BaseTest.TEST_SERVER_AS_DICT['ip'],
            BaseTest.TEST_SERVER_AS_DICT['name'],
            BaseTest.TEST_SERVER_AS_DICT['ssh_private_key'],
            BaseTest.TEST_SERVER_AS_DICT['host_public_key'],
            self.args.server_url)

        self.assertTestServerPresenceOnPage(True)
  def testDeleteUser(self):
    """Test that deleting a user removes that user."""
    landing_page = LandingPage(self.driver)
    landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                               BaseTest.TEST_USER_AS_DICT['email'],
                               self.args.server_url)

    self.assertTestUserPresenceOnPage(True)

    landing_page.remove_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                                  self.args.server_url)

    self.assertTestUserPresenceOnPage(False)
  def testAddServerFromLandingPage(self):
    """Test that adding a server shows up on the server listing."""
    landing_page = LandingPage(self.driver)
    self.assertTestServerPresenceOnPage(False)

    landing_page.add_test_server(
        BaseTest.TEST_SERVER_AS_DICT['ip'],
        BaseTest.TEST_SERVER_AS_DICT['name'],
        BaseTest.TEST_SERVER_AS_DICT['ssh_private_key'],
        BaseTest.TEST_SERVER_AS_DICT['host_public_key'],
        self.args.server_url)

    self.assertTestServerPresenceOnPage(True)
Example #14
0
    def testEditServer(self):
        """Test that editing a server displays the modified server."""
        landing_page = LandingPage(self.driver)
        landing_page.add_test_server(
            BaseTest.TEST_SERVER_AS_DICT['ip'],
            BaseTest.TEST_SERVER_AS_DICT['name'],
            BaseTest.TEST_SERVER_AS_DICT['ssh_private_key'],
            BaseTest.TEST_SERVER_AS_DICT['host_public_key'],
            self.args.server_url)

        self.assertTestServerPresenceOnPage(True)

        landing_page.editTestServer(
            BaseTest.TEST_SERVER_AS_DICT['name'],
            BaseTest.TEST_SERVER_EDIT_AS_DICT['ip'],
            BaseTest.TEST_SERVER_EDIT_AS_DICT['name'],
            BaseTest.TEST_SERVER_EDIT_AS_DICT['ssh_private_key'],
            BaseTest.TEST_SERVER_EDIT_AS_DICT['host_public_key'],
            self.args.server_url)

        self.assertTestServerPresenceOnPage(False)
        self.assertTestServerPresenceOnPage(
            True, name=BaseTest.TEST_SERVER_EDIT_AS_DICT['name'])

        landing_page.removeTestServer(
            BaseTest.TEST_SERVER_EDIT_AS_DICT['name'],
            self.args.server_url,
            should_raise_exception=False)
Example #15
0
 def set_landing_page(self):
     if hasattr(self, 'mission_page'):
         del self.mission_page
     self.landing_page = LandingPage()
     self.landing_page.mission_ready.connect(self.setup_mission)
     self.landing_page.config_ready.connect(self.save_config)
     self.setCentralWidget(self.landing_page)
  def testDeleteServer(self):
    """Test that deleting a server removes that server."""
    landing_page = LandingPage(self.driver)
    landing_page.add_test_server(
        BaseTest.TEST_SERVER_AS_DICT['ip'],
        BaseTest.TEST_SERVER_AS_DICT['name'],
        BaseTest.TEST_SERVER_AS_DICT['ssh_private_key'],
        BaseTest.TEST_SERVER_AS_DICT['host_public_key'],
        self.args.server_url)

    self.assertTestServerPresenceOnPage(True)

    landing_page.removeTestServer(BaseTest.TEST_SERVER_AS_DICT['name'],
                                  self.args.server_url,
                                  should_raise_exception=False)

    self.assertTestServerPresenceOnPage(False)
Example #17
0
    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 testEditServer(self):
    """Test that editing a server displays the modified server."""
    landing_page = LandingPage(self.driver)
    landing_page.add_test_server(
        BaseTest.TEST_SERVER_AS_DICT['ip'],
        BaseTest.TEST_SERVER_AS_DICT['name'],
        BaseTest.TEST_SERVER_AS_DICT['ssh_private_key'],
        BaseTest.TEST_SERVER_AS_DICT['host_public_key'],
        self.args.server_url)

    self.assertTestServerPresenceOnPage(True)

    landing_page.editTestServer(
        BaseTest.TEST_SERVER_AS_DICT['name'],
        BaseTest.TEST_SERVER_EDIT_AS_DICT['ip'],
        BaseTest.TEST_SERVER_EDIT_AS_DICT['name'],
        BaseTest.TEST_SERVER_EDIT_AS_DICT['ssh_private_key'],
        BaseTest.TEST_SERVER_EDIT_AS_DICT['host_public_key'],
        self.args.server_url)

    self.assertTestServerPresenceOnPage(False)
    self.assertTestServerPresenceOnPage(
        True, name=BaseTest.TEST_SERVER_EDIT_AS_DICT['name'])

    landing_page.removeTestServer(BaseTest.TEST_SERVER_EDIT_AS_DICT['name'],
                                  self.args.server_url,
                                  should_raise_exception=False)
Example #19
0
  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)
Example #20
0
def test_init():
    landing_page = LandingPage(
        full_url="www.example.com?utm_source=my_source&utm_medium=my_medium&utm_campaign=my_campaign"
    )

    assert landing_page.path == "www.example.com"
    assert (
        landing_page.utm_parameters_string
        == "utm_source=my_source&utm_medium=my_medium&utm_campaign=my_campaign"
    )
Example #21
0
    def testLandingPageLayout(self):
        """Test the landing page layout contains the elements we expect.

    This should include elements inherited from the base page,
    BASE_PAGE_ELEMENTS (defined in layout.py), as well as elements specific to
    the landing page, LANDING_PAGE_ELEMENTS. Please add to each list as the UI
    is modified to ensure this test stays up to date.
    """
        self.driver.get(self.args.server_url + flask.url_for('landing'))

        landing_page = LandingPage(self.driver)
        for element_by_id in LandingPage.BASE_PAGE_ELEMENTS:
            base_page_element = landing_page.get_element(element_by_id)
            self.assertIsNotNone(base_page_element)
            self.assertTrue(base_page_element.is_displayed())

        self.assertLogoLinksToLandingPage()

        for element_by_id in LandingPage.LANDING_PAGE_ELEMENTS:
            landing_page_element = landing_page.get_element(element_by_id)
            self.assertIsNotNone(landing_page_element)
            self.assertTrue(landing_page_element.is_displayed())
Example #22
0
  def testRepeatedSearchesFromLandingPage(self):
    """Test that search displays results within the landing page."""
    landing_url = self.args.server_url + flask.url_for('landing')

    # Add user and server.
    landing_page = LandingPage(self.driver)
    landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                               BaseTest.TEST_USER_AS_DICT['email'],
                               self.args.server_url)
    landing_page.add_test_server(
        BaseTest.TEST_SERVER_AS_DICT['ip'],
        BaseTest.TEST_SERVER_AS_DICT['name'],
        BaseTest.TEST_SERVER_AS_DICT['ssh_private_key'],
        BaseTest.TEST_SERVER_AS_DICT['host_public_key'],
        self.args.server_url)

    # Verify they both show up.
    self.assertTestUserPresenceOnPage(True)
    self.assertTestServerPresenceOnPage(True)

    # Search for a server.
    landing_page.searchForTestItem(BaseTest.TEST_SERVER_AS_DICT['name'])

    # Verify the server was found and the user was not.
    self.assertTestUserPresenceOnPage(False, False)
    self.assertTestServerPresenceOnPage(True, False)

    # Verify we are still on the landing page.
    self.assertEquals(landing_url, self.driver.current_url)

    # Search for a user.
    landing_page.searchForTestItem(BaseTest.TEST_USER_AS_DICT['name'])

    # Verify the user was found and the server was not.
    self.assertTestUserPresenceOnPage(True, False)
    self.assertTestServerPresenceOnPage(False, False)

    # Verify we are still on the landing page.
    self.assertEquals(landing_url, self.driver.current_url)
  def testLandingPageLayout(self):
    """Test the landing page layout contains the elements we expect.

    This should include elements inherited from the base page,
    BASE_PAGE_ELEMENTS (defined in layout.py), as well as elements specific to
    the landing page, LANDING_PAGE_ELEMENTS. Please add to each list as the UI
    is modified to ensure this test stays up to date.
    """
    self.driver.get(self.args.server_url + flask.url_for('landing'))

    landing_page = LandingPage(self.driver)
    for element_by_id in LandingPage.BASE_PAGE_ELEMENTS:
      base_page_element = landing_page.get_element(element_by_id)
      self.assertIsNotNone(base_page_element)
      self.assertTrue(base_page_element.is_displayed())

    self.assertLogoLinksToLandingPage()

    for element_by_id in LandingPage.LANDING_PAGE_ELEMENTS:
      landing_page_element = landing_page.get_element(element_by_id)
      self.assertIsNotNone(landing_page_element)
      self.assertTrue(landing_page_element.is_displayed())
  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 testErrorNotificationIsWorking(self):
        """Test the error notification is properly wired up, opened, and closed.

    Not testing the actual behavior directly (e.g. the db save) as those should
    be covered by unit tests.
    """
        self.driver.get(self.args.server_url + flask.url_for("landing"))
        landing_page = LandingPage(self.driver)

        # By default the error notification will be present but not displayed.
        error_notification = ErrorNotification(self.driver)
        self.assertTrue(error_notification.is_present())
        self.assertFalse(error_notification.is_displayed())

        landing_page.add_test_user(
            BaseTest.TEST_USER_AS_DICT["name"], BaseTest.TEST_USER_AS_DICT["email"], self.args.server_url
        )
        landing_page.add_test_user(
            BaseTest.TEST_USER_AS_DICT["name"], BaseTest.TEST_USER_AS_DICT["email"], self.args.server_url
        )

        # Trying to add the same user twice will cause the error notification
        # to be displayed.
        WebDriverWait(self.driver, ErrorNotification.DEFAULT_TIMEOUT).until(
            EC.visibility_of_element_located((error_notification.ERROR_NOTIFICATION_DIALOG))
        )
        self.assertTrue(error_notification.is_displayed())

        # Check the correct error message is displayed.
        # TODO: Make it testable for i18n.
        message = custom_exceptions.UnableToSaveToDB.message
        self.assertTrue(error_notification.has_error_message(message))

        # Check we can close the error notification.
        error_notification.close()
        self.assertFalse(error_notification.is_displayed())
Example #26
0
  def assertTestServerPresenceOnPage(
      self, is_present, go_to_landing=True,
      name=TEST_SERVER_AS_DICT['name']):
    """Helper to assert whether a server is present on the landing page.

    Args:
      is_present: True for the server 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.
      name: The name of the server to assert upon, which defaults to the test
            server.
    """
    if go_to_landing:
      self.driver.get(self.args.server_url + flask.url_for('landing'))
    landing_page = LandingPage(self.driver)
    server_list = landing_page.get_element(LandingPage.SERVER_LIST_ITEM)
    server_listbox = server_list.find_element(*LandingPage.GENERIC_LISTBOX)
    test_server_item = landing_page.findItemInListing(server_listbox, name)
    if is_present:
      self.assertIsNotNone(test_server_item)
      self.assertTrue(test_server_item.is_displayed())
    else:
      self.assertIsNone(test_server_item)
Example #27
0
    def testDisableAndEnableUserFromDetailsDialog(self):
        """Test that disabling and enabling a user works from the details page."""
        landing_page = LandingPage(self.driver)
        landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                                   BaseTest.TEST_USER_AS_DICT['email'],
                                   self.args.server_url)
        self.assertTestUserPresenceOnPage(True)

        self.assertUserCanBeDisabledAndThenEnabled(False, True)

        landing_page.tryToCloseDetailsDialogAndRefreshIfFail(
            self.args.server_url)
Example #28
0
    def testDeleteUser(self):
        """Test that deleting a user removes that user."""
        landing_page = LandingPage(self.driver)
        landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                                   BaseTest.TEST_USER_AS_DICT['email'],
                                   self.args.server_url)

        self.assertTestUserPresenceOnPage(True)

        landing_page.remove_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                                      self.args.server_url)

        self.assertTestUserPresenceOnPage(False)
Example #29
0
  def testSearchUserFromLandingPage(self):
    """Test that search displays user results within the landing page."""
    landing_page = LandingPage(self.driver)
    landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                               BaseTest.TEST_USER_AS_DICT['email'],
                               self.args.server_url)
    self.assertTestUserPresenceOnPage(True)

    landing_page.searchForTestItem(BaseTest.TEST_USER_AS_DICT['name'])

    self.assertTestUserPresenceOnPage(True, False)
    landing_url = self.args.server_url + flask.url_for('landing')
    self.assertEquals(landing_url, self.driver.current_url)
Example #30
0
  def testSearchServerFromLandingPage(self):
    """Test that search displays server results within the landing page."""
    landing_page = LandingPage(self.driver)
    landing_page.add_test_server(
        BaseTest.TEST_SERVER_AS_DICT['ip'],
        BaseTest.TEST_SERVER_AS_DICT['name'],
        BaseTest.TEST_SERVER_AS_DICT['ssh_private_key'],
        BaseTest.TEST_SERVER_AS_DICT['host_public_key'],
        self.args.server_url)
    self.assertTestServerPresenceOnPage(True)

    landing_page.searchForTestItem(BaseTest.TEST_SERVER_AS_DICT['name'])

    self.assertTestServerPresenceOnPage(True, False)
    landing_url = self.args.server_url + flask.url_for('landing')
    self.assertEquals(landing_url, self.driver.current_url)
Example #31
0
    def testDeleteServer(self):
        """Test that deleting a server removes that server."""
        landing_page = LandingPage(self.driver)
        landing_page.add_test_server(
            BaseTest.TEST_SERVER_AS_DICT['ip'],
            BaseTest.TEST_SERVER_AS_DICT['name'],
            BaseTest.TEST_SERVER_AS_DICT['ssh_private_key'],
            BaseTest.TEST_SERVER_AS_DICT['host_public_key'],
            self.args.server_url)

        self.assertTestServerPresenceOnPage(True)

        landing_page.removeTestServer(BaseTest.TEST_SERVER_AS_DICT['name'],
                                      self.args.server_url,
                                      should_raise_exception=False)

        self.assertTestServerPresenceOnPage(False)
  def testErrorNotificationIsWorking(self):
    """Test the error notification is properly wired up, opened, and closed.

    Not testing the actual behavior directly (e.g. the db save) as those should
    be covered by unit tests.
    """
    self.driver.get(self.args.server_url + flask.url_for('landing'))
    landing_page = LandingPage(self.driver)

    # By default the error notification will be present but not displayed.
    error_notification = ErrorNotification(self.driver)
    self.assertTrue(error_notification.is_present())
    self.assertFalse(error_notification.is_displayed())

    landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                               BaseTest.TEST_USER_AS_DICT['email'],
                               self.args.server_url)
    landing_page.add_test_user(BaseTest.TEST_USER_AS_DICT['name'],
                               BaseTest.TEST_USER_AS_DICT['email'],
                               self.args.server_url)

    # Trying to add the same user twice will cause the error notification
    # to be displayed.
    WebDriverWait(self.driver, ErrorNotification.DEFAULT_TIMEOUT).until(
        EC.visibility_of_element_located((
            error_notification.ERROR_NOTIFICATION_DIALOG)))
    self.assertTrue(error_notification.is_displayed())

    # Check the correct error message is displayed.
    # TODO: Make it testable for i18n.
    message = custom_exceptions.UnableToSaveToDB.message
    self.assertTrue(error_notification.has_error_message(message))

    # Check we can close the error notification.
    error_notification.close()
    self.assertFalse(error_notification.is_displayed())
Example #33
0
def main():
    configuration_error = 1
    webdriver_error = 2
    config = None
    password = None

    try:
        config = get_config()
    except OSError as config_file_error:
        print(
            f"Error: Failed to read config file {config_file}: \n{config_file_error} \nExiting."
        )
        exit(configuration_error)

    logger = VerySimpleLogger(file_path=config['log_path'])

    try:
        password = get_password(config)
    except ValueError as value_error:
        logger.log_message(value_error)
        exit(configuration_error)

    logger.log_message("Preparing options, capabilities, and profile")
    driver_options = set_webdriver_options(
        headless_mode=config['headless_mode'])
    driver_capabilities = set_webdriver_capabilities()
    profile = set_webdriver_profile()
    logger.log_message("Instantiating webdriver")
    driver = None

    try:
        driver = webdriver.Firefox(
            firefox_profile=profile,
            capabilities=driver_capabilities,
            options=driver_options,
            firefox_binary=config['firefox_binary_path'],
            executable_path=config['gecko_driver_path'])
    except Exception as e:
        logger.log_message(f"Failed to instantiate webdriver: {e}")
        exit(webdriver_error)

    try:
        logger.log_message("Visiting landing page")
        landing_page = LandingPage(driver)

        logger.log_message("Visiting login page")
        login_page = landing_page.navigate_to_login_page()

        logger.log_message("Visiting offers page")
        offers_page = login_page.perform_login(config['user_name'], password)
        offers_page.load_offers()
        time.sleep(3)  # Wait until the points animation finishes counting.
        points_available = offers_page.get_accumulated_points()
        logger.log_message("Points available: " + points_available)
        offers_page.sign_out()
        logger.log_message("Signed out")
        time.sleep(2)
    except Exception as e:
        logger.log_message(f"Error while navigating pages: {e}")
    finally:
        driver.quit()
        logger.log_message("Quit driver")
Example #34
0
    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)