0

こんにちは

私はこれをやろうとしているセレン/phpのテストからメールを送信する方法を誰かが知っているかどうか知りたいです:

<?php

class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  protected function setUp()
  {
    $this->setBrowser("chrome");
    $this->setBrowserUrl("http://recette2011.thalys.com/");
    $this->setSpeed(500);
  }

  public function testMyTestCase()
  {
    $this->open("/be/en");
    $this->click("link=Help");
    $this->waitForPageToLoad("30000");
    $this->click("id=multi_block_title_span_element_2");
    $this->click("id=demande_information");
    $this->click("id=type_billet_information_aucun");
    $this->click("id=btn_valider");
    $this->waitForPageToLoad("30000");
    $url = $this->getLocation();
    echo $url;
    $cpt = substr_count ($url, "&");
    if($cpt >3){
        if(mail('ths@bytesandcom.be','Test',"Le test a foiré"))
        {
            echo "message sent";
        }
        else
        {
            echo "sent message failed";
        }
        echo "test failed";
    }
    else
    {
        echo "Test Granted";
    }
  }

}

「if($cpt >3)」に入ると、サーバーから次のように言われます: PHPUnit_Framework_Error::__construct() に渡される引数 5 は、C:\wamp\bin\ で呼び出される例外のインスタンスである必要があります。 php\php5.3.5\PEAR\PHPUnit\Extensions\SeleniumTestCase.php の 1152 行で定義済み

4

2 に答える 2

1

エラーが発生したときにログファイルを書き込む方法を見つけ、ファイルが存在するかどうかを確認してメールを送信するCronを作成しました

これは私のコードです:

<?php

class Example extends PHPUnit_Extensions_SeleniumTestCase
{
  protected function setUp()
  {
    $this->setBrowser("*firefox");
    $this->setBrowserUrl("http://recette2011.thalys.com/");
    $this->setSpeed(500);
  }

  public function testMyTestCase()
  {
      $this->open("/be/en");
      $this->click("link=Help");
      $this->waitForPageToLoad("30000");
      $this->click("id=multi_block_title_span_element_2");
      $this->click("id=demande_information");
      $this->click("id=type_billet_information_aucun");
      $this->click("id=btn_valider");
      $this->waitForPageToLoad("30000");
      $url = $this->getLocation();
      echo $url;
      $cpt = substr_count ($url, "&");
      if($cpt >3){
         $date = date("d-m-Y");
         $heure = date("H:i");
         $monfichier = fopen('C:\Users\intégrateur\Desktop\testSelenium\logSelenium.txt', 'a+');
         fputs($monfichier, '-- Probleme dans le fichier PasBillet.php le '.$date.' a '.$heure.' -- ');
         fclose($monfichier);
      }
      else
      {
          echo "Test Granted";
      }
   }

}
?>

そしてCronは次のとおりです。

<?php
$file = "C:\Users\intégrateur\Desktop\testSelenium\logSelenium.txt";
if(file_exists($file))
{
    if(filesize($file)>0)
    {
        mail('ths@bytesandcom.be','Probleme selenium','Une erreur est survenue dans un test de formaulaire. Pour plus d\'info consulter le fichier logSelenium.txt');
    } 
}
?>
于 2012-09-27T10:55:40.210 に答える
0

これは、コンポーザーを使用PHPUnit 3.7.1.
してダウンロードすることで解決したの下位互換性の破れによるものだと思います。phpunit/phpunit-selenium

于 2012-09-26T16:31:49.777 に答える