Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

QAExample

alex-gorbivskyi edited this page · 11 revisions

Let's consider part of register customer tests:

class Core_Mage_Customer_RegisterTest extends Mage_Selenium_TestCase
{
    protected function assertPreConditions()
    {
        $this->frontend();
        $this->logoutCustomer();
        $this->frontend('customer_login');
    }

Magento employs a class naming convention whereby the names of the classes directly map to the directories in which they are stored, in our case this is ..\testsuite\Core\Mage\Customer\RegisterTest.php .

Class names may only contain alphanumeric characters. Numbers are permitted in class names but are discouraged. Underscores are only permitted in place of the path separator – the filename ” Mage/Core/Model/Abstract.php ” must map to the class name ” Mage_Core_Model_Abstract ”.

If a class name is comprised of more than one word, the first letter of each new word must be capitalized. Successive capitalized letters are not allowed, e.g. a class ” Mage_Core_Model_MySQL4_Abstract ” is not allowed while ” Mage_Core_Model_Mysql4_Abstract ” is acceptable.

assertPreConditions() is a special function which will be executed before every test in class, so we will do following steps before every test:

  1. Go to Home page ('Home page' will be opened if frontend() function executed without parameters)
  2. Logout customer if he is logged in
  3. Go to 'Customer Login' page (customer_login is a page identifier defined in customer fronted fixtures ..\fixture\default\core\Mage\Customer\uimap\frontend\Customer.yml)
    /**
     * <p>Customer registration.  Filling in only required fields</p>
     *
     * @return array
     * @test
     * @TestlinkId TL-MAGE-3245
     */
    public function withRequiredFieldsOnly()
    {
        //Data
        $userData = $this->loadDataSet('Customers', 'customer_account_register');
        //Steps
        $this->customerHelper()->registerCustomer($userData);
        //Verifying
        $this->assertMessagePresent('success', 'success_registration');

        return $userData;
    }
  1. loading dataset for customer creation on frontend - 'Customers' point out to file(..\fixture\default\core\Mage\Customer\data\Customers.yml) where framework will try to find 'customer_account_register' dataset
  2. creating customer via registerCustomer() using data received in previous step
  3. asserts that the specified message(success_registration) of the specified type(in our case success) is present on the current page
  4. return $userData - this data can be used in other tests
    /**
     * <p>Customer registration.  Use email that already exist.</p>
     *
     * @param array $userData
     *
     * @test
     * @depends withRequiredFieldsOnly
     * @TestlinkId TL-MAGE-3239
     */
    public function withEmailThatAlreadyExists(array $userData)
    {
        //Steps
        $this->customerHelper()->registerCustomer($userData);
        //Verifying
        $this->assertMessagePresent('error', 'email_exists');
    }
}

Via @param and @depends in docblock we specify that withEmailThatAlreadyExists() function receive data from withRequiredFieldsOnly(), so for customer creation in this test we will use exactly the same information, including the same e-mail

Something went wrong with that request. Please try again.