Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create screenshot after failed selenium command

The PHPUnit Selenium base class has an option to make a screenshot on failure, which is a huge help in finding out why the test failed. The selenium server, however, returns an error instead of a failure on any error condition other than explicit assert* calls (such us trying to do something with a non-existent element). If I try to make a screenshot after the server reports the error, I get another error saying that the server already discarded the session. Is there any way to change that behavior?

Update: this is because PHPUnit breaks the connection when it receives an error. I was able to change it by some (rather ugly) manipulation of the PHPUnit code.

like image 378
Tgr Avatar asked May 30 '26 14:05

Tgr


1 Answers

Make those interactions as test cases.

For example in perl, If it is written as below and fails due to a non-existent element. the script will error out

$sel->type("email-id","trial\@trial.com");

While if the above step is made as a test case by writing it as follows

$sel->type_ok("email-id","trial\@trial.com");

If there is a non-existent element, the test case will only fail, and the script will continue.

So using TAP (test any protocol) by using the module use Test::More; , if _ok is added after a function, the function return will be used to determine the fate of the test case.

ie. - A return of 'O' means the test Failed

and A return of '1' means the test Passed

like image 139
Amey Avatar answered Jun 01 '26 20:06

Amey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!