Magen To Test Automation Framework Users Guide
Magen To Test Automation Framework Users Guide
The Magento Test Automation Framework (MTAF) is a system of software tools used for running repeatable functional tests against the Magento
application being tested. This framework can be used for automating most routine processes in Magento, such as:
MTAF is used for both writing test automation scripts and for performing the actual testing. Test automation scripts created within the framework
can be used for testing most Magento functionality which does not relate to an external system. This is a cross-platform solution (not dependent
on a specific operating system). MTAF allows QA specialists to quickly develop all kinds of tests for the current Magento version, and the tests
can be reused at any time. Framework users can run a single test independently, a group of tests together (a test suite), or all available tests from
a single command.
This guide provides instructions on using the test automation framework. It explains the environment requirements for the MTAF and describes
the process of running tests and reviewing the results.
This document is intended for specialists who are either interested or involved in using the Magento Test Automation Framework (hereinafter
referred to as MTAF). This framework is used to run automated tests against a normally installed Magento application. Primarily, this document is
aimed at Magento Quality Assurance specialists and PHP developers.
Note
Using the Magento Test Automation Framework requires advanced knowledge of XML, YAML, and PHP for installing the
necessary working environment, creating functional tests, executing the tests created, and using test results properly.
Related Documents
Conventions
The following text formatting conventions are used to accentuate specific types of information:
Magento The Magento Test Automation Framework (MTAF) is a system of software tools used for running repeatable functional tests
Test against a normally installed Magento application.
Automation
Framework MTAF is used for both writing test automation scripts and for performing the actual testing. Test automation scripts created within
(MTAF) the framework can be used for testing most Magento functionality which does not relate to an external system. This is a
cross-platform solution (not dependent on a specific operating system). MTAF allows QA specialists to quickly develop all kinds of
tests for the current Magento version, and the tests can be reused at any time. Framework users can run a single test
independently, a bunch of tests together (a test suite), or all available tests.
Test A Test Automation Script is a PHP class dependent on the PHPUnit framework and the Selenium library. The script initiates the
Automation running of a specific test case or a suite of test cases.
Script
DataSet A DataSet is a data file or set of data files required for running automated tests. Such file(s) are created in the YAML format. For
more information refer to the MTAF Logical Structure section.
UI Map A UI Map is used to define, store, and serve the UI elements of an application or website. In the case of Magento (website), the
definition of UI elements depends on the Selenium technology, which uses strings and XPATH to locate and define UI elements.
In other words, a UI Map is a repository of test script objects which correspond to UI elements of the application being tested.
User When this document refers to the User, it refers to a Quality Assurance Engineer, PHP Developer, or other person with similar
skills and responsibilities working with the MTAF.
Document The Document Object Model (DOM) is a cross-platform, language-independent convention for representing and interacting with
Object objects in HTML, XHTML and XML documents. Aspects of the DOM (such as its "Elements") may be addressed and manipulated
Model within the syntax of the programming language in use. The public interface of a DOM is specified in its application programming
(DOM) interface (API).
Scope
This section presents a brief overview of each chapter's contents.
Introduction to Magento Automated testing describes the benefits and workflow of automated testing. It also provides the list of tools and
frameworks used to maintain automated testing.
MTAF Environment Requirements lists the software required to use MTAF and the list of Web browsers supported by Magento (and thus
MTAF).
MTAF File Formats describes the file formats used for MTAF files.
MTAF Logical Structure provides a graphical representation of MTAF logic.
MTAF File Structure provides an overview of files used for the MTAF (their location and content).
Starting MTAF provides instructions for starting MTAF.
Running Tests describes the process of running tests.
Results of Running Tests provides examples of test results.
MTAF Instructions provides instructions on custom UIMap, DataSet, test script and test suite creation.
Currently, there are two major approaches used for automated testing: Unit Testing (hereinafter “UT”), and Automated Functional Testing
(hereinafter “AFT”). In Magento, the UT approaches is rarely used, because it requires significant time and resources to establish dependencies
between different modules.
AFT, for Magento, means an automated process used to diagnose whether the application's functionality meets defined functional requirements.
Using the AFT approach confirms that the code for each specific function or feature accomplishes the corresponding tasks successfully.
Secondly, running functional tests confirms that the application operates exactly as expected.
The workflow for using AFT in Magento applications can be presented as follows:
Magento Test Automation Framework (MTAF) uses the following tools and frameworks:
PHPUnit is a unit testing framework for the PHP programming language. Its purpose is to find mistakes in PHP source code. The major
benefit of using PHPUnit is the ability to establish a testing infrastructure and to re-use it as often as needed, simply by creating unique
parts for each particular test.
Selenium is a well know open source testing framework, widely used for testing Web-based applications. It contains a variety of software
tools, each with a different approach to support test automation. These tools provide a rich set of testing functions specifically geared to
the needs of web application testing of all types. Such operations are highly flexible, providing many options for locating UI elements and
comparing expected test results against actual application behavior. One of Selenium’s key features is support for executing tests on
multiple browser platforms. Selenium uses a simple but powerful Document Object Model (DOM) which also allows tests to be exported
to multiple programming languages and frameworks.
The Selenium framework includes the following tools:
Selenium Integrated Development Environment (IDE) is a prototyping tool for building test scripts, a Firefox plugin that
provides an “easy-to-use interface” for developing automated tests. Selenium IDE has a recording feature which records user
actions as they are performed, then exports them as a reusable script that can be later executed in one of many programming
languages. It contains a context menu that allows you to first select a UI element from the browser’s currently displayed page
and then select from a list of Selenium commands; the commands have pre-defined parameters according to the context of the
selected UI element. One can record and playback automated tests without needing to know a test scripting language. This is
not only a time-saver, but also an excellent way of learning Selenium script syntax.
Selenium Remote Control (RC) is a test tool that allows you to write automated web application UI tests in any programming
language against any HTTP website using any mainstream JavaScript-enabled browser.
Selenium Web Driver is a tool for writing automated tests for websites. It aims to mimic the behavior of a real user, and as such
interacts with the HTML of the application.
Selenium-Grid is a Selenium derivative that allows developers and QA personnel to access Selenium Remote Controls without
worrying about where the Selenium Remote Controls are located. As a developer or QA specialist, one can create a script as
one would for Selenium Remote Control and run it as usual.
For details about installing and configuring the necessary applications, refer to the Magento Test Automation Framework Installation Guide.
Note
The Selenium RC server must be able to locate the browser's '.EXE' file in order to successfully run a browser. For more information
about this, refer to the official Selenium documentation.
A custom browser profile must be created to be used by Selenium for running automated tests. For more information about this, refer to
the Magento Test Automation Framework Installation Guide.
XML: The only meaningful XML file used in MTAF is the phpunit.xml configuration file
PHP: In MTAF, PHP files are basically used in two situations:
Test case files, located in the tests directory (test cases can be run based on the configuration defined in the phpunit.xml file,
and use the input data set specified in the DataSet YAML files)
Framework library files
YAML: Most MTAF files are created in the YAML format (a human-readable data serialization format); these can present either UIMap
files or data set files.
A UIMap is a concept for defining, storing, and serving UI elements of an application or a website. The UIMap file (YAML file) contains a set of
‘key-value’ pairs, where each key is the alias of a UI element, and the corresponding value is an Xpath locator. In terms of the UIMap, each page
rendered by a browser is presented as a Document Object Model (DOM). Such a model includes every single UI element that can exist on a
page. Xpath locators are paths to such UI element in a DOM model. Thus, using Xpath expressions, it is possible to link any UI element on a
page (even a hidden one) with a method that imitates an action being executed upon it (a method in the MTAF library). For example, one can use
UIMaps (Xpath expressions) and a “click” method from the MTAF library to reproduce clicking any UI element on the specified web page. An
example of using such an approach can be the re-testing of the localized application.
A DataSet is a pool of YAML files (data storage) which describe the data main-space being referred to by the test case files. For search
convenience purposes the data main-space is logically split into several data files. Each data file can be related to a specific functionality being
tested (and thus, related to specific test case files).
A Test is, generally speaking, a single action or sequence of actions that evaluates whether a specific feature meets functional requirements. It
can be said that a test is a method in a class which is inherited from the basic test case class. The test calls a library function (or functions), which
in turn executes the actions required to check the application's expected business logic.
The config folder contains two major files: config.yml and local.yml. The config.yml file is used as a template for configuring the
Selenium client. For more information on using these files, refer to the MTAF Configuration section.
The library folder contains the entire class hierarchy from the API framework.
The uimaps folder stores YAML files with descriptions of UIMaps for tests. It contains all UIMaps used in tests and may include some
custom ones.
The data folder contains all of the input parameters for all tests. Test data can be loaded to this folder with the help of the loadData()
method as follows:
$storeData = $this->loadData('generic_store', Null, 'store_name');
The tests folder contains PHP files with test suite classes.
Starting MTAF
1. Run Selenium Server.
2. Execute runtests.bat (in Windows) through the command prompt for tests running.
3. Executing runtests.sh for Linux/*NIX OS is not implemented yet
Running Tests
When choosing the appropriate method for running tests you must consider the quanitity of tests (whether it is a single test, a test suite or all
tests), test sites (local, remote, distributed machines or cluster) and continuous integration practices. You also need to take into account testing
purposes when choosing a way to run your tests, such as test script debugging, manual start or continuous integration. Based on these factors,
you may choose to run your tests from the Integrated Development Environment (IDE), from the command prompt or from the continuous
integration server.
The following instructions are specific to the NetBeans IDE. If you are using a different IDE, refer to that product's documentation for instructions.
1. Select the test file (the file node) you want to run.
2. Right click the file in the file tree (Projects window), then click 'Run'.
or
Press Shift+F6 to run the test opened in the edit window.
Command Prompt
The command prompt provides you with full control over your tests and independence from platforms. It also enables you to start your tests
manually. This option is most preferable when you have already debugged the tests and they can be run in production.
To work from the command prompt you need to have a BAT file with the phpunit.xml configuration. The same logic is used for running tests from
a continuous integration server, which we will discuss later.
You can configure your phpunit.xml file to run all tests, a specific test suite or just a single test:
Running tests this way requires far fewer machine resources and the tests are executed more quickly, but it does not provide you with full
debugging capabilities.
Command Prompt
After executing runtests.bat from the command prompt you can see the current progress of running your tests. It provides an overview without
detailed information:
Legend:
More details about PHPUnit results generation are available on the PHPUnit website.
Logs
PHPUnit logging tools provide more detailed information about test results. Once you execute runtests.bat, log files containing detailed
information about test execution are created in the same directory.
Log files are created in several different formats: plain text, XML, HTML etc. Several of them are provided in the examples below:
{
"event": "suiteStart",
"suite": "All Tests",
"tests": 527
} {
"event": "suiteStart",
"suite": "AdminUser_DeleteTest",
"tests": 2
} {
"event": "testStart",
"suite": "AdminUser_DeleteTest",
"test": "AdminUser_DeleteTest::test_DeleteAdminUser_Deletable"
} {
"event": "test",
"suite": "AdminUser_DeleteTest",
"test": "AdminUser_DeleteTest::test_DeleteAdminUser_Deletable",
"status": "pass",
"time": 45.594885826111,
"trace": [],
"message": ""
} {
"event": "testStart",
"suite": "AdminUser_DeleteTest",
"test": "AdminUser_DeleteTest::test_DeleteAdminUser_Current"
} {
"event": "test",
"suite": "AdminUser_DeleteTest",
"test": "AdminUser_DeleteTest::test_DeleteAdminUser_Current",
"status": "pass",
"time": 17.709816932678,
"trace": [],
"message": ""
} {
...
Example of Results Display in TAP File Format
TAP version 13
ok 1 - AdminUser_DeleteTest::test_DeleteAdminUser_Deletable
ok 2 - AdminUser_DeleteTest::test_DeleteAdminUser_Current
ok 3 - AdminUser_CreateTest::test_Navigation
ok 4 - AdminUser_CreateTest::test_WithRequiredFieldsOnly
ok 5 - AdminUser_CreateTest::test_WithUserNameThatAlreadyExists
ok 6 - AdminUser_CreateTest::test_WithUserEmailThatAlreadyExists
ok 7 - AdminUser_CreateTest::test_WithRequiredFieldsEmpty with data set #0 ('user_name', 1)
ok 8 - AdminUser_CreateTest::test_WithRequiredFieldsEmpty with data set #1 ('first_name', 1)
ok 9 - AdminUser_CreateTest::test_WithRequiredFieldsEmpty with data set #2 ('last_name', 1)
ok 10 - AdminUser_CreateTest::test_WithRequiredFieldsEmpty with data set #3 ('email', 1)
ok 11 - AdminUser_CreateTest::test_WithRequiredFieldsEmpty with data set #4 ('password', 2)
ok 12 - AdminUser_CreateTest::test_WithRequiredFieldsEmpty with data set #5 ('password_confirmation',
1)
ok 13 - AdminUser_CreateTest::test_WithSpecialCharacters_exeptEmail
ok 14 - AdminUser_CreateTest::test_WithLongValues
ok 15 - AdminUser_CreateTest::test_WithInvalidPassword with data set #0 (array('1234567890',
'1234567890'), 'invalid_password')
ok 16 - AdminUser_CreateTest::test_WithInvalidPassword with data set #1 (array('qwertyqw',
'qwertyqw'), 'invalid_password')
ok 17 - AdminUser_CreateTest::test_WithInvalidPassword with data set #2 (array('123qwe', '123qwe'),
'invalid_password')
ok 18 - AdminUser_CreateTest::test_WithInvalidPassword with data set #3 (array('123123qwe',
'1231234qwe'), 'password_unmatch')
ok 19 - AdminUser_CreateTest::test_WithInvalidEmail with data set #0 ('invalid')
ok 20 - AdminUser_CreateTest::test_WithInvalidEmail with data set #1 ('test@invalidDomain')
ok 21 - AdminUser_CreateTest::test_WithInvalidEmail with data set #2 ('te@[email protected]')
ok 22 - AdminUser_CreateTest::test_InactiveUser
ok 23 - AdminUser_CreateTest::test_WithRole
ok 24 - AdminUser_CreateTest::test_WithoutRole
ok 25 - AdminUser_LoginTest::loginValidUser
...
Example of Results Display in HTML File Format
<html>
<body>
<h2 id="AdminUser_DeleteTest">
AdminUser_Delete
</h2>
<ul>
<li>
test DeleteAdminUser Deletable
</li>
<li>
test DeleteAdminUser Current
</li>
</ul>
<h2 id="AdminUser_CreateTest">
AdminUser_Create
</h2>
<ul>
<li>
test Navigation
</li>
<li>
test WithRequiredFieldsOnly
</li>
<li>
test WithUserNameThatAlreadyExists
</li>
<li>
test WithUserEmailThatAlreadyExists
</li>
<li>
test WithRequiredFieldsEmpty
</li>
<li>
test WithSpecialCharacters exeptEmail
</li>
<li>
test WithLongValues
</li>
<li>
test WithInvalidPassword
</li>
<li>
test WithInvalidEmail
</li>
<li>
test InactiveUser
</li>
<li>
test WithRole
</li>
<li>
test WithoutRole
</li>
</ul>
...
Example of Results Display in Testdox-Text
AdminUser_Delete
[x] test DeleteAdminUser Deletable
[x] test DeleteAdminUser Current
AdminUser_Create
[x] test Navigation
[x] test WithRequiredFieldsOnly
[x] test WithUserNameThatAlreadyExists
[x] test WithUserEmailThatAlreadyExists
[x] test WithRequiredFieldsEmpty
[x] test WithSpecialCharacters exeptEmail
[x] test WithLongValues
[x] test WithInvalidPassword
[x] test WithInvalidEmail
[x] test InactiveUser
[x] test WithRole
[x] test WithoutRole
AdminUser_Login
[x] Login valid user
[x] Login empty one field
[x] Login non existant user
[x] Login incorrect password
[x] Login inactive admin account
[x] Login without permissions
[x] Forgot empty password
[x] Forgot password invalid email
[x] Forgot password correct email
[ ] Forgot password old password
...
<testsuites>
<testsuite name="All Tests" tests="194" assertions="713" failures="0" errors="0"
time="2974.288380">
<testsuite name="AdminUser_CreateTest" file="D:\Work\selenium-saas\tests\AdminUser\CreateTest.php"
fullPackage="selenium.tests" package="selenium" subpackage="tests" tests="22" assertions="68"
failures="0" errors="0" time="491.137801">
<testcase name="test_Navigation" class="AdminUser_CreateTest"
file="D:\Work\selenium-saas\tests\AdminUser\CreateTest.php" line="71" assertions="6"
time="26.675233"/>
<!--...-->
</testsuite>
<!--...-->
</testsuites>
MTAF Instructions
After unpacking the downloaded project, the user will see the following structure for the Magento TAF:
Example of MTAF Structure
__/magento-afw-x.x.x
|
|__/config // Contains files with Selenium Server configuration
| |
| |--config.yml // Contains the list of browsers for testing
| |--*.yml
|
|__/data // Contains test Data Sets for running test cases
| |
| |--DataSetFile.yml // Contains files with test data
| |--*.yml
|
|__/lib // Contains Magento Test Automation Framework sources
| |__/Mage
| |__/Selenium
| |--LibraryFile.php
| |--*.php
|
|__/tests // Contains the files with test scripts divided by specific functional areas
| |
| |__/FunctionalityGroupName1 // example: /Customer/
| | |--FGN1TestScript.php // example: Register.php
| |
| |__/FunctionalityGroupName*
|
|__/uimaps // Contains page elements UIMaps for all pages that need to be tested
| |__/admin
| | |--FunctionalityRelatesUIMAPFile.yml // for example: dashboard.yml
| | |--*.yml
| |__/front
| | |--FunctionalityRelatesUIMAPFile.yml
| | |--*.yml
| |__/paypal_ui
| |--FunctionalityRelatesUIMAPFile.yml
| |--*.yml |
|__phpunit.xml // Contains the list of test cases that will be run
_page_name
|__mca: URL without BaseURL
|
|__title: page title
|
|__uimap:
| |
| |__form: &formLink
| | |
| | |__tabs:
| | | |
| | | |__-
| | | | |
| | | | |__tab_name_1:
| | | | | |
| | | | | |__xpath: tabXpath
| | | | | |
| | | | | |__fieldsets:
| | | | | | |
| | | | | | |__-
| | | | | | | |
| | | | | | | |__fieldset_name_1:
| | | | | | | | |
| | | | | | | | |__xpath: fieldsetXpath
| | | | | | | | |
| | | | | | | | |__buttons:
| | | | | | | | | |
| | | | | | | | | |__fieldset_button_name_1: buttonXpath
| | | | | | | | | |__fieldset_button_name_2: buttonXpath
| | | | | | | | | |__fieldset_button_name_3: buttonXpath
| | | | | | | | | |__ ...
| | | | | | | | |
| | | | | | | | |__checkboxes:
| | | | | | | | | |
| | | | | | | | | |__checkbox_name_1: checkboxXpath
| | | | | | | | | |__checkbox_name_2: checkboxXpath
| | | | | | | | | |__ ...
| | | | | | | | |
| | | | | | | | |__dropdowns:
| | | | | | | | | |
| | | | | | | | | |__dropdown_name_1: dropdownXpath
| | | | | | | | | |__dropdown_name_2: dropdownXpath
| | | | | | | | | |__ ...
| | | | | | | | |
| | | | | | | | |__links:
| | | | | | | | | |
| | | | | | | | | |__link_name_1: linkXpath
| | | | | | | | | |__link_name_2: linkXpath
| | | | | | | | | |__ ...
| | | | | | | | |
| | | | | | | | |__multiselects:
| | | | | | | | | |
| | | | | | | | | |__multiselect_field_name_1: Xpath
| | | | | | | | | |__multiselect_field_name_2: Xpath
| | | | | | | | | |__ ...
| | | | | | | | |
| | | | | | | | |__fields:
| | | | | | | | | |
| | | | | | | | | |__field_name_1: fieldXpath
| | | | | | | | | |__field_name_2: fieldXpath
| | | | | | | | | |__ ...
| | | | | | | | |
| | | | | | | | |__radiobuttons:
| | | | | | | | | |
| | | | | | | | | |__radiobutton_name_1: radiobuttonXpath
| | | | | | | | | |__radiobutton_name_2: radiobuttonXpath
| | | | | | | | | |__ ...
| | | | | | | | |
| | | | | | | | |__required: [required_field_name1, required_field_name2, ....]
| | | | | | |
| | | | | | |__-
| | | | | | | |
| | | | | | | |__fieldset_name_2:
| | | | | | | | |
| | | | | | | | |__xpath: fieldsetXpath
| | | | | | | | |
| | | | | | | | |__ ...
| | | | | | | | |
| | | | | | | | |__ ...
| | | | | | |
| | | | | | |__-
| | | | | | | |
| | | | | | | |__fieldset_name_3:
| | | | | | | | |
| | | | | | | | |__xpath: fieldsetXpath
| | | | | | | | |
| | | | | | | | |__ ...
| | | | | | | | |
| | | | | | | | |__ ...
| | | |
| | | |__-
| | | | |
| | | | |__tab_name_2:
| | | | | |
| | | | | |__xpath: tabXpath
| | | | | |
| | | | | |__fieldsets:
| | | | | | |
| | | | | | |__-
| | | | | | | |
| | | | | | | |__fieldset_name_4:
| | | | | | | | |
| | | | | | | | |__xpath: fieldsetXpath
| | | | | | | | |
| | | | | | | | |__ ...
| | | | | | | | |
| | | | | | | | |__ ...
| |
| |__buttons:
| | |
| | |__button_name_1: buttonXpath
| | |__button_name_2: buttonXpath
| |
| |__messages:
| | |
| | |__success_saved_message: Xpath
| | |__success_deleted_message: Xpath
| | |__error_message: Xpath
| | |__ ...
Create a new *.yml file under /magento-afw-x.x.x/uimaps, either by using the UIMap template or by creating a custom one using the
example:
Create a new *.yml file under /magento-afw-x.x.x/data with the following structure:
Example of Custom DataSet Structure
all_fields_store_view:
store_name: Main Website Store
store_view_name: Test Store View Name 2
store_view_code: test_store_view_code_2
store_view_status: Enabled
store_view_sort_order: 1
/**
* Create Store. Fill in only required fields.
* Steps:
* 1. Click 'Create Store' button.
* 2. Fill in required fields.
* 3. Click 'Save Store' button.
* Expected result:
* Store is created.
* Success Message is displayed
*/
public function test_WithRequiredFieldsOnly()
{
//Data
$storeData = $this->loadData('generic_store', Null, 'store_name');
//Steps
$this->clickButton('create_store');
$this->fillForm($storeData);
$this->saveForm('save_store');
//Verifying
$this->assertTrue($this->successMessage('success_saved_store'), $this->messages);
$this->assertTrue($this->checkCurrentPage('manage_stores'),
'After successful creation store should be redirected to Manage Stores page');
}
}
Scenario 1 - Verifying the Catalog Advanced Search page with valid data:
Expected result: The product should be displayed on the Advanced Search Results page.
Scenario 2 - Verifying the Catalog Advanced Search error message with empty fields:
Expected result: The error message "Please specify at least one search term." should be displayed.