diff --git a/.changeset/sixty-colts-cough.md b/.changeset/sixty-colts-cough.md new file mode 100644 index 00000000000..79449cb3ec6 --- /dev/null +++ b/.changeset/sixty-colts-cough.md @@ -0,0 +1,5 @@ +--- +"saleor-dashboard": minor +--- + +Optimizing playwright setup and playwright.config.ts files diff --git a/.github/actions/run-pw-tests/action.yml b/.github/actions/run-pw-tests/action.yml index 9c868592f9d..3e32f320d24 100644 --- a/.github/actions/run-pw-tests/action.yml +++ b/.github/actions/run-pw-tests/action.yml @@ -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 diff --git a/playwright.config.ts b/playwright.config.ts index c23c0b44d53..e04330a5877 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -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"] }, }, ], }); + diff --git a/playwright/tests/auth.setup.ts b/playwright/tests/auth.setup.ts index d5c6f56d936..9c0ff4abd18 100644 --- a/playwright/tests/auth.setup.ts +++ b/playwright/tests/auth.setup.ts @@ -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`);