Last active
March 10, 2024 04:58
-
-
Save mandemeskel/50de1611d561166ab01290d6e2987d8b to your computer and use it in GitHub Desktop.
Login Testing API for Retool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Page, expect } from "@playwright/test" | |
export class LoginTapi { | |
constructor(public page: Page) { | |
this.page = page | |
} | |
async login() { | |
await this.goToPage() | |
await this.fillLoginEmail() | |
await this.fillLoginPassword() | |
await this.clickSignInButton() | |
await this.expectUserToBeLogedIn() | |
} | |
async goToPage() { | |
await this.page.goto(this.getEnvVarOrThrow('RETOOL_APP_URL') | |
} | |
async fillLoginEmail() { | |
const email = this.page.getByPlaceholder('name@company.com') | |
await email.fill(this.getEnvVarOrThrow('RETOOL_EMAIL')) | |
} | |
async fillLoginPassword() { | |
const pass = this.page.getByPlaceholder('*******************') | |
await pass.fill(this.getEnvVarOrThrow('RETOOL_PASSWORD')) | |
} | |
async clickSignInButton() { | |
await this.page.getByRole('button').getByText('Sign in', { exact: true }).click() | |
} | |
async expectUserToBeLogedIn() { | |
return await expect(this.page).toHaveTitle(/Omni: Admin Control Panel/, {timeout: 10000}) | |
} | |
getEnvVarOrThrow(env_var: string) { | |
const val = process.env[env_var] | |
if (val === undefined) | |
throw `${env_var} is undefined, set it in .env.test` | |
return val | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment