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 bb1addf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 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
2 changes: 1 addition & 1 deletion .github/actions/run-pw-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ runs:
E2E_USER_PASSWORD: ${{ inputs.E2E_USER_PASSWORD }}
E2E_PERMISSIONS_USERS_PASSWORD: ${{ inputs.E2E_PERMISSIONS_USERS_PASSWORD }}
SHARD_NUMBER: ${{ inputs.SHARD }}
MAILPITURL: ${{ inputs.MAILPITURL }}
MAILPITURL: ${{ inputs.MAILPITURL }}
run: npm run qa:pw-e2e -- --shard "$SHARD_NUMBER"

- name: Upload blob report to GitHub Actions Artifacts
Expand Down
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 bb1addf

Please sign in to comment.