jerrywright's avatar

Dusk runs only a single test

Hi,

I've recently picked up Dusk and have put together a handful of test classes. From the docs I understand that

php artisan dusk should perform all tests, but it doesn't work for me. It just seems to run one of the tests (the most recently created one). If I use php artisan dusk {path/to/filename.php} I can run individual tests (and they're each running to completion without errors) but it's becoming a pain to trigger each test in turn.

Tests sit in tests/Browser and they each seem to behave as you'd expect.

One thing I did notice is that I have nothing about Dusk in my phpunit.xml file, and no obvious Dusk config file. Should I have one?

Laravel 5.8.38, PHP 7.4, Dusk 5.11

Thanks

0 likes
4 replies
bugsysha's avatar

Strange one. Can you provide any screenshots of your terminal when running tests and maybe code from one of the test classes?

jerrywright's avatar

So I'm running from the project root

The test I most recently wrote was CurrecyTest.php which is the one that I think is running...

<?php

namespace Tests\Browser;

use App\Currency;
use App\User;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Log;

class CurrencyTest extends DuskTestCase
{
    /**
     * A Dusk test example.
     *
     * @return void
     */
    public function testPageLoad()
    {
        $this->browse(function (Browser $browser) {
			$adminUser = User::join('role_user', 'user_USR_PK', '=', 'USR_PK')
				->join('ST_ROL_ROLES', 'ROL_PK', '=', 'role_ROL_PK')
				->where('ROL_NAME', '=', 'IT & DEV')
				->first();

			$message = 'user selected: '. json_encode($adminUser);
			Log::info(basename(__FILE__, '.php') . '->' . __FUNCTION__ . ': ' . $message);

			$browser->loginAs($adminUser)
				->assertAuthenticated();

			$currency = Currency::inRandomOrder()
				->first();

			$browser->visit('/systemAdmin/currencies')
                    ->assertSee('Currencies')
					->assertSeeIn('.card-header a.create', 'Add Currency')
					->waitFor('#results-table')
                    ->assertSeeIn('#results-table', $currency->CUR_CODE);

			$browser->click('.card-header a.create')
				->waitForLocation('/systemAdmin/currencies/create')
				->assertSee('Add Currency')
				->assertSeeIn('.card-header a.back', 'Back');
		});
    }
}

jerry@Caesar:~/wroot/site$ php artisan dusk --verbose
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.21
Configuration: /var/www/site/phpunit.dusk.xml

.                                                                   1 / 1 (100%)

Time: 4.06 seconds, Memory: 28.00 MB

OK (1 test, 6 assertions)
jerry@Caesar:~/wroot/site$ 

Running the BookingSearchTests, for example...

jerry@Caesar:~/wroot/site$ php artisan dusk tests/Browser/BookingSearchTests.php --verbose
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.21
Configuration: /var/www/site/phpunit.dusk.xml

..                                                                  2 / 2 (100%)

Time: 9.31 seconds, Memory: 30.00 MB

OK (2 tests, 11 assertions)
jerry@Caesar:~/wroot/site$

That file /var/www/site/phpunit.dusk.xml doesn't exist, btw. Should it, and what should it contain?

Thanks

Hashim's avatar

@jerrywright In my case I found this was down to PHPUnit's bizarre convention that all test files and classes - stated nowhere in the Laravel Dusk documentation, of course - must end with the Test suffix. Try renaming BookingSearchTests.php to BookingSearchTest.php (and the class to BookingSearchTest) and see if it makes a difference.

1 like

Please or to participate in this conversation.