コード例 #1
0
 /**
  * Get singleton instance
  *
  * @return Menta_ConfigurationPhpUnitVars
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new Menta_ConfigurationPhpUnitVars();
     }
     return self::$instance;
 }
コード例 #2
0
ファイル: Common.php プロジェクト: aoemedia/menta
 /**
  * Get main domain.
  * Fetches main domain from configuration if not set manually
  *
  * @return string
  */
 public function getMainDomain()
 {
     if (is_null($this->mainDomain)) {
         $this->mainDomain = Menta_ConfigurationPhpUnitVars::getInstance()->getValue('testing.maindomain');
         $this->mainDomain = rtrim($this->mainDomain, '/');
     }
     return $this->mainDomain;
 }
コード例 #3
0
ファイル: RectangleProcessor.php プロジェクト: aoemedia/menta
 public function process()
 {
     // TODO copy file to backup location
     // TODO check if file exists
     // System call to actually crop the image
     $command = Menta_ConfigurationPhpUnitVars::getInstance()->getValue('screenshot.command_rectangle');
     $command = sprintf($command, intval($this->x1), intval($this->y1), intval($this->x2), intval($this->y2), escapeshellarg($this->color), escapeshellarg($this->fill ? $this->color : 'none'), escapeshellarg($this->imageFile));
     exec($command);
 }
コード例 #4
0
 /**
  * Generic clean up in case a session already was started before
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $mainDomain = Menta_ConfigurationPhpUnitVars::getInstance()->getValue('testing.maindomain');
     $this->getHelperCommon()->setMainDomain($mainDomain . $this->urlPrefix);
     if (Menta_SessionManager::activeSessionExists()) {
         // clear cart
         $cart = Menta_ComponentManager::get('MagentoComponents_Pages_Cart');
         /* @var $cart MagentoComponents_Pages_Cart */
         $cart->clearCart();
         // logout
         $customerAccount = Menta_ComponentManager::get('MagentoComponents_Pages_CustomerAccount');
         /* @var $customerAccount MagentoComponents_Pages_CustomerAccount */
         $customerAccount->logoutViaOpen();
     }
 }
コード例 #5
0
ファイル: Bootstrap.php プロジェクト: aoemedia/menta
 /**
  * Initialize basic component system
  */
 public static function init()
 {
     define('MENTA_ROOTDIR', dirname(__FILE__));
     // Provide configuration object to all components
     Menta_Events::addObserver('before_component_get', function (Menta_Component_Abstract $component) {
         // set configuration to each component
         $component->setConfiguration(Menta_ConfigurationPhpUnitVars::getInstance());
         // pass current test to components inheriting from Menta_Component_AbstractTest
         if ($component instanceof Menta_Component_AbstractTest && isset($GLOBALS['current_testcase']) && $GLOBALS['current_testcase'] instanceof PHPUnit_Framework_TestCase) {
             /* @var $component Menta_Component_AbstractTest */
             $component->setTest($GLOBALS['current_testcase']);
         }
     });
     $shutDownCallback = array('Menta_Bootstrap', 'closeSeleniumSession');
     if (function_exists('pcntl_signal')) {
         declare (ticks=1);
         pcntl_signal(SIGTERM, $shutDownCallback);
         pcntl_signal(SIGINT, $shutDownCallback);
     }
     register_shutdown_function($shutDownCallback);
     // will also be called on "PHP Fatal Error"
 }
コード例 #6
0
ファイル: Selenium1.php プロジェクト: aoemedia/menta
 /**
  * @return Menta_ConfigurationPhpUnitVars
  */
 public function getConfiguration()
 {
     return Menta_ConfigurationPhpUnitVars::getInstance();
 }
コード例 #7
0
ファイル: Selenium2.php プロジェクト: aoemedia/menta
 /**
  * Take a screenshot
  *
  * @param string $title
  * @param string $description
  * @param string $type
  * @param array $trace
  * @param string $id
  * @param string $variant
  * @return bool|Menta_Util_Screenshot
  */
 public function takeScreenshot($title = NULL, $description = NULL, $type = NULL, array $trace = NULL, $id = NULL, $variant = NULL)
 {
     // don't init a new session if there is none
     if (!Menta_SessionManager::activeSessionExists()) {
         return false;
     }
     if (Menta_ConfigurationPhpUnitVars::getInstance()->getValue('testing.selenium.skipScreenshots', false)) {
         return false;
     }
     // fire events
     $eventParamaters = array('test' => $this);
     Menta_Events::dispatchEvent('before_taking_screenshot', $eventParamaters);
     $screenshot = $this->getScreenShot();
     $screenshot->setTitle($title);
     $screenshot->setTrace(!is_null($trace) ? $trace : debug_backtrace());
     if (!is_null($id)) {
         $screenshot->setId($id);
     }
     if (!is_null($description)) {
         $screenshot->setDescription($description);
     }
     if (!is_null($type)) {
         $screenshot->setType($type);
     }
     if (!is_null($variant)) {
         $screenshot->setVariant($variant);
     }
     $this->screenshots[] = $screenshot;
     Menta_Events::dispatchEvent('after_taking_screenshot', $eventParamaters);
     return $screenshot;
 }
コード例 #8
0
 /**
  * Create pdiff
  *
  * @param $imageA
  * @param $imageB
  * @param $target
  * @throws Exception
  */
 public function createPdiff($imageA, $imageB, $target)
 {
     $command = Menta_ConfigurationPhpUnitVars::getInstance()->getValue('report.pdiff_command');
     $command = sprintf($command, escapeshellarg($imageA), escapeshellarg($imageB), escapeshellarg($target));
     // TODO: check return value
     exec($command);
 }
コード例 #9
0
ファイル: bootstrap.php プロジェクト: aoemedia/menta
    }
    // window size
    try {
        if ($configuration->issetKey('testing.selenium.windowSize')) {
            list($width, $height) = explode('x', $configuration->getValue('testing.selenium.windowSize'));
            $width = intval(trim($width));
            $height = intval(trim($height));
            if (empty($height) || empty($width)) {
                throw new Exception('Invalid window size');
            }
            $session->window('main')->size(array('width' => $width, 'height' => $height));
        }
    } catch (Exception $e) {
        // nevermind
    }
    // implicit wait
    try {
        if ($configuration->issetKey('testing.selenium.timeoutImplicitWait')) {
            $time = $configuration->getValue('testing.selenium.timeoutImplicitWait');
            $time = intval($time);
            $session->timeouts()->implicit_wait(array('ms' => $time));
        }
    } catch (Exception $e) {
        // nevermind
    }
});
// Provide configuration object to all components
Menta_Events::addObserver('after_component_create', function (Menta_Component_Abstract $component) {
    $component->setConfiguration(Menta_ConfigurationPhpUnitVars::getInstance());
});
// WebDriver_Base::$debugFile = 'debug.txt';
コード例 #10
0
<?php

define('TEST_ROOTDIR', dirname(__FILE__) . '/../');
require_once TEST_ROOTDIR . 'vendor/autoload.php';
Menta_Bootstrap::init();
Menta_ConfigurationPhpUnitVars::addConfigurationFile(TEST_ROOTDIR . 'conf/defaults.xml');
// Initialize session manager and provider selenium server url
$configuration = Menta_ConfigurationPhpUnitVars::getInstance();
Menta_SessionManager::init($configuration->getValue('testing.selenium.seleniumServerUrl'), $configuration->getValue('testing.selenium.browser'), $configuration->getValue('testing.selenium.capabilities'));
// Do some stuff based on configuration values after the session is initialized
Menta_Events::addObserver('after_session_create', function (\WebDriver\Session $session, $forceNew) {
    $configuration = Menta_ConfigurationPhpUnitVars::getInstance();
    // window focus
    try {
        if ($configuration->issetKey('testing.selenium.windowFocus') && $configuration->getValue('testing.selenium.windowFocus')) {
            $session->window('main');
            // focus
        }
    } catch (Exception $e) {
        // nevermind
    }
    // window position
    try {
        if ($configuration->issetKey('testing.selenium.windowPosition')) {
            list($x, $y) = explode(',', $configuration->getValue('testing.selenium.windowPosition'));
            $x = intval(trim($x));
            $y = intval(trim($y));
            $session->window('main')->postPosition(array('x' => $x, 'y' => $y));
        }
    } catch (Exception $e) {
        // nevermind