/** * 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'); }
/** * 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]; }
/** * 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'); } }
/** * 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; }