def testCreateCustomer(self):
        # Count the number of customers before creation.
        target_url = self.configuration['base_url'] + "/admin/order_manager/customer/"
        index_page = CustomerIndex(self.browser, target_url)

        num_customers_before_creation = index_page.count_customers()

        # Fill the form and submit it
        target_url = self.configuration['base_url'] + "/admin/order_manager/customer/add/"
        create_page = CustomerCreate(self.browser, target_url)
        first_name = self.configuration['customer_tests']['first_name']
        last_name = self.configuration['customer_tests']['last_name']
        create_page.fill_form(first_name, last_name)
        create_page.submit_form()

        # Verify that customer was created
        num_customers_after_creation = index_page.count_customers()
        self.validate((num_customers_after_creation == num_customers_before_creation + 1),
                      error_message="Could not find created customer.")

        customer_pattern = "([0-9]+) %s %s" % (first_name, last_name)
        customers_after_creation = index_page.get_customer_elements()
        # Regular expression match
        match = re.match(customer_pattern, customers_after_creation[0].text)
        self.validate((match is not None), error_message="Could not find created customer.")

        self.customer_id = index_page.id_for_customer_named(first_name, last_name)
    def testDeleteCustomer(self):
        # Count the number of customers before creation.
        target_url = self.configuration['base_url'] + "/admin/order_manager/customer/"
        index_page = CustomerIndex(self.browser, target_url)

        num_customers_before_deletion = index_page.count_customers()

        # Delete the customer
        target_url = "%s/admin/order_manager/customer/%d" % (self.configuration['base_url'],
                                                             self.customer_id)
        edit_page = CustomerEdit(self.browser, target_url)
        edit_page.delete_customer()

        edit_page.wait_for_text_to_load_in_element(css_selector="div#content > h1",
                                                   text_to_wait_for="Select customer to change")

        # Verify that the customer is gone from the index page
        num_customers_after_deletion = index_page.count_customers()
        self.validate((num_customers_after_deletion == num_customers_before_deletion - 1),
                      error_message="Could not verify that customer was deleted.")
    def testCreateCustomer(self):
        # Count the number of customers before creation.
        target_url = self.configuration[
            'base_url'] + "/admin/order_manager/customer/"
        index_page = CustomerIndex(self.browser, target_url)

        num_customers_before_creation = index_page.count_customers()

        # Fill the form and submit it
        target_url = self.configuration[
            'base_url'] + "/admin/order_manager/customer/add/"
        create_page = CustomerCreate(self.browser, target_url)
        first_name = self.configuration['customer_tests']['first_name']
        last_name = self.configuration['customer_tests']['last_name']
        create_page.fill_form(first_name, last_name)
        create_page.submit_form()

        # Verify that customer was created
        num_customers_after_creation = index_page.count_customers()
        self.validate((num_customers_after_creation
                       == num_customers_before_creation + 1),
                      error_message="Could not find created customer.")

        customer_pattern = "([0-9]+) %s %s" % (first_name, last_name)
        customers_after_creation = index_page.get_customer_elements()
        # Regular expression match
        match = re.match(customer_pattern, customers_after_creation[0].text)
        self.validate((match is not None),
                      error_message="Could not find created customer.")

        self.customer_id = index_page.id_for_customer_named(
            first_name, last_name)
    def testDeleteCustomer(self):
        # Count the number of customers before creation.
        index_page = CustomerIndex(self.browser, self.configuration['base_url'])
        index_page.open()
        customers_before_deletion = index_page.get_customer_elements()

        # Delete the customer
        edit_page = CustomerEdit(self.browser, self.configuration['base_url'])
        edit_page.open(self.customer_id)
        edit_page.delete_customer()

        # Wait for index page to load
        WebDriverWait(self.browser, 20).until(
            EC.text_to_be_present_in_element(
                (By.CSS_SELECTOR, "div#content > h1"),
                "Select customer to change"
            )
        )

        # Verify that the customer is gone from the index page
        customers_after_deletion = index_page.get_customer_elements()
        assert len(customers_after_deletion) == len(customers_before_deletion) - 1, \
            "Could not verify that customer was deleted."
    def testDeleteCustomer(self):
        # Count the number of customers before creation.
        target_url = self.configuration[
            'base_url'] + "/admin/order_manager/customer/"
        index_page = CustomerIndex(self.browser, target_url)

        num_customers_before_deletion = index_page.count_customers()

        # Delete the customer
        target_url = "%s/admin/order_manager/customer/%d" % (
            self.configuration['base_url'], self.customer_id)
        edit_page = CustomerEdit(self.browser, target_url)
        edit_page.delete_customer()

        edit_page.wait_for_text_to_load_in_element(
            css_selector="div#content > h1",
            text_to_wait_for="Select customer to change")

        # Verify that the customer is gone from the index page
        num_customers_after_deletion = index_page.count_customers()
        self.validate(
            (num_customers_after_deletion
             == num_customers_before_deletion - 1),
            error_message="Could not verify that customer was deleted.")
    def testCreateCustomer(self):
        # Count the number of customers before creation.
        index_page = CustomerIndex(self.browser, self.configuration['base_url'])
        index_page.open()
        customers_before_creation = index_page.get_customer_elements()

        # Fill the form and submit it
        create_page = CustomerCreate(self.browser, self.configuration['base_url'])
        create_page.open()
        first_name = self.configuration['customer_tests']['first_name']
        last_name = self.configuration['customer_tests']['last_name']
        create_page.fill_form(first_name, last_name)
        create_page.submit_form()

        # Verify that customer was created
        customers_after_creation = index_page.get_customer_elements()
        assert len(customers_after_creation) == len(customers_before_creation) + 1, \
            "Could not find created customer."

        customer_pattern = "([0-9]+) %s %s" % (first_name, last_name)
        match = re.match(customer_pattern, customers_after_creation[0].text)
        assert match is not None, "Could not find created customer."

        self.customer_id = index_page.id_for_customer_named(first_name, last_name)