Cheats

This cheats page is an unordered list of common, quick code examples you can use to copy and paste code into your Magium Magento tests. The un-fully qualified class names are provided for the sake of clarity on this page. Use code completion in your IDE to get the right ones.

Hint: Magium is designed to be very intuitive when using code completion.

Hint: Most examples presume that they are in a properly defined AbstractMagentoTestCase class.

Basic Operations

Starting A Test


use Magium\Magento\AbstractMagentoTestCase;

class BasicTest extends AbstractMagentoTestCase
{

    public function testGuestCheckout()
    {
        $theme = $this->getTheme();
        $this->commandOpen($theme->getBaseUrl());
    }
}
    

Navigating To A Category Page

Add Hoc Category Navigation


$this->getNavigator()->navigateTo('Men/Shirts');
    

Static Category Navigation (recommended)

This method is recommended because it provides a global category via configuration. If the category needs to be changed, it will be changed in only one place. This makes the test much simpler to use.


$this->getNavigator(DefaultSimpleProductCategory::NAVIGATOR)->navigateTo();
    

Navigating To A Product Page

Ad Hoc Navigation To A Product Page

When on a category page do the following


$this->getNavigator(Product::NAVIGATOR)->navigateTo('Blue Horizons Bracelets');
    

Static Product Navigation For A Simple Product(recommended)

This method is recommended because it provides a global category via configuration. If the category needs to be changed, it will be changed in only one place. This makes the test much simpler to use.


$this->getNavigator(DefaultSimpleProductCategory::NAVIGATOR)->navigateTo();
$this->getNavigator(DefaultSimpleProduct::NAVIGATOR)->navigateTo();
    

Static Product Navigation For A Configurable Product(recommended)

This method is recommended because it provides a global category via configuration. If the category needs to be changed, it will be changed in only one place. This makes the test much simpler to use.


$this->getNavigator(DefaultConfigurableProductCategory::NAVIGATOR)->navigateTo();
$this->getNavigator(DefaultConfigurableProduct::NAVIGATOR)->navigateTo();
    

Adding A Simple Product To The Cart From The Product Page


$this->getAction(AddSimpleProductToCart::ACTION)->execute();

// or

$action = $this->getAction(AddSimpleProductToCart::ACTION);
/* @var $action AddSimpleProductToCart */
$action->setQty(2); // configure the quantity
$action->execute();
    

Adding A Configurable Product To The Cart From The Product Page


$action = $this->getAction(AddConfigurableProductToCart::ACTION);
/* @var $action AddConfigurableProductToCart */
$action->setOption('size', 'large');
$action->setOption('color', 'red');
$action->execute();
    

Searching The Website


$this->getAction(Search::ACTION)->search('search terms');
    

Logging In As A Customer


// If you are on the login page
$this->getAction(NavigateAndLogin::ACTION)->login();

// or if you are not on the login page

$this->getAction(\Magium\Magento\Actions\Customer\Login::ACTION)->login();
    

Navigate To A Customer Page (such as Orders)


$this->getNavigator(Account::NAVIGATOR)->navigateTo('My Orders');
    

Checkout

Each example presumes a product has been added to the cart

Guest Checkout


$this->getAction(GuestCheckout::ACTION)->execute();
    

Customer Checkout


$this->getAction(CustomerCheckout::ACTION)->execute();
    

New Customer Checkout


$this->getAction(RegisterNewCustomerCheckout::ACTION)->execute();
    

Stopping Checkout


$customerCheckout= $this->getAction(CustomerCheckout::ACTION);
/* @var $customerCheckout \Magium\Magento\Actions\Checkout\CustomerCheckout */
$customerCheckout->addStep(
    $this->getAction(StopProcessing::ACTION), // The step to add, StopProcessing, in this case
    $this->getAction(PlaceOrder::ACTION) // Insert it prior to this step
);
$customerCheckout->execute();
    

Changing A Customer Parameter During Checkout


$this->getIdentity()->setBillingFirstName('Bob');
$this->getAction(GuestCheckout::ACTION)->execute();
    

Admin

Logging In


$this->getAction(\Magium\Magento\Actions\Admin\Login\Login::ACTION)->login();
    

Navigation

Navigate To An Arbitrary Page


$this->getNavigator(AdminMenu::NAVIGATOR)->navigateTo('Promotions/Catalog Price Rules');
    

Navigate To An Order


$this->getNavigator(Order::NAVIGATOR)->navigateTo('100000101);
    

Navigate To A Customer


$this->getNavigator(AdminMenu::NAVIGATOR)->navigateTo('Customers/Manage Customers');
$this->getNavigator(Customer::NAVIGATOR)->navigateTo(new Customer\ByEmail('kschroeder@magiumlib.com'));
    

Changing A System Configuration Value


$this->getAction(Login::ACTION)->login();
$this->getNavigator(AdminMenu::NAVIGATOR)->navigateTo('System/Configuration');
$modifier = $this->getAction(SettingModifier::ACTION);
/* @var $modifier \Magium\Magento\Actions\Admin\Configuration\SettingModifier */

$modifier->set('Checkout/Checkout Options::label=Enable Terms and Conditions', SettingModifier::SETTING_OPTION_YES, true); // True saves it
    

Enable Or Disable A Module


$enabler = $this->getAction(Enabler::ACTION);
/** @var $enabler \Magium\Magento\Actions\Admin\Configuration\Enabler */
$enabler->disable('Payment Methods/Saved CC');
    

Available Assertions

Assert that an element denoted by the selector is clickable (tempermental)


        $this->assertElementClickable('//body', WebDriver::BY_XPATH);
    

Assert that an element denoted by the selector is not clickable (tempermental)


        $this->assertElementNotClickable('//body', WebDriver::BY_XPATH);
    

Assert that an element denoted by the selector exists


        $this->assertElementExists('//body', WebDriver::BY_XPATH);
    

Assert that the title of a page is exactly


        $this->assertTitleEquals('The title exactly equals this text');
    

Assert that the title at least has this text in it


        $this->assertTitleContains('Title contains this text');
    

Assert that the title does not equal this text


        $this->assertNotTitleEquals('The title does not exactly equal this text');
    

Assert that the title does not contain this text as a substring


        $this->assertNotTitleContains('The title does not contain this text');
    

Assert that the current browser URL matches this exactly


        $this->assertURLEquals('An exact URL to match');
    

Assert that the current browser URL contains certain text


        $this->assertURLContains('A partial URL match');
    

Assert that the current URL does not match the specified URL


        $this->assertURLNotEquals('The current URL is not this URL');
    

Assert that the current URL does not contain the specified text


        $this->assertURLNotContains('The URL does not contain this text');
    

Assert that an element denoted by the selector exists and is displayed


        $this->assertElementDisplayed('//body', WebDriver::BY_XPATH);
    

Assert that an element denoted by the selector exists, but is not displayed


        $this->assertElementNotDisplayed('//body', WebDriver::BY_XPATH);
    

Assert that the retrieved element does not contain the specified text


        $this->assertElementHasText(WebDriverElement $node, 'Text);
    

Assert that the page contains the specified text


        $this->assertPageHasText('The page has this text in one or several of its elements');
    

Assert that the page does not contain the specified text


        $this->assertPageNotHasText('The page does not have this text');