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

[Draft] 🎀 Add login on demand depending on user permission 🎀 #5176

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
09ae677
Added login on demand depending on user permission
michalina-graczyk Sep 23, 2024
d4d8baa
Mute problematic eslint rule
michalina-graczyk Sep 23, 2024
dea1a07
Test testWithPermission for admin
michalina-graczyk Sep 24, 2024
0d6e19e
Change test order
michalina-graczyk Sep 24, 2024
ae33a8c
Add changeset
michalina-graczyk Sep 25, 2024
bb6f440
Make test 131 run in serial mode
michalina-graczyk Sep 25, 2024
bbc56d3
Add login failed error logging
michalina-graczyk Sep 26, 2024
3aaa323
Fix error for login for the TC:137
michalina-graczyk Sep 27, 2024
b43f9da
Add in-memory lock mechanism for logInUserViaApi
michalina-graczyk Sep 30, 2024
449b5de
Guarantee minimum of 1000ms between requests
michalina-graczyk Sep 30, 2024
1d4ad99
Extend the time to 1500ms and add a log
michalina-graczyk Oct 1, 2024
fdd72dc
Add logs with @actions/core
michalina-graczyk Oct 1, 2024
c054b8a
Log attempts
andrzejewsky Oct 1, 2024
3c5d38e
Add PW debug logs
michalina-graczyk Oct 1, 2024
81fcdf1
Hide banner help on demand
andrzejewsky Oct 1, 2024
227f6b3
list reporter
andrzejewsky Oct 1, 2024
4d38330
list reporter
andrzejewsky Oct 1, 2024
886c7bd
Apply to other tests
andrzejewsky Oct 1, 2024
aa33f12
Apply to other tests
andrzejewsky Oct 1, 2024
f2d59d2
Apply to other tests
andrzejewsky Oct 1, 2024
7b7260c
Apply to other tests
andrzejewsky Oct 1, 2024
7681f14
Apply to other tests
andrzejewsky Oct 1, 2024
c7e00d7
Apply to other tests
andrzejewsky Oct 1, 2024
294f521
Apply to other tests
andrzejewsky Oct 1, 2024
692e7dd
Apply to other tests
andrzejewsky Oct 1, 2024
c89800f
Apply to other tests
andrzejewsky Oct 1, 2024
215dd07
Ci fixes
andrzejewsky Oct 2, 2024
252107d
Ci fixes
andrzejewsky Oct 2, 2024
73239b8
Ci fixes
andrzejewsky Oct 2, 2024
17b4bcb
Ci fixes
andrzejewsky Oct 2, 2024
46b2570
Ci fixes
andrzejewsky Oct 2, 2024
01288c7
Ci fixes
andrzejewsky Oct 2, 2024
4368ca5
Ci fixes
andrzejewsky Oct 2, 2024
c0a26c7
Ci fixes
andrzejewsky Oct 2, 2024
8f20df9
Ci fixes
andrzejewsky Oct 2, 2024
02b1071
Ci fixes
andrzejewsky Oct 2, 2024
f00c970
Ci fixes
andrzejewsky Oct 2, 2024
56b622d
Ci fixes
andrzejewsky Oct 2, 2024
2ca25da
Ci fixes
andrzejewsky Oct 2, 2024
d9f080e
Ci fixes
andrzejewsky Oct 2, 2024
db6a337
Ci fixes
andrzejewsky Oct 2, 2024
fe55289
Ci fixes
andrzejewsky Oct 2, 2024
0cbb42b
Ci fixes
andrzejewsky Oct 2, 2024
0126f8f
Ci fixes
andrzejewsky Oct 2, 2024
a40405a
Ci fixes
andrzejewsky Oct 2, 2024
542a178
Ci fixes
andrzejewsky Oct 2, 2024
4b6a6c0
Ci fixes
andrzejewsky Oct 2, 2024
77f845a
Ci fixes
andrzejewsky Oct 2, 2024
8512c64
Ci fixes
andrzejewsky Oct 2, 2024
096190f
Ci fixes
andrzejewsky Oct 2, 2024
0e60e93
Ci fixes
andrzejewsky Oct 2, 2024
b209ce7
Ci fixes
andrzejewsky Oct 2, 2024
cb31fca
Ci fixes
andrzejewsky Oct 2, 2024
26647d6
Ci fixes
andrzejewsky Oct 2, 2024
4295545
Ci fixes
andrzejewsky Oct 2, 2024
be30908
Ci fixes
andrzejewsky Oct 2, 2024
2e1dd38
Ci fixes
andrzejewsky Oct 2, 2024
4cd2d57
Ci fixes
andrzejewsky Oct 2, 2024
3f35d60
Ci fixes
andrzejewsky Oct 3, 2024
f81f552
Ci fixes
andrzejewsky Oct 3, 2024
92bcb91
Ci fixes
andrzejewsky Oct 3, 2024
6a21853
Ci fixes
andrzejewsky Oct 3, 2024
acc2ebf
Reporter
andrzejewsky Oct 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brown-bobcats-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Implemented on-demand authentication for Playwright tests to mitigate rate-limiting issues. Authenticates only the admin user during initial setup and uses a helper function to authenticate other roles as needed within tests.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off"
},
"ignorePatterns": ["node_modules/", "**/types/**/*", "type-policies.ts"]
"ignorePatterns": ["node_modules/", "**/types/**/*", "type-policies.ts", "playwright/auth.js"]
}
16 changes: 16 additions & 0 deletions .github/actions/run-pw-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ inputs:
description: "Project name form playwright config"
required: false
default: "e2e"
ACCOUNTS:
description: "Accounts hash"
required: true
E2E_ENCODE_PASS:
description: "Accounts hash"
required: true

runs:
using: "composite"
Expand All @@ -47,6 +53,16 @@ runs:
shell: bash
run: npm ci

- name: Restore accounts
shell: bash
env:
E2E_ENCODE_PASS: ${{ inputs.E2E_ENCODE_PASS }}
ACCOUNTS: ${{ inputs.ACCOUNTS }}
API_URL: ${{ inputs.API_URL }}
BASE_URL: ${{ inputs.BASE_URL }}
run: |
node playwright/auth.js restore $ACCOUNTS

- name: Install Playwright Browsers
shell: bash
run: npx playwright install --with-deps
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/pr-automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ jobs:

deploy-dashboard:
if: github.event.pull_request.head.repo.full_name == 'saleor/saleor-dashboard'
outputs:
ACCOUNTS: ${{ steps.accounts.outputs.ACCOUNTS }}
runs-on: ubuntu-22.04
needs: initialize-cloud
permissions:
Expand Down Expand Up @@ -150,6 +152,18 @@ jobs:
env_url: ${{ needs.initialize-cloud.outputs.BASE_URL }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env: ${{ needs.initialize-cloud.outputs.POOL_NAME }}
- name: Prepare accounts
id: accounts
env:
BASE_URL: ${{ needs.initialize-cloud.outputs.BASE_URL }}
API_URL: ${{ needs.initialize-cloud.outputs.API_URL }}
E2E_USER_NAME: ${{ secrets.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
E2E_ENCODE_PASS: ${{ secrets.E2E_ENCODE_PASS }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ secrets.E2E_PERMISSIONS_USERS_PASSWORD }}
run: |
ACCOUNTS=$(node playwright/auth.js login)
echo "ACCOUNTS=${ACCOUNTS}" >> "$GITHUB_OUTPUT"

run-tests:
if: ${{ contains(github.event.pull_request.labels.*.name, 'run pw-e2e') }}
Expand All @@ -159,6 +173,7 @@ jobs:
fail-fast: false
matrix:
shard: ${{ fromJson(needs.initialize-cloud.outputs.SHARD_MATRIX) }}

steps:
- uses: actions/checkout@v4

Expand All @@ -174,6 +189,8 @@ jobs:
MAILPITURL: ${{ secrets.MAILPITURL }}
PW_WORKERS: ${{ vars.PW_WORKERS }}
PW_RETRIES: ${{ vars.PW_RETRIES }}
ACCOUNTS: ${{ needs.deploy-dashboard.outputs.ACCOUNTS }}
E2E_ENCODE_PASS: ${{ secrets.E2E_ENCODE_PASS }}

merge-reports:
if: "!cancelled() && contains(github.event.pull_request.labels.*.name, 'run pw-e2e')"
Expand Down
109 changes: 109 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@actions/core": "^1.10.1",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.1",
"@editorjs/embed": "^2.5.3",
Expand Down Expand Up @@ -307,6 +308,7 @@
"qa:artifact-move-screenshots": "find cypress/reports/*/mochareports -type d -name \"*.js\" -exec mv {} cypress/reports/mochareports \\;",
"qa:artifact-move-videos": "find cypress/reports/*/mochareports/videos -type f -name \"*.js.mp4\" -exec mv {} cypress/reports/mochareports/videos \\;",
"qa:pw-e2e": "npx playwright test --grep @e2e",
"qa:pw-ci-setup": "npx playwright test --grep @setup",
"qa:pw-ui": "npx playwright test --ui"
},
"description": "![Saleor Dashboard](https://user-images.githubusercontent.com/44495184/185379472-2a204c0b-9b7a-4a3e-93c0-2cb85205ed5e.png)"
Expand Down
30 changes: 15 additions & 15 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ export default defineConfig({
workers: parseInt(env.WORKERS || DEFAULT_WORKERS),
reporter: process.env.CI
? [
["blob"],
["github"],
[
"playwright-testmo-reporter",
{
outputFile: "testmo/testmo.xml", // Optional: Output file path. Defaults to 'testmo.xml'.
embedBrowserType: true, // Optional: Embed browser type in the XML file. Defaults to false.
embedTestSteps: true, // Optional: Embed test steps in the XML file. Defaults to true.
testStepCategories: ["hook", "expect", "pw:api", "test.step"], // Optional: Test step categories to include in the XML file. Defaults to ["hook","expect","pw:api","test.step"]. Possible options are "hook", "expect", "pw:api", "test.step".
testTitleDepth: 1, // Optional: Test case title depth to report in the XML file. Defaults to 1. Increase this to 2 include suite name. Increase this even further to include the path.
attachmentBasePathCallback: () =>
process.env.URL_TO_RUN ? process.env.URL_TO_RUN : "",
},
],
]
["blob"],
["github"],
[
"playwright-testmo-reporter",
{
outputFile: "testmo/testmo.xml", // Optional: Output file path. Defaults to 'testmo.xml'.
embedBrowserType: true, // Optional: Embed browser type in the XML file. Defaults to false.
embedTestSteps: true, // Optional: Embed test steps in the XML file. Defaults to true.
testStepCategories: ["hook", "expect", "pw:api", "test.step"], // Optional: Test step categories to include in the XML file. Defaults to ["hook","expect","pw:api","test.step"]. Possible options are "hook", "expect", "pw:api", "test.step".
testTitleDepth: 1, // Optional: Test case title depth to report in the XML file. Defaults to 1. Increase this to 2 include suite name. Increase this even further to include the path.
attachmentBasePathCallback: () =>
process.env.URL_TO_RUN ? process.env.URL_TO_RUN : "",
},
],
]
: [["html"], ["list"]],
expect: { timeout: 10 * 1000 },
maxFailures: 10,
Expand Down
39 changes: 26 additions & 13 deletions playwright/api/basics.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as core from "@actions/core";
import { APIRequestContext } from "@playwright/test";

interface User {
Expand Down Expand Up @@ -34,22 +35,34 @@ export class BasicApiService {

async logInUserViaApi(user: User): Promise<ApiResponse<TokenCreateResponse>> {
const query = `mutation TokenAuth{
tokenCreate(email: "${user.email}", password: "${user.password}") {
token
refreshToken
errors: errors {
code
message
}
user {
id
}
}
}`;
tokenCreate(email: "${user.email}", password: "${user.password}") {
token
refreshToken
errors: errors {
code
message
}
user {
id
}
}
}`;

core.info(`Executing login request at: ${new Date().toISOString()}`);

const loginResponse = await this.request.post(process.env.API_URL || "", {
data: { query },
});
const loginResponseJson = await loginResponse.json();

const loginResponseJson: { data: TokenCreateResponse } = await loginResponse.json();

if (loginResponseJson.data.tokenCreate.errors?.length > 0) {
const errorMessages = loginResponseJson.data.tokenCreate.errors
.map(e => e.message)
.join(", ");

throw new Error(`Login failed: ${errorMessages}`);
}

return loginResponseJson as ApiResponse<TokenCreateResponse>;
}
Expand Down
Loading
Loading