2

I want to write some browser tests using phpunit-selenium, Now this is my test class

<?php

namespace Tests\System;

use Tests\TestCase;

class LoginTest extends TestCase
{

    /**
     * @test
     */
    public function showLoginPage()
    {
        $this->url('/');
        $this->assertTrue(true);
    }
}

And this is the testCase class that i have made to add extra methods and properties to it

<?php

namespace Tests;
require_once dirname(__DIR__) . '/vendor/autoload.php';
use PHPUnit\Extensions\Selenium2TestCase;

class TestCase extends Selenium2TestCase {

    public function setUp(): void
    {
        $config = new \Config('test');
        $this->setDesiredCapabilities([
            'chromeOptions'=>['w3c' => false, "args"  => [
                '--no-sandbox',
                '--disable-gpu',
                '--headless',
                '--verbose',
                '--whitelisted-ips='
            ]]]);
        $this->setHost('localhost');
        $this->setPort(4444);
        $this->setBrowserUrl('http://localhost/');
        $this->setBrowser('chrome');
        $this->shareSession(true);
    }

}

Now when i run vendor/bin/phpunit it runs around 366 tests. But they are not tests, They are methods in the assert class. For example it runs this methods

Tests\System\LoginTest::objectHasAttribute
Tests\System\LoginTest::classHasStaticAttribute
Tests\System\LoginTest::classHasAttribute

What did i understand from that response is that, Somehow it not understand to run only those methods which has @test annotation or has prefix test. And the final file is phpunit.xml file

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php"
         backupGlobals="false"
>

    <testsuites>
        <testsuite name="PHPUnit">
            <directory suffix="Test.php">Tests</directory>
        </testsuite>
    </testsuites>

</phpunit>

I appreciate any help, Thanks.

2
  • What package versions do you use, especially PHPUnit and Selenium extension? Commented Feb 2, 2021 at 12:05
  • I encountered the same problem with phpunit 9.5.4, phpunit-selenium 9.0.0 and php 7.4.21 Commented Jul 23, 2021 at 11:41

1 Answer 1

2

In my case, I was using phpunit 9.5.4 and phpunit-selenium 9.0.0.

Apparently phpunit-selenium is not compatible with phpunit >= 9.4.0. There is an open issue for this: https://github.com/giorgiosironi/phpunit-selenium/issues/453

So the solution (for me) was to downgrade phpunit to 9.3.x:

composer require --dev phpunit/phpunit:9.3.*

Apparently the same problem also occurs for phpunit 8.5.9: https://github.com/sebastianbergmann/phpunit/issues/4516

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

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.