0

I want to learn about ui testing with selenium in phpunit. I had phpunit installed on my cakephp project, and it was running perfectly. Then I decided to install selenium following the steps described in https://phpunit.de/manual/3.7/en/selenium.html (i installed selenium in my project with the following command $ php composer.phar require --dev phpunit/phpunit-selenium: ">=1.2". Now after starting the selenium server with its jar file, I have been trying to run the example test provided in the link above, but I am receiving the following error:

$ vendor/bin/phpunit

PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /var/www/html/ujols/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php on line 97

Seems like the error is related to the Selenium2TestCase.php file that was installed with the composer. This is how the Selenium2TestCase.php file starts:

abstract class PHPUnit_Extensions_Selenium2TestCase extends PHPUnit_Framework_TestCase
{

Is there anyone here who managed to install selenium on cakephp or any other php framework? I would be super grateful if you could help me fix the problem

EDIT the sample test case i ve been trying to run to check if selenium is working:

PlainviewTest.php

<?php

class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
    protected function setUp()
    {
        $this->setBrowser('firefox');
        $this->setBrowserUrl('http://www.example.com/');
    }

    public function testTitle()
    {
        $this->url('http://www.example.com/');
        $this->assertEquals('Example WWW Page', $this->title());
    }

}
?>
9
  • noticed that I was actually looking at phpunit 3.7 manual while i had version 6 installed... Does anyone have a link for the installation manual for selenium in phpunit6? Commented Mar 22, 2017 at 14:45
  • I don't think there is any, given that it's not yet compatible. github.com/giorgiosironi/phpunit-selenium/pull/404 Commented Mar 22, 2017 at 19:15
  • @ndm thank you for your comment! How about facebook's php-webdriver? github.com/facebook/php-webdriver i tried implementing it, but I cannot figure out how to run the test Commented Mar 22, 2017 at 22:35
  • 1
    Check out the docs Testing framework integration section, besides the more sophisticated integration via Steward, there's also some very basic manual PHPUnit integration example. The webdriver library itself has no "testing functionality", it's just a connection to Selenium that you can use in any PHP script you want. Commented Mar 23, 2017 at 12:55
  • @ndm thank you so much for sharing it!!!! I have installed it and I am trying to run their example test asserting w3.org title, but when i run the test it says ` [ERROR] Testcases executed: 1 (fatal: 1) `, the log file is empty.. here is my file gist.github.com/nodirashidov/176a76d46031fe6f4063f6fb0834d838 Commented Mar 23, 2017 at 14:09

1 Answer 1

1

I figured a way to get selenium integrated with phpunit in my app with a lot of help from @ndm, here are the steps:

Follow the easy installation steps here - Testing with Selenium WebDriver + PHPUnit

*Make sure your new ui-tests are not in the same folder with unit tests, I had mine in the same folder and kept getting fatal errors.

*If running the ./vendor/bin/steward run staging firefox command returns an error, then change firefox to chrome. If you still keep getting error (like I did), install chromedriver and run again. It should work.

It was really worth all the effort.

Sign up to request clarification or add additional context in comments.

1 Comment

one more thing, if you want to set this up inside a php framework, then you should create a new separate folder in your project (as it says in the installation manual), and init a new composer there instead of using the existing phpunit of the framework. Otherwise the selenium will clash with regular phpunit tests and will keep exiting with fatal errors

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.