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

Playwright #18927

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AdrienClairembault
Copy link
Contributor

@AdrienClairembault AdrienClairembault commented Feb 5, 2025

Description

Setup playwright and migrate two tests cypress tests files.

It does seems faster locally, the 2 migrated tests take ~15 seconds with 6 threads on my machine (vs 28 seconds for their cypress equivalent on the CI).

On the CI, the improvement seems less impressive (unsure why, it even seems slower).
Maybe there isn't enough tests to properly compare.
Anyway, I've saved a trace of its execution to investigate it next week (the work can still be reviewed).

Regarding the tests themselves, they feel nicer to write.
Cypress was great at the start because it is easy to get started, however as you go on you face many issues when you try to do more complicated things due to its design choices (thenable everywhere that is not a real promise, command pattern, ...).

For that, playwright feels much better IMO.
It requires a bit more time to understand it at the start but after that it get quite smooth due to its design which is way more predictable.

@AdrienClairembault AdrienClairembault self-assigned this Feb 5, 2025
@AdrienClairembault AdrienClairembault force-pushed the playwright branch 8 times, most recently from 5c5bc1a to 48aafcd Compare February 7, 2025 15:54
@AdrienClairembault
Copy link
Contributor Author

Don't worry about sonar cloud failure, it report a new OS command execution but it should be safe given its just a call to glpi's console:

image

@trasher
Copy link
Contributor

trasher commented Feb 7, 2025

Don't worry about sonar cloud failure, it report a new OS command execution but it should be safe given its just a call to glpi's console:
[...]

Iv'e marked it as safe

@cconard96
Copy link
Contributor

Not a fan of using TypeScript. That's both a personal thing and also a worry that it makes writing E2E tests less desirable for the developers that already don't work with JavaScript a lot. Also, working with TypeScript is incredibly frustrating in PHPStorm. There have been too many times I've Ctrl + Click a JS function related to a library to try and see the code for it, only to be directed to the useless .d.ts file for it. Same issue started happening when TS files were being added to the Cypress tests. I don't see the benefit of it at all, and only downsides. I voiced my opinion about it before, but that was when we only had a .d.ts file added for Cypress commands all to fix VSCode behavior (which I also don't like but I know others are using it and it was an OK solution to fix autocomplete).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be handled during the installation of GLPI like we handled with Cypress?
We should have a PHP script that handles test environment data and then include it during the installation when the env is testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That actually what we do not want to have anymore.
It isn't convenient because you can't run the test locally unless you are in the right environnement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an additional note, maybe we could force the environnement to switch to testing when running e2e tests.


public async getToken()
{
// TODO: try to reuse a single csrf token per worker if it is possible.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stealing CSRF tokens from unrelated pages sounds very weird and something we shouldn't be doing. Actions should be actual form submissions when needed or use AJAX which already handles automatically sending a CSRF token.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same code from cypress migrated to playwright (nothing new here).
AJAX does not automatically send a CRSF token in this context as this code is not executed on a GLPI's page.


test('can remove tiles', async ({ page }) => {
// Make sure the tile exist before trying to delete it
await expect(config_page.getTile("Request a service")).toBeVisible();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan that we trade command queuing for "await hell". At the very least, we should be careful to not use await for every single line of playwright test code. Should use Promise.all when possible to run things together at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO (and most online opinions from what I can tell) await is correct modern way of using javacript while cypress command queue is an un-intuitive nightmare that lead to callback hell.

throw new Error(`Unknown profile: ${profile}`);
}

await this.request.post(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be AJAX rather than a fake form submit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AJAX POST request, not sure what mean here.
If by "fake subit" you refer to the CSRF token, it is required since we changed this endpoint to accept only POST queries on GLPI's 11.

@AdrienClairembault
Copy link
Contributor Author

Not a fan of using TypeScript. That's both a personal thing and also a worry that it makes writing E2E tests less desirable for the developers that already don't work with JavaScript a lot. Also, working with TypeScript is incredibly frustrating in PHPStorm. There have been too many times I've Ctrl + Click a JS function related to a library to try and see the code for it, only to be directed to the useless .d.ts file for it. Same issue started happening when TS files were being added to the Cypress tests. I don't see the benefit of it at all, and only downsides. I voiced my opinion about it before, but that was when we only had a .d.ts file added for Cypress commands all to fix VSCode behavior (which I also don't like but I know others are using it and it was an OK solution to fix autocomplete).

It is the recommended way to setup playwright.

Here is an extract form the documentation:

TypeScript in Playwright works out of the box and gives you better IDE integrations. Your IDE will show you everything you can do and highlight when you do something wrong. No TypeScript experience is needed and it is not necessary for your code to be in TypeScript, all you need to do is create your tests with a .ts extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants