feat: test sign out and sign in
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
80d6e80112
commit
28cfa742f2
2 changed files with 79 additions and 3 deletions
|
@ -19,8 +19,8 @@ test("Go to explore page", async ({ page }) => {
|
||||||
await expect(page).toHaveTitle("Explore - Forgejo: Beyond coding. We forge.");
|
await expect(page).toHaveTitle("Explore - Forgejo: Beyond coding. We forge.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Go to register page", async ({ page }) => {
|
test("Test registration error: password mismatch", async ({ page }) => {
|
||||||
const user = new User("gotoregisterpage");
|
const user = new User("pwmismatch");
|
||||||
|
|
||||||
console.log(`running with user ${user.username}`);
|
console.log(`running with user ${user.username}`);
|
||||||
|
|
||||||
|
@ -42,6 +42,14 @@ test("Go to register page", async ({ page }) => {
|
||||||
expect(page.locator(".negative > p:nth-child(1)")).toContainText(
|
expect(page.locator(".negative > p:nth-child(1)")).toContainText(
|
||||||
"passwords do not match"
|
"passwords do not match"
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Test successful registration", async ({ page }) => {
|
||||||
|
const user = new User("register");
|
||||||
|
|
||||||
|
console.log(`running with user ${user.username}`);
|
||||||
|
|
||||||
|
await page.goto(config.INSTANCE_URL.toString());
|
||||||
|
|
||||||
// successful registration
|
// successful registration
|
||||||
|
|
||||||
|
@ -56,3 +64,36 @@ test("Go to register page", async ({ page }) => {
|
||||||
"Account was successfully created. Welcome!"
|
"Account was successfully created. Welcome!"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Test signout", async ({ page }) => {
|
||||||
|
const user = new User("signout");
|
||||||
|
|
||||||
|
// successful registration
|
||||||
|
await user.register(page);
|
||||||
|
await user.logout(page);
|
||||||
|
await expect(page).toHaveTitle("Forgejo: Beyond coding. We forge.");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Test login", async ({ page }) => {
|
||||||
|
const user = new User("login");
|
||||||
|
|
||||||
|
// successful registration
|
||||||
|
await user.register(page);
|
||||||
|
await user.logout(page);
|
||||||
|
await user.login(page);
|
||||||
|
await user.logout(page);
|
||||||
|
|
||||||
|
// sign in with email
|
||||||
|
await page.goto(config.INSTANCE_URL.toString());
|
||||||
|
await page.getByRole("link", { name: "Sign In" }).click();
|
||||||
|
await page.waitForURL("**/user/login**");
|
||||||
|
await page.getByLabel("Username").clear();
|
||||||
|
await page.getByLabel("Password", { exact: true }).clear();
|
||||||
|
await page.getByLabel("Username").fill(user.email);
|
||||||
|
await page.getByLabel("Password", { exact: true }).fill(user.password);
|
||||||
|
await page.getByRole("button", { name: "Sign In" }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveTitle(
|
||||||
|
`${user.username} - Dashboard - Forgejo: Beyond coding. We forge.`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
|
@ -10,11 +10,46 @@ export default class User {
|
||||||
|
|
||||||
constructor(name: string) {
|
constructor(name: string) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.username = `playwright_${getRandomString(6)}_${name}`;
|
this.username = `plw_${getRandomString(6)}_${name}`;
|
||||||
|
if (this.username.length > 40) {
|
||||||
|
throw Error(`username must be less than 40 char. Reduse length of ${name}`)
|
||||||
|
}
|
||||||
this.email = `${this.username}@playwright.local`;
|
this.email = `${this.username}@playwright.local`;
|
||||||
this.password = "628acdbd8b7b3f";
|
this.password = "628acdbd8b7b3f";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async logout(page: Page) {
|
||||||
|
await page.goto(config.INSTANCE_URL.toString());
|
||||||
|
// going to explore page to wait for sign out to be successful. Change in
|
||||||
|
// URL must indicate successful sign out.
|
||||||
|
await page.getByRole("link", { name: "Explore" }).click();
|
||||||
|
await page.waitForURL("**/explore/repos");
|
||||||
|
|
||||||
|
let dropdown = page.locator("div.dropdown:nth-child(4)");
|
||||||
|
await dropdown.click();
|
||||||
|
// await dropdown.getByRole("link", { name: "Sign Out" }).click();
|
||||||
|
await dropdown.getByText("Sign Out").click();
|
||||||
|
await page.waitForURL(config.INSTANCE_URL.toString());
|
||||||
|
|
||||||
|
await expect(page).toHaveTitle("Forgejo: Beyond coding. We forge.");
|
||||||
|
}
|
||||||
|
|
||||||
|
async login(page: Page) {
|
||||||
|
await page.goto(config.INSTANCE_URL.toString());
|
||||||
|
await page.getByRole("link", { name: "Sign In" }).click();
|
||||||
|
await page.waitForURL("**/user/login**");
|
||||||
|
await page.getByLabel("Username").clear();
|
||||||
|
await page.getByLabel("Password", { exact: true }).clear();
|
||||||
|
await page.getByLabel("Username").fill(this.username);
|
||||||
|
await page.getByLabel("Password", { exact: true }).fill(this.password);
|
||||||
|
await page.getByRole("button", { name: "Sign In" }).click();
|
||||||
|
|
||||||
|
await expect(page).toHaveTitle(
|
||||||
|
`${this.username} - Dashboard - Forgejo: Beyond coding. We forge.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async register(page: Page) {
|
async register(page: Page) {
|
||||||
await page.goto(config.INSTANCE_URL.toString());
|
await page.goto(config.INSTANCE_URL.toString());
|
||||||
await page.getByRole("link", { name: "Register" }).click();
|
await page.getByRole("link", { name: "Register" }).click();
|
||||||
|
|
Loading…
Reference in a new issue