3

I am completely new to Seleniu, and am trying to set up PHPUnit with Selenium 2, following this tutorial https://www.youtube.com/watch?v=zva_GETXimI

So far this is what I've done:

Installed PHPUnit using PHAR as instructed here https://phpunit.de/manual/current/en/installation.html

Installed Selenium Server

Upgraded to PHP5.6 (but my Apache is still 2.22 instead of 2.4)

Installed PHPUnit_selenium package using Composer

Created a testLogin.php file:

<?php

class testLogin extends PHPUnit_Extensions_Selenium2TestCase{

    public function setUp()


    {
        $this->setHost('localhost');
        $this->setPort(4444);
        $this->setBrowser('firefox');
        $this->setBrowserUrl('http://localhost/Achievers');
    }

}

When I run testLogin.php using 'phpunit testLogin.php' I get an error:

Class 'PHPUnit_Extensions_Selenium2TestCase' not found in /home/osadmin/projects/Sel/testLogin.php on line 5

Since I am just starting out, I have no idea how to fix this. On googling the error, it shows to add this line to my php file:

require_once('PHPUnit/Extensions/Selenium2TestCase.php');

But I'm not sure how I can use this since there is no PHPUnit folder, just a file linked to the PHAR.

Could someone please shed some light on how to fix this issue?

Thanks.

EDIT:

As per Ushakov's suggestion, I tried /path/to/phpunit.phar testLogin.php

But it gives the same error.

If I add this line to the testLogin.php: require_once('/usr/local/bin/phpunit');

and run /path/to/phpunit.phar testLogin.php

I get this:

#!/usr/bin/env php
PHP Notice:  Constant __PHPUNIT_PHAR__ already defined in /usr/local/bin/phpunit on line 18
PHP Notice:  Constant __PHPUNIT_PHAR_ROOT__ already defined in /usr/local/bin/phpunit on line 19
PHP Fatal error:  Cannot redeclare class DeepCopy\DeepCopy in phar:///usr/local/bin/phpunit/myclabs-deep-copy/DeepCopy/DeepCopy.php on line 15
2
  • Did you tryed run /path/to/phpunit.phar testLogin.php ? Commented Oct 29, 2015 at 10:01
  • Tried it, same error. Posted some edit in the original question Commented Oct 29, 2015 at 20:50

2 Answers 2

4

Solved it by adding this line to the PHP file:

require_once 'vendor/autoload.php';

No tutorial I have seen mentions this, but it can be found in github projects

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

2 Comments

Yeah it didn't solve the issue. Showing this error: Declaration of PHPUnit_Extensions_Selenium2TestCase::run(?PHPUnit\Framework\TestResult $result = NULL) must be compatible with PHPUnit\Framework\Test::run(?PHPUnit\Framework\TestResult $result = NULL): PHPUnit\Framework\TestResult in /Applications/MAMP/htdocs/selenium/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php on line 596
this answer didn't solve it for me ..
0

For anyone else coming late to the party - this worked for me:

class testLogin extends \PHPUnit\Extensions\Selenium2TestCase

(Using PHP 7.0.3 and installing Selenium package with Composer ).

Comments

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.