Advertisement
djbob2000

Untitled

May 2nd, 2025 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { type Page } from "@playwright/test";
  2. import { UiTester } from "@fernir2/saas-kit/test/fd-test-ui-tester";
  3. import "dotenv/config";
  4.  
  5. const baseUrl = process.env["BASE_URL"] ?? "https://saas-kit-staging.fernir.biz";
  6. const cfToken = process.env["CF_TOKEN"] ?? "";
  7.  
  8. interface IUiTester {
  9.     page: Page;
  10. }
  11.  
  12. export class LoginPo {
  13.     readonly #page: Page;
  14.  
  15.     constructor(pageOrTester: Page | (UiTester & IUiTester)) {
  16.         this.#page = pageOrTester instanceof UiTester ? pageOrTester.page : pageOrTester;
  17.     }
  18.  
  19.     get page(): Page {
  20.         return this.#page;
  21.     }
  22.  
  23.     async login() {
  24.         if (!cfToken) {
  25.             throw new Error("CF_TOKEN is not set! Please check your .env file and how you run the test");
  26.         }
  27.  
  28.         await this.page.context().addCookies([
  29.             {
  30.                 name: "CF_Authorization",
  31.                 value: cfToken,
  32.                 domain: "saas-kit-staging.fernir.biz",
  33.                 path: "/",
  34.                 httpOnly: true,
  35.                 secure: true,
  36.                 sameSite: "Lax",
  37.             },
  38.         ]);
  39.  
  40.         await this.page.goto(baseUrl);
  41.         await this.page.waitForURL((url) => url.pathname.includes("sign-in"));
  42.         await this.page.click("#loginButton");
  43.         await this.page.waitForURL("**/view?resource=Contact");
  44.     }
  45.  
  46.     async logout() {
  47.         await this.page.click("#userDropdownMenu");
  48.         await this.page.click("#signOutButton");
  49.         await this.page.waitForURL(`${baseUrl}/sign-in`);
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement