-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#317] 로그인/회원가입 e2e 테스트
- Loading branch information
Showing
12 changed files
with
241 additions
and
32 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,5 @@ dist-ssr | |
/playwright/.cache/ | ||
|
||
.eslintcache | ||
.env | ||
.env | ||
auth.json |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { chromium, FullConfig } from "@playwright/test"; | ||
import { LoginPage } from "@tests/e2eTests/models/LoginPage.ts"; | ||
|
||
async function globalSetup(config: FullConfig) { | ||
const { storageState } = config.projects[1].use; | ||
const browser = await chromium.launch(); | ||
const page = await browser.newPage(); | ||
|
||
const loginPage = new LoginPage(page); | ||
await loginPage.navigate(); | ||
console.log("로그인 시도"); | ||
await loginPage.login("[email protected]", "asdf1234!"); | ||
const accessToken = await loginPage.getAccessToken(); | ||
const refreshToken = await loginPage.getRefreshToken(); | ||
// const fcmToken = await loginPage.getFcmToken(); | ||
console.log("accessToken", accessToken); | ||
console.log("refreshToken", refreshToken); | ||
// console.log("fcmToken", fcmToken); | ||
await page.context().storageState({ path: storageState as string }); | ||
await browser.close(); | ||
} | ||
|
||
export default globalSetup; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Page } from "@playwright/test"; | ||
|
||
export class LoginPage { | ||
page: Page; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
async navigate(): Promise<void> { | ||
await this.page.goto("http://localhost:5173/signin"); | ||
} | ||
|
||
async login(email: string, password: string): Promise<void> { | ||
const navigationPromise = this.page.waitForNavigation(); | ||
await this.page.fill('input[name="email"]', email); | ||
await this.page.fill('input[name="password"]', password); | ||
await this.page.click('button:has-text("로그인")'); | ||
|
||
await navigationPromise; | ||
} | ||
|
||
async getAccessToken(): Promise<string | null> { | ||
await this.page.waitForLoadState("networkidle"); | ||
return this.page.evaluate(() => { | ||
return localStorage.getItem("accessToken"); | ||
}); | ||
} | ||
async getRefreshToken(): Promise<string | null> { | ||
await this.page.waitForLoadState("networkidle"); | ||
return this.page.evaluate(() => { | ||
return localStorage.getItem("refreshToken"); | ||
}); | ||
} | ||
// async getFcmToken(): Promise<string | null> { | ||
// await this.page.waitForLoadState("networkidle"); | ||
// return this.page.evaluate(() => { | ||
// return localStorage.getItem("fcmToken"); | ||
// }); | ||
// } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Page } from "@playwright/test"; | ||
|
||
export class Signup { | ||
page: Page; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
async navigate(): Promise<void> { | ||
await this.page.goto("http://localhost:5173/signup"); | ||
} | ||
|
||
async fillSignupForm( | ||
email: string, | ||
password: string, | ||
checkPassword: string, | ||
name: string, | ||
phone: string, | ||
): Promise<void> { | ||
await this.page.fill('input[name="email"]', email); | ||
await this.page.fill('input[name="password"]', password); | ||
await this.page.fill('input[name="checkPassword"]', checkPassword); | ||
await this.page.fill('input[name="name"]', name); | ||
await this.page.fill('input[name="phone"]', phone); | ||
} | ||
|
||
async fillVerificationCode(code: string): Promise<void> { | ||
await this.page.fill('input[name="code"]', code); | ||
} | ||
|
||
async clickVerificationCode(): Promise<void> { | ||
await this.page.click('button:has-text("인증 확인")'); | ||
} | ||
|
||
async submitSignup(): Promise<void> { | ||
const navigationPromise = this.page.waitForNavigation(); | ||
await this.page.click('button:has-text("가입하기")'); | ||
await navigationPromise; | ||
} | ||
|
||
async clickAllAgreeCheckbox(): Promise<void> { | ||
const checkboxLocator = this.page | ||
.locator("label") | ||
.filter({ hasText: "전체동의" }) | ||
.locator("span") | ||
.first(); | ||
|
||
await checkboxLocator.click(); | ||
} | ||
|
||
async getVerifyEmail(): Promise<string | null> { | ||
await this.page.click('button:has-text("인증 요청")'); | ||
|
||
// await this.page.waitForLoadState("networkidle"); | ||
|
||
const response = await this.page.waitForResponse( | ||
(response) => | ||
response.url() === "https://3.34.147.187.nip.io/v1/members/email" && | ||
response.status() === 200, | ||
); | ||
|
||
const responseData = await response.json(); | ||
console.log(responseData); | ||
return responseData.data; | ||
} | ||
// async getFcmToken(): Promise<string | null> { | ||
// await this.page.waitForLoadState("networkidle"); | ||
// return this.page.evaluate(() => { | ||
// return localStorage.getItem("fcmToken"); | ||
// }); | ||
// } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test.use({ storageState: { cookies: [], origins: [] } }); | ||
|
||
test("로그인 성공", async ({ page }) => { | ||
await page.goto("http://localhost:5173/signin"); | ||
|
||
await page.fill('input[name="email"]', "[email protected]"); | ||
await page.fill('input[name="password"]', "asdf1234!"); | ||
|
||
await page.click('button:has-text("로그인")'); | ||
|
||
await page.waitForNavigation(); | ||
|
||
const localStorageValue = await page.evaluate(() => { | ||
return localStorage.getItem("accessToken"); | ||
}); | ||
|
||
expect(typeof localStorageValue).toBe("string"); | ||
|
||
expect(page.url()).toBe("http://localhost:5173/"); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { test } from "@playwright/test"; | ||
import { Signup } from "@tests/e2eTests/models/SignupPage"; | ||
|
||
test.use({ storageState: { cookies: [], origins: [] } }); | ||
|
||
test("회원가입 성공", async ({ page }) => { | ||
const signup = new Signup(page); | ||
const userEmail = `test${Math.floor(Math.random() * 10000)}@example.com`; | ||
const userPassword = "asdf1234!"; | ||
const userName = "집주인"; | ||
const userPhone = "010-1234-5678"; | ||
|
||
await signup.navigate(); | ||
|
||
await signup.fillSignupForm( | ||
userEmail, | ||
userPassword, | ||
userPassword, | ||
userName, | ||
userPhone, | ||
); | ||
|
||
const verificationCode = await signup.getVerifyEmail(); | ||
if (!verificationCode) { | ||
throw new Error("인증 이메일을 받지 못했습니다."); | ||
} | ||
|
||
await signup.fillVerificationCode(verificationCode); | ||
|
||
await signup.clickVerificationCode(); | ||
|
||
await signup.clickAllAgreeCheckbox(); | ||
|
||
await signup.submitSignup(); | ||
}); |
8 changes: 4 additions & 4 deletions
8
...nectYanoljaPage/VerificationPage.spec.tsx → tests/unitTestsSrc/VerificationPage.spec.tsx
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
7 changes: 3 additions & 4 deletions
7
...c/hooks/api/useEmailVerification.spec.tsx → ...nitTestsSrc/useEmailVerification.spec.tsx
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
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
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