Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebDriver screenshot at failure is throwing an error #961

Closed
mhightower opened this issue Apr 1, 2014 · 17 comments
Closed

WebDriver screenshot at failure is throwing an error #961

mhightower opened this issue Apr 1, 2014 · 17 comments

Comments

@mhightower
Copy link
Contributor

codeception v1.8.4

I'm running the WebDriver module and getting this error when a test fails.
Fatal error: Call to a member function takeScreenshot() on a non-object in /Users/mhightower/PhpstormProjects/SauceExtension/vendor/codeception/codeception/src/Codeception/Module/WebDriver.php on line 163

What I'm seeing is that the WebDriver::_after() is destroying the WebDriver::$webDriver object before WebDriver::_saveScreenshot() is called. WebDriver::_saveScreenshot() is using the WebDriver::$webDriver object to create the screenshot.

I have confirmed that the WebDriver::webDriver was created successfully.

I'm trying to decide if adding a check for the webdriver object is a good fix or if it is a defect further up in the logic?

@DavertMik
Copy link
Member

_failed is called before _after. At least that is how it supposed to be...

@mhightower
Copy link
Contributor Author

You are correct, _after is being called before _failed.
The call to \Codeception\TestCase\Test::tearDown() which calls _after()
https://github.com/Codeception/Codeception/blame/1.8/src/Codeception/TestCase/Test.php#L58

Question does $this->_after() really need to be called?
test.After event should hit everything.

@mhightower
Copy link
Contributor Author

I removed both _after() and fire() from \Codeception\TestCase\Test::tearDown() and it works except it is going to ignore the webdriver restart config.

@wyhmichael
Copy link
Contributor

Hey @mhightower,

Wondering how you got the error?

Are you using Test with webdriver or Cest with webdriver?

@mhightower
Copy link
Contributor Author

I'm using Test. It seems to be calling _after() then _failed() then _after() again.
The tearDown() is calling _after() and firing off a test.after if I remember correctly.

@wyhmichael
Copy link
Contributor

@mhightower , I see, I think Test is better for making unit test in codeception, if you want to do selenium tests or tests interacting with browsers, Cest is better option for you

To be frank, I never used Test with Webdriver, thought it's for unit tests, but not 100% sure.

@mhightower
Copy link
Contributor Author

I'm using Test because it gives me a few more options and more familiar with PHPUnit. I will take a look at Cest but I think if we can give tearDown() function the correct calls it would work fine.

@DavertMik
Copy link
Member

@mhightower Yep, that's an interesting case. Not sure what else calls test.after event. As it was supposed test.after should be called in teardown method only. Can you run with a debugger and get a stacktrace for both cases when after is called, if you say it is calling twice?

@mhightower
Copy link
Contributor Author

Here are the two function traces.
one _after()
two _after()
Just search for WebDriver->_after()

@DavertMik
Copy link
Member

sorry, I can't open this format. Can you put traces here?

@mhightower
Copy link
Contributor Author

The links are publicly viewable and they are big are you sure you can't see them from google drive?

@DavertMik
Copy link
Member

You may think of me as tech (google) idiot. And probably I am :) But GDrive opens file trace..1396640462.xt (what is xt format for?) without any preview.

@mhightower
Copy link
Contributor Author

You then just download the file. .xt is just a plain text file that xdebug produced.

@mturalenka
Copy link

get the same issue. not every time but with rarely frequency.
@mhightower have you resolved the issue?
PS.
used codeception v1.8.5 with selenium server with xpra X buffering tool

@DavertMik
Copy link
Member

Outdated. Reopen if it is still relevant

@mturalenka
Copy link

codeception 2.0.8
got the same issue:

PHP Fatal error: Call to a member function takeScreenshot() on a non-object in phar:///usr/ib/ui_tests/codecept.phar/src/Codeception/Module/Webdriver.php on line 219

for sure i can wrap $this->webDriver->takeScreenshot($filename); in if-isset condition, but it will be better to fix issue
@DavertMik please reopen ticket

@FnTm
Copy link
Contributor

FnTm commented Dec 17, 2014

Getting the same error using 2.1.0:

PHP Fatal error:  Call to a member function takeScreenshot() on a non-object in /var/www/example/vendor/codeception/codeception/src/Codeception/Module/WebDriver.php on line 250
PHP Stack trace:
PHP   1. {main}() /var/www/example/vendor/codeception/codeception/codecept:0
PHP   2. Symfony\Component\Console\Application->run() /var/www/example/vendor/codeception/codeception/codecept:27
PHP   3. Symfony\Component\Console\Application->doRun() /var/www/example/vendor/symfony/console/Symfony/Component/Console/Application.php:126
PHP   4. Symfony\Component\Console\Application->doRunCommand() /var/www/example/vendor/symfony/console/Symfony/Component/Console/Application.php:195
PHP   5. Symfony\Component\Console\Command\Command->run() /var/www/example/vendor/symfony/console/Symfony/Component/Console/Application.php:874
PHP   6. Codeception\Command\Run->execute() /var/www/example/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:252
PHP   7. Codeception\Codecept->run() /var/www/example/vendor/codeception/codeception/src/Codeception/Command/Run.php:191
PHP   8. Codeception\Codecept->runSuite() /var/www/example/vendor/codeception/codeception/src/Codeception/Codecept.php:139
PHP   9. Codeception\SuiteManager->run() /var/www/example/vendor/codeception/codeception/src/Codeception/Codecept.php:156
PHP  10. Codeception\PHPUnit\Runner->doEnhancedRun() /var/www/example/vendor/codeception/codeception/src/Codeception/SuiteManager.php:153
PHP  11. PHPUnit_Framework_TestSuite->run() /var/www/example/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:100
PHP  12. PHPUnit_Framework_TestCase->run() /var/www/example/vendor/phpunit/phpunit/src/Framework/TestSuite.php:751
PHP  13. PHPUnit_Framework_TestResult->run() /var/www/example/vendor/phpunit/phpunit/src/Framework/TestCase.php:729
PHP  14. PHPUnit_Framework_TestResult->addError() /var/www/example/vendor/phpunit/phpunit/src/Framework/TestResult.php:724
PHP  15. Codeception\PHPUnit\Listener->addError() /var/www/example/vendor/phpunit/phpunit/src/Framework/TestResult.php:269
PHP  16. Codeception\PHPUnit\Listener->fire() /var/www/example/vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php:51
PHP  17. Symfony\Component\EventDispatcher\EventDispatcher->dispatch() /var/www/example/vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php:101
PHP  18. Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() /var/www/example/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php:53
PHP  19. call_user_func:{/var/www/example/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php:164}() /var/www/example/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php:164
PHP  20. Codeception\Subscriber\Module->failed() /var/www/example/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php:164
PHP  21. Codeception\Module\WebDriver->_failed() /var/www/example/vendor/codeception/codeception/src/Codeception/Subscriber/Module.php:72
PHP  22. Codeception\Module\WebDriver->_saveScreenshot() /var/www/example/vendor/codeception/codeception/src/Codeception/Module/WebDriver.php:186

I do think this is a valid cause for reopening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants