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

feat(playwright): add playwright testing #33

Merged
merged 55 commits into from
Jun 7, 2023
Merged

feat(playwright): add playwright testing #33

merged 55 commits into from
Jun 7, 2023

Conversation

benjaminpaige
Copy link
Collaborator

@benjaminpaige benjaminpaige commented May 23, 2023

Purpose

This change adds end to end testing via playwright to the ui service, top level run e2e script, and gh workflow step. This is one part of two changes.

Linked Issues to Close

https://qmacbis.atlassian.net/browse/OY2-23755
https://qmacbis.atlassian.net/browse/OY2-24074

Approach

We installed playwright in the ui and api services, added playwright config files in the roots of those directories, and added example tests. In the ui service these tests use a headless browser to run through actions and expectations in the local instance of the front end. In the api service these tests make calls and expectations to actual endpoints.

An e2e script was added to the run command. A step was added to the deploy workflow to set up the aws creds, install playwright browsers and run the e2e tests and upload the artifacts when complete.

You run e2e tests against a local running instance of the application by using the run ui --stage [stage] command to deploy and init an instance of the application. A second terminal can be used to run the run e2e command which will run the playwright tests against the currently running instance of the ui on localhost:5000.

Assorted Notes/Considerations/Learning

A pattern of selectors is used which define selectors in a separate dir and imports them for reusability.

The e2e tests for the UI service are located in src/services/ui/e2e and defined in .spec files. examples can be found to guide how to structure tests.

When defining the selectors for elements make sure to define your selectors in the e2e/selectors directory. Defining selectors using react component names and properties is preferred to maintain consistent scalable testing. Other patterns can be used such as xpath, element type/name, and id/data-id/test-id. But should only be used when necessary.

@benjaminpaige benjaminpaige marked this pull request as ready for review June 5, 2023 03:09
Comment on lines 3 to 12
export const addIssueForm = {
addButton: (page: Page) => page.locator("_react=Button[buttonText = \"Add\"]"),
submitButton: (page: Page) =>
page.locator("_react=Button[buttonText = \"Submit\"]"),
titleInput: (page: Page) => page.getByLabel("Title"),
descriptionInput: (page: Page) => page.getByLabel("Description"),
prioritySelect: (page: Page) =>
page.getByRole("combobox", { name: "Priority" }),
typeSelect: (page: Page) => page.getByRole("combobox", { name: "Type" }),
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i dont love this way of doing the selectors. thinking maybe a class might work better. thoughts are welcome

Copy link
Collaborator

@jdinh8124 jdinh8124 left a comment

Choose a reason for hiding this comment

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

This looks good from what I can tell, great work! Excited to see it in action

Comment on lines 34 to 42
// {
// name: "firefox",
// use: { ...devices["Desktop Firefox"] },
// },

// {
// name: "webkit",
// use: { ...devices["Desktop Safari"] },
// },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thoughts on uncommenting these configs for other browsers? Unless we want all devs to use chronium based browsers only

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah thats a good idea. was there mainly for an example, but cant hurt to have them run as well 👍

@codeclimate
Copy link

codeclimate bot commented Jun 7, 2023

Code Climate has analyzed commit dcd6f77 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

@benjaminpaige benjaminpaige merged commit 4e9ced5 into master Jun 7, 2023
@benjaminpaige benjaminpaige deleted the play branch June 7, 2023 16:03
@github-actions
Copy link
Contributor

github-actions bot commented Jun 7, 2023

🎉 This PR is included in version 1.3.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants