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

test: create colony flow #3327

Closed
wants to merge 16 commits into from
Closed

test: create colony flow #3327

wants to merge 16 commits into from

Conversation

olgapod
Copy link
Contributor

@olgapod olgapod commented Oct 15, 2024

Description

  • Added e2e tests for the Create Colony flow
  • Set up playwright eslint plugin and dotenv

Testing

Prerequisites: The test script simulates user interactions with the local instance of the web app, which means that the BE is expected to be set up and running. For now, backend services should be started manually and the initial test data should be seeded . Therefore, ensure that the development environment is properly set up by following the instructions in the README file

  • Setup and start your local dev environment (all BE services should be up and running) npm run dev

  • Seed the data, if it's not already done before node scripts/create-data.js

  • If it's the first time you run e2e tests on your machine - run npm e2e:install

  • run npm run e2e or npm run e2e:ui

  • Ensure all tests pass

Diffs

New stuff

  • playwright folder is added to the lint script
  • added loading of the .env file into playwright environment

@rdig
Copy link
Member

rdig commented Oct 15, 2024

This shouldn't be based on the master branch, but rather on the playwright changes from #3297

So the base branch should be feat/add-playwright

@olgapod olgapod changed the base branch from master to feat/add-playwright October 15, 2024 13:06
Base automatically changed from feat/add-playwright to master October 15, 2024 13:13
@olgapod olgapod force-pushed the e2e/create-colony-flow branch 2 times, most recently from ffb0989 to cbdf36a Compare October 15, 2024 18:50
@olgapod olgapod changed the title test: create colony flow, step 1 test: create colony flow Oct 15, 2024
@rdig
Copy link
Member

rdig commented Oct 16, 2024

@olgapod please assing yourself to PRs

@olgapod olgapod self-assigned this Oct 16, 2024
@olgapod olgapod marked this pull request as ready for review October 16, 2024 06:49
@olgapod olgapod requested review from a team as code owners October 16, 2024 06:49
Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

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

All the tests fail for me here, I assume it's something to do with playwright's setup as it seems to not be starting the dev env.

Either that, or your testing instructions are missing a few steps.

Speaking of the above, until everybody gets comfortable with this, please also include the steps to actually set up playwright (install, etc).

Basically what I am saying is be more comprehensive when writing your testing instructions.

Screenshot from 2024-10-16 13-23-15
Screenshot from 2024-10-16 13-23-28

@olgapod
Copy link
Contributor Author

olgapod commented Oct 16, 2024

@rdig I missed the step to start the dev environment (BE services) before running the tests, added it now

Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

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

Ran this with the dev environment up and running and while some initial tests work, most of them fail or time out due to your usage of a hard coded token address.

Token addresses are not static, so you cannot hard code them.

Also, please leave a comment on this PR with what I told you in our private chat, as to why you're not wiring up the dev environment to run automatically, but have to start it separately by hand.

Screenshot from 2024-10-17 17-53-43
Screenshot from 2024-10-17 17-53-45
Screenshot from 2024-10-17 17-54-16
Screenshot from 2024-10-17 17-55-50
Screenshot from 2024-10-17 17-56-06
Screenshot from 2024-10-17 17-57-31
Screenshot from 2024-10-17 17-59-41

package.json Outdated
@@ -38,7 +38,7 @@
"postinstall": "if [ -z \"$SKIP_HOOKS\" ]; then ./scripts/lambda-functions-dependencies.sh && scripts/generate-amplify-local-config.sh; fi",
"watch-amplify": "node scripts/watchAmplifyFiles",
"forward-time": "node scripts/forward-time",
"playwright:install": "npx playwright install --with-deps",
"playwright:install": "npx playwright install --with-deps",
"playwright:run": "playwright test",
Copy link
Member

Choose a reason for hiding this comment

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

can you please change this to something like "test" or "execute" or something, just having npm run playright:run is very redundant :)

Not a major gripe but a nitpick here

test.describe('Create Colony flow', () => {
let colonyUrl: string;
const colonyName = 'testcolonyname';
const validToken = '0xeF841fe1611ce41bFCf0265097EFaf50486F5111';
Copy link
Member

Choose a reason for hiding this comment

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

This won't work. Addresses are not the same between dev environment runs, or even between machines at times.

So this cannot be hardcoded.

That's why this test fails

Screenshot from 2024-10-17 17-57-31

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting problem to solve. Even if we can get away with manually creating a token in the DB for now, will the tests have to interact with the chain like create-data script does?

Copy link
Member

Choose a reason for hiding this comment

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

The proper solution here is to use one of the "verified" tokens we deploy via the create data script and fetch it's address, either from the db, or from the chain directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, I've used your advice and updated the PR

});
});

test('Should render Confirmation step as expected', async ({ page }) => {
Copy link
Member

Choose a reason for hiding this comment

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

This step fails again because of the token that doesn't exist

Screenshot from 2024-10-17 17-59-41

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated, removed hardcoding the token address

Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

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

Great to see a start on the create colony flow, very nice work @olgapod 🎉

Unfortunately I'm also seeing some tests fail:
image

image

test.describe('Create Colony flow', () => {
let colonyUrl: string;
const colonyName = 'testcolonyname';
const validToken = '0xeF841fe1611ce41bFCf0265097EFaf50486F5111';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting problem to solve. Even if we can get away with manually creating a token in the DB for now, will the tests have to interact with the chain like create-data script does?

@olgapod olgapod force-pushed the e2e/create-colony-flow branch 2 times, most recently from 1504d58 to 16d4a44 Compare October 18, 2024 13:42
jakubcolony
jakubcolony previously approved these changes Oct 18, 2024
Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

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

Getting a full pass ✅ now, great work Olha 💯

image

I looked through the test cases and could not see one where a correctly formatted token address is used but it cannot be found in the DB and on chain. Should that be covered as well?

@olgapod olgapod requested a review from rdig October 18, 2024 15:22
@olgapod
Copy link
Contributor Author

olgapod commented Oct 18, 2024

@jakubcolony I'll add that test case in the next PR. Good catch, thanks! Also, please feel free to suggest test cases going forward, it would be helpful as I'm still learning all the features of the app

iamsamgibbs
iamsamgibbs previously approved these changes Oct 21, 2024
Copy link
Contributor

@iamsamgibbs iamsamgibbs left a comment

Choose a reason for hiding this comment

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

Great work on this, all working nicely and all tests are passing.

Screenshot 2024-10-21 at 11 08 44 Screenshot 2024-10-21 at 11 15 23

As Jakub mentioned, it would be good to test for invalid but properly formatted addresses.

It might be worth checking src/components/common/Onboarding/wizardSteps/CreateColony/validation.ts for any other relevant validation checks. For example, there is a list of RESERVED_ROUTES and it shouldn't be possible to set your colony url to any of these reserved routes. I think we should get this merged and add these in a later PR though. :)

Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

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

This is getting closer. Sorry I keep finding changes and preventing you from merging this already :(

First of, on my machine, tests fail in headless mode, which might be a "me" issue. So we'll need some confirmations from other people

Screenshot from 2024-10-21 16-19-33
Screenshot from 2024-10-21 16-19-36

(I'm running this commit)

Screenshot from 2024-10-21 16-19-41

However, the UI run of the tests seem to be running fine

Screenshot from 2024-10-21 16-27-56

I've also left some comments on what other checks you need to add to make this PR complete.

Sorry again, for holding this back still.

await page.getByLabel(/token symbol/i).fill(tokenSymbol);
});

test('Token Logo file uploader should work correctly', async ({ page }) => {
Copy link
Member

Choose a reason for hiding this comment

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

Please also test going back and forth and ensure the token name, symbol and logo persist

Copy link
Member

Choose a reason for hiding this comment

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

Basically testing the bug you identified here: #3300

Copy link
Contributor Author

@olgapod olgapod Oct 21, 2024

Choose a reason for hiding this comment

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

added for the token name and symbol. for the logo I will add a test once the bug is fixed

);
});

test('Should create a colony and navigate to the Complete Setup step', async ({
Copy link
Member

Choose a reason for hiding this comment

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

At this stage the colony is not yet created, so this description is a bit misleading.

I would actually have this step wait until all transactions are complete and you get the "successfully created colony" welcome modal (although that might be harder)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added this step, although it's quite slow as the transactions and transition to the new colony page take some time

).toBeHidden();
});

test('Should accept existing token and display validation message', async ({
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a test where we also check invalid tokens. It should check:

  • a bad formatted address
  • a good formatted address, which is a user address
  • a good formatted address, which is a colony address
  • a good formatted address, but one that doesn't exist on the chain
  • address zero (it's a good formatted address, exists on the chain, but you shouldn't be allowed to add it as a native 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.

done

@olgapod
Copy link
Contributor Author

olgapod commented Oct 21, 2024

This is getting closer. Sorry I keep finding changes and preventing you from merging this already :(

First of, on my machine, tests fail in headless mode, which might be a "me" issue. So we'll need some confirmations from other people

Screenshot from 2024-10-21 16-19-33 Screenshot from 2024-10-21 16-19-36

(I'm running this commit)

Screenshot from 2024-10-21 16-19-41

However, the UI run of the tests seem to be running fine

Screenshot from 2024-10-21 16-27-56

I've also left some comments on what other checks you need to add to make this PR complete.

Sorry again, for holding this back still.

Interesting, Webkit tests are failing on your machine for some reason. To identify if it's your env specific problem or an issue with the tests please try on a clean Playwright example proj by running this command in your terminal npm init playwright mytestproject && cd mytestproject && npx playwright test. This will scaffold a test project (don't forget to remove it afterward) and run tests in headless mode. Let me know if webkit tests are also failing for you there.

@rdig
Copy link
Member

rdig commented Oct 21, 2024

Interesting, Webkit tests are failing on your machine for some reason. To identify if it's your env specific problem or an issue with the tests please try on a clean Playwright example proj by running this command in your terminal npm init playwright mytestproject && cd mytestproject && npx playwright test. This will scaffold a test project (don't forget to remove it afterward) and run tests in headless mode. Let me know if webkit tests are also failing for you there.

👍

Copy link
Contributor

@iamsamgibbs iamsamgibbs left a comment

Choose a reason for hiding this comment

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

This could just be a me issue, but some of the tests are failing for me after the rebase unfortunately!

Screenshot 2024-10-25 at 16 26 09

jakubcolony
jakubcolony previously approved these changes Oct 28, 2024
Copy link
Collaborator

@jakubcolony jakubcolony left a comment

Choose a reason for hiding this comment

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

image

@iamsamgibbs
Copy link
Contributor

Just noting this here as I've tried a few times after different commits and have been unable to get all tests to pass. Seems like it could be an issue just for me if they are passing for Jakub. There also isn't any consistency to which tests pass / fail, and I can get most failed tests to pass after retrying them.

Screenshot 2024-10-28 at 15 29 27

Would be helpful for other people to test and confirm if the tests pass for them or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest creating a helper function for getting an input field by label and also add the { force: true } option - without this option I believe the Continue button will not get enabled, but would love to hear your thoughts

Also, can we please create a constants object holding all the text strings that we are using for getting a text field/button etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestions! @mmioana

  1. I don't think creating such a helper would make the code significantly shorter or easier to read.

  2. Regarding the use of { force: true }, I'm not sure I fully understand the need for it. This option is used to bypass Playwright's actionability checks, like when an element is hidden or disabled. In our case, are we looking to click buttons regardless of their, for example, disabled state?

  3. Creating a constants object to hold all the text strings for selectors - sure we can do this. would be interesting to see what others think about this

@rdig
Copy link
Member

rdig commented Oct 29, 2024

@olgapod please set up a call w/ me, @iamsamgibbs (and however else is interested) so that we can debug this live, as I'm experiencing the same as Sam, but @jakubcolony 's seem to work.

It's either a OS thing, or a resource thing, but either way the tests seem flaky at the moment.

So let's jump on a call and debug this live, as I want to get this merged as soon as possible

@Nortsova
Copy link
Contributor

hey guys, these are errors that I get :)

image

@olgapod I am also interested in investigating this, please include me in a call as well 🙌

iamsamgibbs
iamsamgibbs previously approved these changes Oct 29, 2024
Copy link
Contributor

@iamsamgibbs iamsamgibbs left a comment

Choose a reason for hiding this comment

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

I've ran this 15 or so times now and had it fail only a couple of times. I think it is working consistently enough that we should get this merged and just keep fine tuning as we go as more tests are implemented.

Screenshot 2024-10-29 at 14 20 42

Copy link
Contributor

@rumzledz rumzledz left a comment

Choose a reason for hiding this comment

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

Hey @olgapod ! I had a go at this and tried my best to explain the issue I'm having with one of the tests. But if it consistently passes for everyone else including you, don't mind my comment and I'll just approve it 👌 😄

for (const value of values) {
await inputField.fill(value);

await expect(page.getByTestId('form-error')).toBeVisible();
Copy link
Contributor

@rumzledz rumzledz Oct 29, 2024

Choose a reason for hiding this comment

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

Hey @olgapod awesome job on this PR! I ran this locally and the test seems to consistently fail on this step, as in like 10 times in a row:

Screenshot 2024-10-30 at 02 37 45

Looking at the recorded timeline, it looked like it was entering the 21-length string (A.repeat(21)) into the field which is correct and expected but for whatever reason, the input gets cleared afterwards, which causes this test to fail.

reject invalid

I experimented a little bit and found that the problem went away after adding a 100ms timeout to the fill function:

// I really don't know why.... 🤷🏻‍♂️
await inputField.fill(value, { timeout: 100 });

olha pass 1

There are however also other instances where this test would just pass without this shenanigan 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

EDIT: And now it passes 8 out of 10 times. It might just be my machine or something! The new thing that's flaking out is this test:

Screenshot 2024-10-30 at 03 21 58

This might just work properly when run on CI. A good test to monitor but I have no objections on getting it merged!

Copy link
Contributor

Choose a reason for hiding this comment

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

EDIT:

@olgapod Both tests have passed 5 out of 5 times on my machine without any code changes whatsoever 🚀


for (const value of values) {
await inputField.fill(value);
await inputField.blur();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the test will be a more accurate real-world representation if you didn't blur the field here because our validation is triggered via onChange 👌

Copy link
Contributor

@iamsamgibbs iamsamgibbs left a comment

Choose a reason for hiding this comment

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

Tests seem to be failing more consistently for me this morning unfortunately!

Screenshot 2024-10-30 at 09 08 59 Screenshot 2024-10-30 at 09 23 06

@rumzledz
Copy link
Contributor

Tests seem to be failing more consistently for me this morning unfortunately!

Screenshot 2024-10-30 at 09 08 59 Screenshot 2024-10-30 at 09 23 06

Hey @olgapod it seems that CI is having issues with these as well 😕 I thought it was just my machine. I had some luck "fixing" these yesterday on my local, I outlined it on my comment yesterday. No promises it works on CI though, but I guess it's worth a shot? 🤞

@olgapod
Copy link
Contributor Author

olgapod commented Oct 30, 2024

Thanks all for your time to debug this. The most frustrating part is that I can't reproduce the failures on any of my three laptops (although all macOS based, but with very different specs). For now, my best idea is to close this PR and break down its changes into smaller ones - one for each step of the flow. I think this will help pinpoint the problem with flakiness

@olgapod olgapod closed this Oct 30, 2024
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.

8 participants