Labs

Magium Automated Magento Testing Setup

By 31.07.17October 11th, 2017No Comments

[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

  1. Java JDK
  2. Selenium standalone server v2.53
  3. Google Chrome
  4. Google chrome web driver
  5. XVFB (optional)
  6. PHPUnit

Installation

  1. Download and install Java in your system. Get java JDK from here ( http://www.oracle.com/technetwork/java/javase/downloads/ ) and install
  2. Download Selenium standalone server ( http://selenium-release.storage.googleapis.com/index.html )
  3. 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
  4. Install XVFB (only if you want to run the tests on headless mode)
    // Debian/Ubuntu
    sudo apt-get install xvfb
  5. 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
  6. 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
  7. 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

  1. 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
  2. cd magium
  3. To start the server:
    ./magium
  4. To connect to the server: in the browser go to
    http://localhost:4444/wd/hub/static/resource/hub.html
  5. To add Magium to a Magento project:
    composer require magium/magento

Setup Selenium with WebDriver on your machine

  1. Read How to start/connect to Magium server: Magium
  2. Download Selenium Server and Chrome WebDriver
  3. 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

  1. You must have the Composer on your machine.
  2. Run Composer:
    composer update

    or

    php composer.phar update
  3. Run Magium installing:
    composer require magium/magium
  4. Run Magento library installing:
    composer require magium/magento
  5. 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.

  6. And with that you should see 15 tests running and passed after a few minutes.

Your tests

  1. Make new folder ‘mytests’ in Magium directory.
  2. Make new file ‘phpunit.xml.dist’ in mytests folder. File Contents:phpunit.xml.dist
    
    
    
                AbstractTestCase/phpunit.priority.xml
                .
    
    
    
    
  3. Make one more folder ‘AbstractTestCase’ in mytests directory.
  4. Make new php file with name ‘BaseTest’ or anything in this directory.
  5. 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');
      }
    
    
    
    }
  6. 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