knowii-oss / knowii

Knowii is a next-gen Community Knowledge Management platform
https://knowii.net
GNU Affero General Public License v3.0
9 stars 1 forks source link

Add e2e testing support #1053

Open dsebastien opened 3 weeks ago

dsebastien commented 3 weeks ago

Goal: be able to define and run e2e tests.

We should add Laravel Dusk and a few e2e test scenarios.

References:

Running on GH actions:

dsebastien commented 3 weeks ago

To go to specific pages during e2e tests, we should use $browser->visitRoute('name');

To fill-in forms, we can use $browser->type('field name', 'value') or $browser->typeSlowly('field name', 'value', 300) (in ms)

Alternatively, we can add dusk='key' to the form fields so that Dusk can locate those more easily. For instance if we have <input type="text" dusk="name" ..., then we can do $browser->click('@name');

We can also register keyboard macros in AppServiceProvider.php's boot method:

  public function boot(): void {
  Keyboard::macro('selectAll', function() {
    $this->type([
      OperatingSystem::onMac()? WebDriverKeys::META : WebDriverKeys::CONTROL,
      'a',
    ]);
  });

  Keyboard::macro('copy', function() {
    $this->type([
      OperatingSystem::onMac()? WebDriverKeys::META : WebDriverKeys::CONTROL,
      'c',
    ]);
  });

  Keyboard::macro('copyAll', function() {
    $this->type([
      OperatingSystem::onMac()? WebDriverKeys::META : WebDriverKeys::CONTROL,
    ]);
    return $this->copy();
  });

  Keyboard::macro('paste', function() {
    $this->type([
      OperatingSystem::onMac()? WebDriverKeys::META : WebDriverKeys::CONTROL,
      'v'
    ]);
  });
}

With that, tests will be able to simply do: $browser->withKeyboard(fn (Keyboard $keyboard) => $keyboard->copyAll()); ...

dsebastien commented 3 weeks ago

We can also open multiple browsers in a single test: $this->browser(function (Browser $browser1, Browser $browser2) { ... }

dsebastien commented 3 weeks ago

To test pages that require authentication, use $browser->loginAs(User::find(1))->visit('/home');