Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i stop codeception/selenium from closing the browser window on failed assertions?

I am running codeception 2 with selenium. I can see selenium open the browser and run through the tests. Then I get an error from codeception that there is a failed assertion.

I know there is an HTML file that is saved, but there is a lot of JS, so I can't really analyze that. I need the firefox window to stay open so I can see the output and figure out what is wrong.

How can I do this? I am already running selenium with -browserSessionReuse

If it makes a difference, it's happening inside $I->haveFriend(); $friend->does() statement.

like image 297
DAB Avatar asked Nov 30 '15 22:11

DAB


2 Answers

There no straight solution how to do this, but some tricks can be used:

  1. Use interactive console, follow same steps as in scenario, use assertions which fail - selenium stay open, so you can debug and evaluate what happens.
  2. Use trick with wait. In cest file add "__fail" method where place "wait(300)" (for 5 min). Than on test launch your browser will stay open for 5 min
like image 144
user2064278 Avatar answered Nov 18 '22 01:11

user2064278


If you are running Cest style tests, try

public function _failed(AcceptanceTester $I)
{
     $I->pauseExecution();
}

That will hold the browser window open until you hit enter in case of a failure.

Alternatively, you could take a screenshot upon test failure.

public function _failed(AcceptanceTester $I)
    {
        $I->makeScreenshot('test_failed_screenshot' . time());
    }

This will save a screenshot at the point of failure in tests > output > debug. My cests have several tests within them, so I use the time() to give variation to the failed screenshot names to ensure I have a screenshot for every failed tests.

like image 1
CosetteN Avatar answered Nov 18 '22 01:11

CosetteN