Пример #1
0
 public function saveHtml(Behat\Behat\Hook\Scope\AfterStepScope $scope)
 {
     if (!$scope->getTestResult()->isPassed()) {
         $session = $this->featureContext->getSession();
         $page = $session->getPage();
         $fileName = str_replace(array(' ', ','), '-', $scope->getFeature()->getTitle());
         if (!file_exists($this->html_dump_path)) {
             mkdir($this->html_dump_path);
         }
         $date = date('Y-m-d H:i:s');
         $url = $session->getCurrentUrl();
         $html = $page->getContent();
         $html = "<!-- HTML dump from behat  \nDate: {$date}  \nUrl:  {$url}  -->\n " . $html;
         $htmlCapturePath = $this->html_dump_path . '/' . $fileName . '.html';
         file_put_contents($htmlCapturePath, $html);
         $message = "\nHTML saved to: " . $this->html_dump_path . "/" . $fileName . ".html";
         $message .= "\nHTML available at: " . $this->html_dump_url . "/" . $fileName . ".html";
         echo $message;
     }
 }
Пример #2
0
 public function iLoginAs($user)
 {
     if (isset($this->users[$user])) {
         $this->featureContext->visit("user");
         $name = $this->featureContext->getSession()->getPage()->findField("name");
         $name->setValue($user);
         $pass = $this->featureContext->getSession()->getPage()->findField("pass");
         $pass->setValue($this->users[$user]);
         $login = $this->featureContext->getSession()->getPage()->find("css", "#edit-submit");
         $login->click();
         $escapedValue = $this->featureContext->getSession()->getSelectorsHandler()->xpathLiteral($user);
         $text = $this->featureContext->getSession()->getPage()->find('named', array('content', $escapedValue));
         if (isset($text) && $text != NULL) {
             return true;
         } else {
             throw new Exception("Can't login as the user " . $user . " with password: '******'. Check its credentials are ok in the \$users array");
         }
     } else {
         throw new Exception("Can't find the user " . $user . " in the test user array. Edit the Logger.php class and add its credentials :).");
     }
 }