[nectar_dropcap color=”#00629b”]M[/nectar_dropcap]agium is a Selenium-based testing framework to help automate complex web-based applications such as Magento. It manages much of the complexity of element selection and action execution allowing you to focus on actually building your tests.
In this two-part tutorial we’re going to show you how to install Magium and run some basic tests with it.
Part 1: Download and Install Magium
Requirements
- Java JDK
- Selenium standalone server v2.53
- Google Chrome
- Google chrome web driver
- XVFB (optional)
- PHPUnit
Installation
- Download and install Java in your system. Get java JDK from here ( http://www.oracle.com/technetwork/java/javase/downloads/ ) and install
- Download Selenium standalone server ( http://selenium-release.storage.googleapis.com/index.html )
- Download google chrome web driver ( https://sites.google.com/a/chromium.org/chromedriver/downloads )
// unzip the downloaded driver unzip ~/Downloads/chromedriver_linux64.zip // Make the file you downloaded executable, and move it to /usr/local/share chmod +x ~/Downloads/chromedriver sudo mv -f ~/Downloads/chromedriver /usr/local/share/chromedriver // Create symlink to the chromedriver sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
- Install XVFB (only if you want to run the tests on headless mode)
// Debian/Ubuntu sudo apt-get install xvfb
- Install PHPUnit
// get phpunit wget https://phar.phpunit.de/phpunit.phar // Make executable chmod +x phpunit.phar //Move globally sudo mv phpunit.phar /usr/local/bin/phpunit
- Start selenium server with chrome webdriver
// with graphic interface - java -Dwebdriver.chrome.driver=chromedriver -Dwebdriver.chrome.logfile='/tmp/chrome.log' -jar selenium-server-standalone-2.53.1.jar // without graphic interface - headless mode sudo xvfb-run -a java -Dwebdriver.chrome.driver="chromedriver" -Dwebdriver.chrome.logfile='/tmp/chrome.log' -jar selenium-server-standalone-2.53.1.jar
- To check if selenium server is up and running go to http://127.0.0.1:4444/wd/hub
Get magium and the basic tests
Clone the magium git repo on your local machine
//DO NOT CLONE THE REPO IN YOUR MAGENTO DIRECTORY git clone git@bitbucket.org:accolade_partners/magium.git
Part 2: Connect to Magium server and run some basic tests
In the second part of the tutorial we’ll show you how to connect to the server and run some basic tests.
How to start/connect to Magium server
- If you are in Windows, follow this guide to create an ssh tunnling using putty: http://realprogrammers.com/how_to/set_up_an_ssh_tunnel_with_putty.html, but using the settings 4444:localhost:4444 instead.
If you are in Linux, use
ssh -L 4444:localhost:4444 - cd magium
- To start the server:
./magium - To connect to the server: in the browser go to
http://localhost:4444/wd/hub/static/resource/hub.html - To add Magium to a Magento project:
composer require magium/magento
Setup Selenium with WebDriver on your machine
- Read How to start/connect to Magium server: Magium
- Download Selenium Server and Chrome WebDriver
- Open cmd or Shell and enter request:
java -Dwebdriver.chrome.driver=FULL_PATH_TO_FILE/chromedriver.exe -jar selenium-server-standalone-VERSION_NUMBERS.jar
Magium on XAMPP or PHP IDE or local server
- You must have the Composer on your machine.
- Run Composer:
composer update
or
php composer.phar update
- Run Magium installing:
composer require magium/magium
- Run Magento library installing:
composer require magium/magento
- Run PHPUnit:
If you are using PHPStorm all you need to do is right click on phpunit.xml.dist and select ‘Run phpunit.xml.dist’.
If you are running PHPUnit from the command line you will need to execute:phpunit -c tests/phpunit.xml.dist
May be you need make update your JAVA if you see mistakes about it.
- And with that you should see 15 tests running and passed after a few minutes.
Your tests
- Make new folder ‘mytests’ in Magium directory.
- Make new file ‘phpunit.xml.dist’ in mytests folder. File Contents:phpunit.xml.dist
AbstractTestCase/phpunit.priority.xml .
- Make one more folder ‘AbstractTestCase’ in mytests directory.
- Make new php file with name ‘BaseTest’ or anything in this directory.
- For example php file contents:
BaseTest.php/* The test must open Pamark Home page and go to Blog. */ namespace Tests\Magento\Navigation; use Magium\Magento\AbstractMagentoTestCase; class PageTest extends AbstractMagentoTestCase { public function testPageLinkBlog() { $this->commandOpen('https://pamark.fi/'); $this->byText('Katso kaikki')->click(); $this->assertTitleContains('Ajankohtaista'); } }
- Run PHPUnit:
If you are using PHPStorm all you need to do is right click on phpunit.xml.dist and select ‘Run phpunit.xml.dist’.
If you are running PHPUnit from the command line you will need to execute:phpunit -c mytests/phpunit.xml.dist
More about Magiumlib and quick start tutorials on http://magiumlib.com