Exemplo n.º 1
0
 /**
  * Runs a Selenium_TestCase, useful if we are running an interactive Test with assertions
  * @param array $configEntry Single test-node from XML
  * @param Codex_Xtest_Xtest_Selenium_TestCase $testObject Passed testObject, needs to implement doGeneralAssert
  */
 protected function doPageTest(array $configEntry, Codex_Xtest_Xtest_Selenium_TestCase $testObject)
 {
     /**
      * @var Codex_Xtest_Xtest_Pageobject_Frontend_Homepage $page
      */
     $page = $testObject->getPageObject('xtest/pageobject_frontend_homepage');
     $urlinfo = parse_url(Mage::getBaseUrl());
     $urlinfo['path'] = trim($urlinfo['path']) . $configEntry['url']['url'];
     if ($configEntry['url']['method'] === 'get') {
         $urlinfo['query'] = $configEntry['url']['params'];
     }
     $url = $this->http_build_url($urlinfo);
     $page->url($url);
     if (!empty($configEntry['clickon'])) {
         if (is_string($configEntry['clickon'])) {
             $elements = $page->findElementsByCssSelector($configEntry['clickon']);
             foreach ($elements as $element) {
                 $element->click();
             }
         } else {
             if (is_array($configEntry['clickon'])) {
                 foreach ($configEntry['clickon'] as $clickElement) {
                     $elements = $page->findElementsByCssSelector($clickElement);
                     foreach ($elements as $element) {
                         $element->click();
                     }
                 }
             }
         }
     }
     $responseBody = $page->source();
     if (is_array($configEntry['assert'])) {
         foreach ($configEntry['assert'] as $assert) {
             $assert = $this->stringParser($assert);
             $page->assertContains($assert, $responseBody, 'Assert failed: ' . $assert);
         }
     } else {
         $assert = $this->stringParser($configEntry['assert']);
         $page->assertContains($assert, $responseBody, 'Assert failed: ' . $assert);
     }
     $page->takeResponsiveScreenshots($configEntry['rendername']);
     $testObject->doGeneralAssert($responseBody);
 }
Exemplo n.º 2
0
 public function renderHtml($name, $html, $sleep = 0, $waitForAjax = true)
 {
     $file = null;
     try {
         $fileName = uniqid() . '.html';
         $file = Mage::getBaseDir() . '/' . $fileName;
         file_put_contents($file, $html);
         $test = new Codex_Xtest_Xtest_Selenium_TestCase();
         $test->run();
         /** @var Codex_Xtest_Xtest_Pageobject_Abstract $page */
         $page = $test->getPageObject('xtest/pageobject_abstract');
         $page->url(dirname(Mage::getBaseUrl('media')) . '/' . $fileName);
         sleep($sleep);
         if ($waitForAjax) {
             $page->waitForAjax();
         }
         $page->takeResponsiveScreenshots($name);
         foreach ($test->getScreenshots() as $screen) {
             $this->_screenshots[] = $screen;
         }
     } catch (Exception $e) {
         if ($file && is_file($file)) {
             unlink($file);
         }
         throw $e;
     }
     if ($file && is_file($file)) {
         unlink($file);
     }
 }