orchestral / testbench-dusk

Laravel Dusk Testing Helper for Package Development
https://packages.tools/testbench-dusk
MIT License
101 stars 14 forks source link

I get Fatal error: Uncaught Error: Class "P\Tests\Browser\ExampleTest" #107

Closed namumakwembo closed 2 days ago

namumakwembo commented 3 days ago

Description:

i get the following error (from error screenshot)when i try to run the test ,Please assist. Note: i am using pest

Fatal error: Uncaught Error: Class "P\Tests\Browser\ExampleOneTest" not found in /Users/yodah/Desktop/Workspace/packages/wirechat/wirechat/vendor/orchestra/testbench-dusk/src/server.php:37 Stack trace: #0 {main} thrown in /Users/yodah/Desktop/Workspace/packages/wirechat/wirechat/vendor/orchestra/testbench-dusk/src/server.php on line 37

Steps To Reproduce:

My DuskTestCase


class DuskTestCase extends  \Orchestra\Testbench\Dusk\TestCase

{
    use WithWorkbench; 

    // /**
    //  * Create the RemoteWebDriver instance.
    //  */
    protected function driver(): RemoteWebDriver
    {
        $options = (new ChromeOptions)->addArguments(collect([ '--start-maximized',
        ])->unless($this->hasHeadlessDisabled(), function (Collection $items) {
            return $items->merge([
                '--disable-gpu',
                //'--headless=new',
            ]);
        })->all());

        return RemoteWebDriver::create( 'http://localhost:9515',
            DesiredCapabilities::chrome()->setCapability(
                ChromeOptions::CAPABILITY, $options
            )
        );
    }

    protected function getPackageProviders($app)
    {
        return [
          //  ServiceProvider::class,
            LivewireServiceProvider::class,
            MyPackageServiceProvider::class,
            DuskServiceProvider::class
        ];
    }

    protected function setUp(): void
    {
        parent::setUp(); 

        $this->loadMigrationsFrom(
            workbench_path('database/migrations')
        );
        //\Orchestra\Testbench\Dusk\Options::withUI();
        $this->withoutVite();

    }

    protected function getEnvironmentSetUp($app)
    {

        View ::addLocation('../resources/views');
        tap($app['session'], function ($session) {
            $session->put('_token', str()->random(40));
        });

        tap($app['config'], function ($config) {
            $config->set('app.env', 'testing');

            $config->set('app.debug', true);

            //update wirechat userModel
            $config->set('app.debug', true);

            $config->set('view.paths', [__DIR__.'/views', resource_path('views')]);

            $config->set('app.key', 'base64:Hupx3yAySikrM2/edkZQNQHslgDWYfiBfCuSThJ5SK8=');

            $config->set('database.default', 'testbench');

            $config->set('database.default', 'sqlite');
            $config->set('database.connections.testbench', [
                'driver' => 'sqlite',
                'database' => ':memory:',
                'prefix' => '',
            ]);
                      // Setup queue database connections.
                      $config->set('queue.batching.database', 'testbench'); 
                      $config->set('queue.failed.database', 'testbench');
        });
    }

 }

My testbench.yaml

providers:
  - Namu\WireChat\MyPackageServiceProvider

migrations:
  - workbench\database\migrations

seeders:
  - Workbench\Database\Seeders\DatabaseSeeder

#laravel: "./laravel"

workbench:
  start: '/'
  install: true
  user: test@example.com
  discovers:
    web: true
    api: false
    commands: true
    components: true
    views: false
  build: [
    - drop-sqlite-db
    - create-sqlite-db
    - migrate:refresh

  ]
  assets: []
  sync: [
  ]
crynobone commented 3 days ago

I don't see anything here that would specifically indicate the issue. We does tests with Pest via https://github.com/orchestral/pest-plugin-testbench/blob/3.x/tests/Browser/BrowserTest.php

Also, it's odd that you changed the view path at runtime and tests without vite. The whole point of Dusk tests it to test your application on the actual Browser with CSS and JS.

crynobone commented 3 days ago

Also, in-memory database doesn't work with Dusk since web server and test are 2 separate php instance. You need persistent database here.

namumakwembo commented 2 days ago

I don't see anything here that would specifically indicate the issue. We does tests with Pest via https://github.com/orchestral/pest-plugin-testbench/blob/3.x/tests/Browser/BrowserTest.php

Also, it's odd that you changed the view path at runtime and tests without vite. The whole point of Dusk tests it to test your application on the actual Browser with CSS and JS.

I don't see anything here that would specifically indicate the issue. We does tests with Pest via https://github.com/orchestral/pest-plugin-testbench/blob/3.x/tests/Browser/BrowserTest.php

Also, it's odd that you changed the view path at runtime and tests without vite. The whole point of Dusk tests it to test your application on the actual Browser with CSS and JS.

Thank you for your response.

To clarify, I modified the view path and disabled Vite as part of troubleshooting to isolate the issue, but even after reverting those changes and using a minimal configuration in my DuskTestCase, I am still encountering the same error.

I am following the installation steps outlined in the documentation here: Testbench Dusk Installation. However, I suspect I may have missed something during the setup. As my next step, I’ll try reinstalling the package from scratch to ensure everything is correctly configured

The error : screeen shot

Screen Shot 2024-09-14 at 01 38 43
crynobone commented 2 days ago

There's nothing in your description that could indicate an issue.

namumakwembo commented 2 days ago

I'm still facing issues running my tests, and I’m having trouble understanding what’s causing the error as shown in the screenshot . I’ve followed the installation guide closely and simplified my setup, but the problem persists. I would appreciate any help in understanding the error more clearly