コード例 #1
0
    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."
コード例 #2
0
    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)