-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Introduction to E2E Playwright testing #6641
Comments
Please assign this task to me as I don't have enough permissions to do it by myself |
Cleaner can be done in 2 ways:
First option is time-consuming due to fact resetting database can take about 1-2 min, when run after each test, the amount of time spend on waiting until commands are finished might be higher than on the tests itself but the amount of code is insignificant. (OS shell driver required) Second option is better as it allows to test additional cases like user deleting some objects within one test and the time spent on deleting objects created during the test is lower but the amount of code required to secure all cases is significantly higher compared to first option. Both approaches should be used, first one in case there are scenarios requiring to delete objects created by default (e.g. after first login to workspace) or in case something bad happens, second by default. |
In the future when integration tests with Google will be implemented, instead of using the UI for accessing the mails and calendar, tests should use the API Google provides, this way, it'll be easier to implement (in case the account will be secured using 2FA, it'll be easier to work with) and faster (compared to normal access with UI) with the same result (question is how email can be checked whether its' content [formatted HTML] is the same as in the mockups, using built-in Of course, if the app will support at some point in the future other mail and calendar providers such as Microsoft or Apple, the general rule of thumb is to use API for reasons stated above if possible, if not (like for Proton Mail, there is Python module maintained by the company but not JS/TS library https://github.com/ProtonMail/proton-python-client), then API documentation reference: |
Playwright offers a way to test REST API using built-in However, many people are using Postman for (automated) API testing which supports REST and GraphQL API without bigger problems (additionally, it can get GraphQL schema from the link easily) as well as additional features such as workflows, tests within API requests, exporting environments and more. While this option would be great, it's only nice to have as supporting both solutions will take too much time and effort unless better solution will be found in the future. For now, it's better to use only Playwright. Documentation reference: |
When using app, user has to log in to its account in order to perform any action. In tests, the same logic must be saved (logging in as the first step) but that brings up a problem which is logging before each test. The first solution mimics the user's behaviour but adds additional ~20 sec to time execution of each test, while the second solution saves that time. The question is what about different users when role based access will be added. Storage states (second solution) seem like a good option. Documentation: |
@lucasbordeau added item to Tasklist, by default Playwright scrolls by itself but if that's not enough, it can be done by simulating mouse wheel behaviour or scrolling enough to see specific element on screen. Either way, to check and simulate this, I need to add several objects as I'm running tests from fresh setup each time. Documentation: |
When interacting with page, users are interacting with it by clicking on elements, e.g. clicking on button to complete the transaction or on link to redirect to seemingly normal page only to be rickrolled. In tests, those elements can be located using several options such as But XPath should be used if built-in locators into Playwright fail as last resort. Documentation: |
Since Twenty added webhooks (essentially allowing for integration with different, not officially supported apps with Zapier), these should be tested if are working. Playwright does not offer any way to test them (nor does any other framework), thus the third-party provider should be used for this. There are plenty of sites offering intercepting/receiving webhooks, notably one of them being https://webhook.site TBD if verifying webhooks should be done within the E2E tests. |
Found issue #5583 with interesting solution for Postman testing, if it works like described there, then should it be used together with Playwright? Writing Playwright tests for API is a good option considering fact there are no tests for API and when done correctly, they can be used inside tests, e.g. test checking if object created by API is visible in UI, has correct data, etc. |
When somewhere in the future, the need for load performance tests will appear, we should test the app under extreme conditions (one example is given in #4817). The problem appears with:
Problem 1. can be solved by:
Problem 2. can be solved by creating realistic guidelines for such cases and modifying test to use x independent contexts (or pages if that's possible) simulating users (but here's catch, how to write test in such way that each "user" will perform on different objects so it won't lead to overwriting the same data over and over?) |
Something worth noting, normally when writing tests, it's normal to use the CSS selector to locate specific element IF the app doesn't change classes, in Twenty most components have 1 class which change depending on theme whether it's dark or light, essentially making them impossible to use in tests as locators. We should never resort to using CSS for this reason unless there's very specific reason (even then, we could opt out for XPath). Also, while writing all necessary components for tests, it's possible to find a component by text inside component, but this will become a problem when localization tests will be introduced. All components in tests must be language- and theme-agnostic so there won't be a need to refactor a huge chunk of code just to allow writing localization tests and/or testing in different mode than light/dark mode. |
What do you think about :
|
Using data-testid attributes isn't a bad idea, I'm using it only when I know I can't locate an element easily (like it was with workspace dropdown because it couldn't be hardcoded [who knows what workspace will be default after changing some things and forgetting to revert them]), XPath on one hand is known to be durable but on the other hand writing a XPath made out of 20 divs just to reach one element is something I wouldn't do unless I have to (maybe I'm overexaggerating but I hope you get the idea), also, it's not that hard to fix a XPath. I'll use them if anything else fails or there'll be need for automated localisation tests (locating by text/label won't work there so other methods must be used to locate specific elements). About automated localisation tests, are you planning to use them in the future? |
Ok, I don't think localization will be implemented soon, so maybe a good starting compromise would be fetch by text + data-testid when more precision and stability is required ? |
That's quite what we already have for storybook integration tests. |
@BOHEUS Another important thing to keep in mind, let's also not test only happy paths but also check that we shouldn't be able to do what we can't do and that we shouldn't see what shouldn't be displayed (to be defined). |
@BOHEUS one of our priority next week will be to integrate your end to end tests to our release flow. We will likely rework seed and have a clean environment to run them against |
Thanks for the info @charlesBochet, if you'll need my help, ping me |
Will do! |
Based on all notes above as well as talk with @prastoin earlier this week, other issues I were mentioned in, changes made in Twenty repo adding new functionality, some research in the meantime and more, here's rough "plan" (order of elements may not apply to order in which specific steps will be done):
More info just to be aware:
|
Excellent ! The POM is a good pattern to implement from the outset. Be careful not to fall into premature optimization. We'll see how we'll need utils, XPath, etc. We should have a way to launch commands, to reset the database, create demo data, this way if we need to add a command for E2E tests we can create it in the server and the E2E test will just call it, what do you think ? |
@lucasbordeau I've already implemented it in #6717, it's |
Ok, maybe we'll need some class / module that wraps this shell driver to execute specific functions : But let's see when we'll have the concrete need in front of us. |
We shouldn't optimize for the subscription pattern right now, it's too premature and we don't know what will be implemented and how. Our knowledge of E2E testing and our tooling around it should be sufficiently evolved, should subscription be implemented, that refactoring for subscription will be doable in a reasonable amount of time. Plus we have already done major refactors and continue to do so, it's in our culture, so nothing to be afraid of here. |
Parallelization shouldn't be our main focus since E2E tests won't be run as frequently as other unit tests. Plus it's easy with Playwright to just re-run the failed ones by hand while we're in the process of manually preparing and testing everything before a release, which should be our main focus. Our persona for this E2E testing is the person who will spend multiple days to manually release and review everything, test, migrate, etc. And E2E test should be a manual step for expanding the coverage of testing before a release. |
Also I think we shouldn't prioritize testing complex E2E features right now like emails, remote table, stripe, etc. It would be better to just seed the database with a snapshot of real world emails data from a Twenty instance. Because the main goal is to help the review process right now. But we should certainly implement those E2E tests in a second phase, because they are very hard to test thoroughly at each release. I think that the first of those cases of E2E test we want is around login, subscription, cancellation, etc. With a staging stripe account and fake credit cards. |
Parallelization will be main focus once there are tests covering different areas of the product and CI/CD pipelines for tests are available, it's more of a note for future myself or someone else rather than a goal for now. |
For testing things which require additional sites like emails, here are some possibilities:
|
If there's need to find in page's source code disappearing element which appears only on hover, here is StackOverflow thread with solutions (trick with JS debugger works fine) |
This issue is a parent for all future PR and issues
Description
Since more and more issues/requests appear for E2E tests, here are some things which need to be addressed before progressing:
While this shouldn't prevent from creating issues/requests for tests, this must be addressed ASAP so technical debt will be minimised
Based on all of the things described above (some of them are taken from here where I described them earlier), here's checklist
TO DO
This checklist ^ may be updated in the future
Stages
Materials:
The text was updated successfully, but these errors were encountered: