PHPUnit Selenium captureScreenshotOnFailure not working?

I am using PHPUnit 3.4.12 to test selenium tests. I would like to get a screenshot automatically when the test failed. This should be supported as described in http://www.phpunit.de/manual/current/en/selenium.html#selenium.seleniumtestcase.examples.WebTest2.php

class WebTest { protected $captureScreenshotOnFailure = true; protected $screenshotPath = 'C:\selenium'; protected $screnshotUrl = 'http://localhost/screenshots'; public function testLandingPage($selenium) { $selenium->open("http://www.example.com"); $selenium->fail("fail"); ... } } 

As you can see, I am making the test unsuccessful and theoretically, when it does, it should take a screenshot and place it in C: \ selenium, since I am running the selenium RC server on Windows.

However, when I run the test, it just gives me the following:

 [ root@testbox selenium]$ sh run PHPUnit 3.4.12 by Sebastian Bergmann. F Time: 8 seconds, Memory: 5.50Mb There was 1 failure: 1) WebTest::testLandingPage fail /home/root/selenium/WebTest.php:32 FAILURES! Tests: 1, Assertions: 0, Failures: 1. 

I do not see screenshots in C: \ selenium. However, I can get a screenshot with $ selenium-> captureScreenshot ("C: /selenium/image.png");

Any ideas or suggestions are most welcome.

thanks

+4
source share
3 answers

Error handling in this case is pretty poor in terms of phpunit; if everything is not perfect, he silently ignores your other options without warning.

As Dave noted, if any of the variables is mistakenly written, it will work silently, and you can also try to assign them to an instance in your setUp.

In addition, not every condition triggers a screenshot. Try $ selenium-> assertTextPresent ("foobarbaz") instead of your $ selenium-> fail () to see if it works.

+2
source

you can try adding this line of codes

     try {
         $ this-> assertTrue ($ this-> isTextPresent ("You searched for \" Brakes \ "(2 matches)"));
     } catch (PHPUnit_Framework_AssertionFailedError $ e) {
         array_push ($ this-> verificationErrors, $ e-> toString ());
         $ this-> drivers [0] -> captureEntirePageScreenshot ($ this-> screenshotPath. DIRECTORY_SEPARATOR. rawurlencode ($ this-> getLocation ()). '.png');
     }

+2
source

I recently got this error because I was following the tutorial.

The first example in the documentation is for PHPUnit_Extensions_Selenium2TestCase . All the others on the page are for PHPUnit_Extensions_SeleniumTestCase .

Maybe change

 extends PHPUnit_Extensions_Selenium2TestCase 

to

 extends PHPUnit_Extensions_SeleniumTestCase 
0
source

Source: https://habr.com/ru/post/1309947/