Enabling, Disabling, and Refreshing the Cache in a Magento Selenium test

There could be some user stories that require some kind of a cache refresh in order to complete. One example of this could be that a footer change needs to be made as part of the test. Given that the footer is cached using the HTML block cache, this could be a problem.

In Magium it is very easy to make modifications to the cache. They are done using one of the following classes

  • Magium\Magento\Actions\Admin\Cache\EnableCache
  • Magium\Magento\Actions\Admin\Cache\DisableCache
  • Magium\Magento\Actions\Admin\Cache\RefreshCache

Each of those classes will navigate to the cache page and either

  1. Execute their respective function on all caches
  2. Execute their respective function on specific caches

All Caches

Very easy to do. To disable all caches:

$this->getAction(Login::ACTION)->login();
$cacheAction = $this->getAction(DisableCache::ACTION);
$cacheAction->execute();

To enable all caches

$this->getAction(Login::ACTION)->login();
$cacheAction = $this->getAction(EnableCache::ACTION);
$cacheAction->execute();

Individual Caches

$this->getAction(Login::ACTION)->login();
$cacheAction = $this->getAction(DisableCache::ACTION);
$cacheAction->addTarget(DisableCache::TARGET_BLOCKS);
$cacheAction->addTarget(DisableCache::TARGET_COLLECTIONS);
$cacheAction->execute();

Custom Cache

$this->getAction(Login::ACTION)->login();
$cacheAction = $this->getAction(DisableCache::ACTION);
$cacheAction->addTarget('custom ID, not name');
$cacheAction->execute();