0
votes

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());
    }

}
?>
1
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?Nodir Rashidov
I don't think there is any, given that it's not yet compatible. github.com/giorgiosironi/phpunit-selenium/pull/404ndm
@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 testNodir Rashidov
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.ndm
@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/176a76d46031fe6f4063f6fb0834d838Nodir Rashidov

1 Answers

1
votes

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.