Skip to content

Commit

Permalink
adding condition to not create json file if it does exist
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowee committed Mar 21, 2024
1 parent 9f7370d commit 6c1e098
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-colts-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": minor
---

Optimizing playwright setup and playwright.config.ts files
80 changes: 50 additions & 30 deletions .github/actions/run-pw-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,57 @@ inputs:
description: "mailpit uri"
required: true

runs:
using: "composite"
steps:
- uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
on:
push:
branches:
- main
pull_request:
branches:
- main

- name: Install dependencies
shell: bash
run: npm ci
jobs:
setup_environment:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4]
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps

- name: Install Playwright Browsers
shell: bash
run: npx playwright install --with-deps
run_tests:
needs: setup_environment
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run tests
shell: bash
env:
API_URI: ${{ inputs.API_URL }}
BASE_URL: ${{ inputs.BASE_URL }}
E2E_USER_NAME: ${{ inputs.E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ inputs.E2E_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ inputs.E2E_PERMISSIONS_USERS_PASSWORD }}
SHARD_NUMBER: ${{ inputs.SHARD }}
MAILPITURL: ${{ inputs.MAILPITURL }}
run: npm run qa:pw-e2e -- --shard "$SHARD_NUMBER"
- name: Run tests
env:
API_URI: ${{ API_URL }}
BASE_URL: ${{ BASE_URL }}
E2E_USER_NAME: ${{ E2E_USER_NAME }}
E2E_USER_PASSWORD: ${{ E2E_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ E2E_PERMISSIONS_USERS_PASSWORD }}
SHARD_NUMBER: ${{ SHARD }}
MAILPITURL: ${{ MAILPITURL }}
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ strategy.matrix.shardIndex }}

- name: Upload blob report to GitHub Actions Artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: all-blob-reports
path: blob-report
retention-days: 1
- name: Upload blob report to GitHub Actions Artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: blob-report-${{ matrix.shardIndex }}
path: blob-report
retention-days: 1
26 changes: 10 additions & 16 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,29 @@ export default defineConfig({
testDir: "playwright/tests",
fullyParallel: true,
forbidOnly: !!process.env.CI,
// TODO hardcoded values should be extracted to ENVs
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 2 : 2,
workers: process.env.CI ? 4 : 2,
reporter: process.env.CI ? "blob" : "html",
timeout: 60000 ,
expect: { timeout: 10000 },
// webServer: {
// command: "npm run dev",
// url: "http://localhost:9000/",
// reuseExistingServer: !process.env.CI,
// },
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
maxFailures: 5,
timeout: process.env.CI ? 45000 : 60000,
use: {
baseURL: process.env.BASE_URL,
trace: "on-first-retry",
trace: process.env.CI ? "on-first-retry" : "off",
screenshot: "only-on-failure",
testIdAttribute: "data-test-id",
video: process.env.CI ? "retain-on-failure" : "off",
headless: true,
},

/* Configure projects for major browsers */
projects: [
{ name: "setup", testMatch: /.*\.setup\.ts/ },

{
// if new project added make sure to add dependency as below
name: "setup",
testMatch: /.*\.setup\.ts/
},
{
dependencies: ["setup"],
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
],
});

10 changes: 8 additions & 2 deletions playwright/tests/auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,26 @@ const authenticateAndSaveState = async (request: APIRequestContext, email: strin
});
fs.writeFileSync(filePath, JSON.stringify(loginJsonInfo, null, 2));
};
const authSetup = async ( request: APIRequestContext,email: string, password: string, fileName: string) => {

const authSetup = async (request: APIRequestContext, email: string, password: string, fileName: string) => {
const tempDir = path.join(__dirname, '../.auth');
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir, { recursive: true });
}
const tempFilePath = path.join(tempDir, fileName);
await authenticateAndSaveState(request, email, password, tempFilePath);

if (!fs.existsSync(tempFilePath)) {
await authenticateAndSaveState(request, email, password, tempFilePath);
}
};

setup("Authenticate as admin via API", async ({ request }) => {
await authSetup(request, process.env.E2E_USER_NAME!, process.env.E2E_USER_PASSWORD!, 'admin.json');
});

const user: UserPermissionType = USER_PERMISSION;
const password: string = process.env.E2E_PERMISSIONS_USERS_PASSWORD!;

for (const permission of permissions) {
setup(`Authenticate as ${permission} user via API`, async ({ request }) => {
await authSetup(request, user[permission], password, `${permission}.json`);
Expand Down

0 comments on commit 6c1e098

Please sign in to comment.