Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e testing support #1053

Open
4 tasks
dsebastien opened this issue Nov 4, 2024 · 3 comments
Open
4 tasks

Add e2e testing support #1053

dsebastien opened this issue Nov 4, 2024 · 3 comments
Labels
code_quality Improve code quality and reduce maintenance overhead P3 Affects a small number of users or is largely cosmetic quality_assurance Quality Assurance (QA) SHOULD Nice to have testing Unit tests and/or continuous integration
Milestone

Comments

@dsebastien
Copy link
Member

dsebastien commented Nov 4, 2024

Goal: be able to define and run e2e tests.

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

  • Add and configure Laravel Dusk
  • Create e2e test scenarios (registration, login, etc)
  • Make sure tests run locally: php artisan dusk
  • Execute e2e tests in CI

References:

Running on GH actions:

@dsebastien dsebastien added testing Unit tests and/or continuous integration quality_assurance Quality Assurance (QA) SHOULD Nice to have code_quality Improve code quality and reduce maintenance overhead P3 Affects a small number of users or is largely cosmetic labels Nov 4, 2024
@dsebastien dsebastien added this to the IDEAS milestone Nov 4, 2024
@dsebastien dsebastien added this to Knowii Nov 4, 2024
@dsebastien dsebastien moved this to Backlog in Knowii Nov 4, 2024
@dsebastien
Copy link
Member Author

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
Copy link
Member Author

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

@dsebastien
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code_quality Improve code quality and reduce maintenance overhead P3 Affects a small number of users or is largely cosmetic quality_assurance Quality Assurance (QA) SHOULD Nice to have testing Unit tests and/or continuous integration
Projects
Status: Backlog
Development

No branches or pull requests

1 participant