Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { type Page } from "@playwright/test";
- import { UiTester } from "@fernir2/saas-kit/test/fd-test-ui-tester";
- import "dotenv/config";
- const baseUrl = process.env["BASE_URL"] ?? "https://saas-kit-staging.fernir.biz";
- const cfToken = process.env["CF_TOKEN"] ?? "";
- interface IUiTester {
- page: Page;
- }
- export class LoginPo {
- readonly #page: Page;
- constructor(pageOrTester: Page | (UiTester & IUiTester)) {
- this.#page = pageOrTester instanceof UiTester ? pageOrTester.page : pageOrTester;
- }
- get page(): Page {
- return this.#page;
- }
- async login() {
- if (!cfToken) {
- throw new Error("CF_TOKEN is not set! Please check your .env file and how you run the test");
- }
- await this.page.context().addCookies([
- {
- name: "CF_Authorization",
- value: cfToken,
- domain: "saas-kit-staging.fernir.biz",
- path: "/",
- httpOnly: true,
- secure: true,
- sameSite: "Lax",
- },
- ]);
- await this.page.goto(baseUrl);
- await this.page.waitForURL((url) => url.pathname.includes("sign-in"));
- await this.page.click("#loginButton");
- await this.page.waitForURL("**/view?resource=Contact");
- }
- async logout() {
- await this.page.click("#userDropdownMenu");
- await this.page.click("#signOutButton");
- await this.page.waitForURL(`${baseUrl}/sign-in`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement