Magetno 2 comes with built in functional test framework.(MTAF) This is also available for Magento 1 too. Here is the quick step by step guide to how to run these functional test cases.
Prerequesties
- Working Magento 2 installation
- Disable admin security key urls from magento admin panel. Store=>Config=>Advanced=>Admin=>Add security key url=No
- Firefox or Google chrome web browser
- Java runtime installed in your machine
- PHP Composer
How to Run
- Got to <magento root>/dev/tests/functional/.
- Run composer install to install required dependancies. This will download mtaf, selinium RC etc to vendor folder. [composer install]
- Run [php utils/generate/factory.php] after composer install to generate required factories.
- Open phpunit.xml and update urls
<php>
<env name="app_frontend_url" value="http://magento2.local.com/index.php/" />
<env name="app_backend_url" value="http://magento2.local.com/index.php/admin/" />
<env name="testsuite_rule" value="basic" />
<env name="testsuite_rule_path" value="Magento/Mtf/TestSuite/InjectableTests" />
<env name="log_directory" value="var/log" />
<env name="events_preset" value="base" />
<env name="module_whitelist" value="Magento_Install" />
<env name="basedir" value="var/log" />
<env name="credentials_file_path" value="./credentials.xml.dist" />
</php>
- Open etc/config.xml and update login credentials
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="config.xsd">
<application>
<reopenBrowser>testCase</reopenBrowser>
<backendLogin>admin</backendLogin>
<backendPassword>*****</backendPassword>
<appBackendUrl>http://magento2.local.com/admin/</appBackendUrl>
<backendLoginUrl>admin/auth/login</backendLoginUrl>
</application>
<install>
<host>127.0.0.1</host>
<user>root</user>
<password>******</password>
<dbName>default</dbName>
<baseUrl>http://magento2.local.com/</baseUrl>
<backendName>admin</backendName>
</install>
</config>
- Those are the minimum configuration to get test cases runinng. You can find more descriptive configuration documents under vendor/magento/mtf/docs/
- Start Selenium by [java -jar vendor/netwing/selenium-server-standalone/selenium-server-standalone-2.44.0.jar] your version may variy
- Now run phpunit from <magento root>/dev/tests/functional/
Following are all the commands that used.
cd <magento root>/dev/tests/functional
composer install
vi phpunit.xml (change urls)
vi etc/config.xml (change urls/credentials)
java -jar vendor/netwing/selenium-server-standalone/selenium-server-standalone-2.44.0.jar
phpunit