Beispiel #1
0
 public function testTitle()
 {
     $session = Menta_SessionManager::getSession();
     $session->open('http://www.google.com/ncr');
     $assertHelper = Menta_ComponentManager::get('Menta_Component_Helper_Assert');
     /* @var $assertHelper Menta_Component_Helper_Assert */
     $assertHelper->setTest($this)->assertTitle('Google');
     Menta_SessionManager::closeSession();
 }
Beispiel #2
0
 /**
  * Close existing Selenium server sessions
  *
  * @return void
  */
 public static function closeSeleniumSession()
 {
     try {
         if (Menta_SessionManager::activeSessionExists()) {
             echo "\n[Closing remote selenium session]\n";
             Menta_SessionManager::closeSession();
         }
     } catch (Exception $e) {
         echo "[closeSeleniumSession] EXCEPTION: " . $e->getMessage();
     }
     exit;
 }
 /**
  * Will send the test result to sauce labs in case we're running tests there
  *
  * @return void
  */
 protected function tearDown()
 {
     if (Menta_SessionManager::activeSessionExists()) {
         $status = $this->getStatus();
         if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
             $passed = false;
         } else {
             $passed = true;
         }
         $sauceUserId = $this->getConfiguration()->getValue('testing.sauce.userId');
         $sauceAccessKey = $this->getConfiguration()->getValue('testing.sauce.accessKey');
         if (!empty($sauceUserId) && !empty($sauceAccessKey)) {
             $rest = new WebDriver\SauceLabs\SauceRest($sauceUserId, $sauceAccessKey);
             $rest->updateJob(Menta_SessionManager::getSessionId(), array(WebDriver\SauceLabs\Capability::PASSED => $passed));
         }
     }
     parent::tearDown();
 }
Beispiel #4
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');
     }
 }
Beispiel #5
0
 /**
  * Get session
  *
  * @return \WebDriver\Session
  */
 public function getSession()
 {
     return Menta_SessionManager::getSession();
 }
Beispiel #6
0
 /**
  * @param string $title
  *
  * @return Menta_Util_Screenshot
  */
 public function getScreenShot($title = '')
 {
     // don't init a new session if there is none
     if (!Menta_SessionManager::activeSessionExists()) {
         return false;
     }
     $screenshotHelper = Menta_ComponentManager::get('Menta_Component_Helper_Screenshot');
     /* @var $screenshotHelper Menta_Component_Helper_Screenshot */
     $base64Image = $screenshotHelper->takeScreenshotToString();
     $time = time();
     // put data into the screenshot object
     $screenshot = new Menta_Util_Screenshot();
     $screenshot->setBase64Image($base64Image);
     $screenshot->setTime($time);
     if (!is_null($title)) {
         $screenshot->setTitle($title);
     }
     $screenshot->setLocation($this->getSession()->url());
     return $screenshot;
 }
Beispiel #7
0
<?php

// bootstrap php-webdriver (assuming it is in a directorey "php-webdriver" next to the Menta root directory
require_once dirname(__FILE__) . '/../../php-webdriver/WebDriver/__init__.php';
// bootstrap Menta testing framework
require_once dirname(__FILE__) . '/../bootstrap.php';
// Add additional files (with default values) to configuration
Menta_ConfigurationPhpUnitVars::addConfigurationFile(dirname(__FILE__) . '/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'));
// 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')->position(array('x' => $x, 'y' => $y));
        }