Ejemplo n.º 1
0
 /**
  * Open an url prefixed with the previously configured browserUrl
  *
  * @param string $url
  * @return \WebDriver\Session
  */
 public function open($url)
 {
     if (!preg_match('/^https?:/i', $url)) {
         $url = rtrim($this->getMainDomain(), '/') . '/' . ltrim($url, '/');
     }
     Menta_Events::dispatchEvent('open', array('url' => $url));
     // check for hashes
     $pos = strpos($url, '#');
     if ($pos !== false) {
         // if we're on a different page we need to go to the new page first (Selenium doesn't seem to do this automatically)
         $currentUrl = $this->getSession()->url();
         if (preg_match('/^https?:/i', $currentUrl)) {
             // url could be "about:blank" if no page was loaded before
             $targetUrl = substr($url, 0, $pos);
             $currentPos = strpos($currentUrl, '#');
             if ($currentPos !== false) {
                 $currentUrl = substr($currentUrl, 0, $currentPos);
             }
             if ($targetUrl != $currentUrl) {
                 $this->getSession()->open($targetUrl);
             }
         }
     }
     return $this->getSession()->open($url);
 }
 /**
  * Login
  *
  * @param string $username
  * @param string $password
  */
 public function login($username = NULL, $password = NULL)
 {
     if (is_null($username) || is_null($password)) {
         $username = $this->getConfiguration()->getValue('testing.frontend.user');
         $password = $this->getConfiguration()->getValue('testing.frontend.password');
     }
     $this->openSplitLoginOrRegister();
     $this->getHelperCommon()->type("//input[@id='email']", $username, true, true);
     $this->getHelperCommon()->type("//input[@id='pass']", $password, true, true);
     Menta_Events::dispatchEvent('MagentoComponents_Pages_CustomerAccount->login:beforeSubmit', array('component' => $this));
     $this->getHelperCommon()->click($this->getSplitPageLoginButtonPath());
     $this->getHelperAssert()->assertBodyClass('customer-account-index');
 }
Ejemplo n.º 3
0
 /**
  * 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"
 }
Ejemplo n.º 4
0
 /**
  * Get component
  *
  * @static
  * @throws Exception|InvalidArgumentException
  * @param string $component
  * @param string $instanceKey
  * @return Menta_Interface_Component
  */
 public static function get($component, $instanceKey = 'default')
 {
     if (empty($component) || !is_string($component)) {
         throw new InvalidArgumentException('Parameter "component" must be a classname');
     }
     if (empty($instanceKey) || !is_string($instanceKey)) {
         throw new InvalidArgumentException('Parameter "instanceKey" must be a non empty string');
     }
     $originalComponentClass = $component;
     // resolve rewrite
     if (isset(self::$rewrites[$component])) {
         $component = self::$rewrites[$component];
     }
     if (!isset(self::$components[$component])) {
         self::$components[$component] = array();
     }
     if (!isset(self::$components[$component][$instanceKey])) {
         if (!class_exists($component)) {
             throw new Exception('Could not find component ' . $component);
         }
         self::$components[$component][$instanceKey] = new $component();
         if (!self::$components[$component][$instanceKey] instanceof Menta_Interface_Component) {
             throw new Exception("Component '{$component}' does not implement interface 'Menta_Interfaces_Component'");
         }
         if ($originalComponentClass != $component && !self::$components[$component][$instanceKey] instanceof $originalComponentClass) {
             throw new Exception("Rewrite '{$component}' does not extend original class '{$originalComponentClass}'");
         }
         // fire events
         $eventParamaters = array('component' => self::$components[$component][$instanceKey], 'instanceKey' => $instanceKey);
         Menta_Events::dispatchEvent('after_component_create', $eventParamaters);
         Menta_Events::dispatchEvent('after_component_create_' . $component, $eventParamaters);
     }
     $eventParamaters = array('component' => self::$components[$component][$instanceKey], 'instanceKey' => $instanceKey);
     Menta_Events::dispatchEvent('before_component_get', $eventParamaters);
     Menta_Events::dispatchEvent('before_component_get_' . $component, $eventParamaters);
     return self::$components[$component][$instanceKey];
 }
Ejemplo n.º 5
0
 /**
  * Close existing session
  *
  * @static
  * @return void
  */
 public static function closeSession()
 {
     if (self::activeSessionExists()) {
         Menta_Events::dispatchEvent('before_session_close', array('session' => self::$session));
         self::$session->close();
         self::$session = NULL;
         Menta_Events::dispatchEvent('after_session_close');
     }
 }
Ejemplo n.º 6
0
 /**
  * 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;
 }
Ejemplo n.º 7
0
    }
    // 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';
Ejemplo n.º 8
0
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
    }
    // 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')->postSize(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
    }
});