0

Hi people,

I would like to know if somebody knows how to send an email from a test in selenium/php I'm trying to do this :

<?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";
    }
  }

}

When i go in the " if($cpt >3)" my server go out telling me : Argument 5 passed to PHPUnit_Framework_Error::__construct() must be an instance of Exception, array given, called in C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\Exten sions\SeleniumTestCase.php on line 1152 and defined

tomzi
  • 1,215
  • 1
  • 12
  • 23
  • I don't understand. Shouldn't the email be sent at backend? So then you don't need to send it trough selenium, just doing the application normal workflow should send it. – Skatox Sep 26 '12 at 14:12
  • what do you mean by the email should be sent at backend? I need to send an email specificly at this point if something occurs – tomzi Sep 26 '12 at 14:22
  • i found this : http://www.lastcraft.com/fakemail.php – tomzi Sep 26 '12 at 14:49

2 Answers2

1

I found how to by writing a log file when an error accurs and i created a Cron to send an email by checking if the file exists or not

This is my code :

<?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";
      }
   }

}
?>

And the Cron is :

<?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');
    } 
}
?>
tomzi
  • 1,215
  • 1
  • 12
  • 23
0

I think this is due to backward compatibily break of PHPUnit 3.7.1.
I solved it by downloading phpunit/phpunit-selenium using composer.

Stephan
  • 41,764
  • 65
  • 238
  • 329
  • Thanks for the answer but the fact is i had already downloaded phpunit-selenium... – tomzi Sep 27 '12 at 06:48
  • I'm wondering if it wouldn't be easier to create a file. It would be like a log file that i write in php which will be set with a message telling what's going on. Actually i tried it by using the php function fopen,fputs,fclose but when i do my test...nothing is wrote in the file ....... help me please – tomzi Sep 27 '12 at 07:07