Skip to content

Commit

Permalink
mypage_login.fixture で毎回会員登録するよう修正
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Jan 17, 2025
1 parent 975c624 commit 07927d8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
15 changes: 13 additions & 2 deletions e2e-tests/fixtures/mypage_login.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import { test as base, expect } from "@playwright/test";
import { MypageLoginPage } from "../pages/mypage/login.page";
import { EntryPage } from "../pages/entry/entry.page";
import { Mode, ContextType } from '../utils/ZapClient';
import { ECCUBE_DEFAULT_USER, ECCUBE_DEFAULT_PASS } from "../config/default.config";
import PlaywrightConfig from '../../playwright.config';
import { FakerUtils } from "../utils/FakerUtils";

type MypageLoginFixtures = {
mypageLoginPage: MypageLoginPage;
};

export const test = base.extend<MypageLoginFixtures>({
mypageLoginPage: async ({ page }, use) => {
const loginPage = new MypageLoginPage(page);
const email = FakerUtils.createEmail();
const password = FakerUtils.createPassword();
const loginPage = new MypageLoginPage(page, email, password);
if (PlaywrightConfig.use?.proxy === undefined) {
const entryPage = new EntryPage(page, email, password);
await entryPage.goto();
await entryPage.agree();
await entryPage.fill();
await entryPage.confirm();
await entryPage.register();
await loginPage.goto();
await loginPage.login(ECCUBE_DEFAULT_USER, ECCUBE_DEFAULT_PASS);
await loginPage.logout();
await loginPage.login();
} else {
const zapClient = loginPage.getZapClient();
await zapClient.setMode(Mode.Protect);
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/pages/entry/entry.page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Locator, Page } from '@playwright/test';
import { PersonalInputPage } from '../personal_input.page';
import { faker } from '@faker-js/faker/locale/ja';
import { FakerUtils } from '../../utils/FakerUtils';

export class EntryPage {
readonly page: Page;
Expand All @@ -14,7 +14,7 @@ export class EntryPage {

constructor(page: Page, email?: string, password?: string, url?: string) {
this.page = page;
this.password = password ?? faker.string.uuid();
this.password = password ?? FakerUtils.createPassword();
this.url = url ?? '/entry/kiyaku.php';
this.registerButton = page.locator('[alt=会員登録をする]');
this.confirmButton = page.locator('[alt=確認ページへ]');
Expand Down
12 changes: 8 additions & 4 deletions e2e-tests/pages/mypage/login.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import { ZapClient } from '../../utils/ZapClient';
export class MypageLoginPage {
readonly page: Page;
readonly url: string;
readonly email: string;
readonly password: string;

readonly loginEmail: Locator;
readonly loginPass: Locator;
readonly loginButton: Locator;
readonly logoutButton: Locator;
zapClient: ZapClient;

constructor(page: Page) {
constructor(page: Page, email: string, password: string) {
this.page = page;
this.url = '/mypage/login.php';
this.email = email;
this.password = password;

this.loginEmail = page.getByRole('textbox', { name: 'メールアドレスを入力して下さい' });
this.loginPass = page.getByRole('textbox', { name: 'パスワードを入力して下さい' });
Expand All @@ -26,9 +30,9 @@ export class MypageLoginPage {
await this.page.goto(this.url);
}

async login(email: string, password: string) {
await this.loginEmail.fill(email);
await this.loginPass.fill(password);
async login() {
await this.loginEmail.fill(this.email);
await this.loginPass.fill(this.password);
await this.loginButton.click();
}

Expand Down
3 changes: 1 addition & 2 deletions e2e-tests/test/front_guest/entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { test, expect, request, APIRequestContext } from '@playwright/test';

import { EntryPage } from '../../pages/entry/entry.page';
import PlaywrightConfig from '../../../playwright.config';
import { faker } from '@faker-js/faker/locale/ja';
import { FakerUtils } from '../../utils/FakerUtils';

const url = '/entry/kiyaku.php';
Expand All @@ -24,7 +23,7 @@ test.describe.serial('会員登録のテストをします', () => {

test('会員登録のテストをします', async ({ page }) => {
await page.goto(url);
const password = faker.string.uuid();
const password = FakerUtils.createPassword();
const email = FakerUtils.createEmail();
const entryPage = new EntryPage(page, email, password, url);

Expand Down
12 changes: 6 additions & 6 deletions e2e-tests/test/front_login/contact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test.describe.serial('お問い合わせページのテストをします', () =

test.describe('テストを実行します[GET] @attack', () => {
let scanId: number;
test('アクティブスキャンを実行します', async () => {
test('アクティブスキャンを実行します', async ({ page }) => {
const contactPage = new ContactPage(page);
const zapClient = contactPage.getZapClient();
scanId = await zapClient.activeScanAsUser(url, 2, 110, false, null, 'GET');
Expand All @@ -40,8 +40,8 @@ test.describe.serial('お問い合わせページのテストをします', () =
await page.goto(url);
await expect(page.locator('#header')).toContainText('ようこそ');
inputNames.forEach(async (name) => expect(page.locator(`input[name=${ name }]`)).not.toBeEmpty());
await expect(page.locator('input[name=email]')).toHaveValue('[email protected]');
await expect(page.locator('input[name=email02]')).toHaveValue('[email protected]');
await expect(page.locator('input[name=email]')).toHaveValue(mypageLoginPage.email);
await expect(page.locator('input[name=email02]')).toHaveValue(mypageLoginPage.email);
});

let confirmMessage: HttpMessage;
Expand All @@ -64,7 +64,7 @@ test.describe.serial('お問い合わせページのテストをします', () =
await expect(page.locator(`input[name=${ name }]`)).not.toBeEmpty();
});
await expect(page.locator('input[name=email]')).toBeHidden();
await expect(page.locator('input[name=email]')).toHaveValue('[email protected]');
await expect(page.locator('input[name=email]')).toHaveValue(mypageLoginPage.email);
await expect(page.locator('input[name=contents]')).toBeHidden();
await expect(page.locator('input[name=contents]')).toHaveValue('お問い合わせ入力');

Expand All @@ -79,7 +79,7 @@ test.describe.serial('お問い合わせページのテストをします', () =
await expect(page.locator('#form1 >> tr:nth-child(5) > td')).toContainText(await page.locator('input[name=tel01]').inputValue());
await expect(page.locator('#form1 >> tr:nth-child(5) > td')).toContainText(await page.locator('input[name=tel02]').inputValue());
await expect(page.locator('#form1 >> tr:nth-child(5) > td')).toContainText(await page.locator('input[name=tel03]').inputValue());
await expect(page.locator('#form1 >> tr:nth-child(6) > td')).toContainText('[email protected]');
await expect(page.locator('#form1 >> tr:nth-child(6) > td')).toContainText(mypageLoginPage.email);
await expect(page.locator('#form1 >> tr:nth-child(7) > td')).toContainText('お問い合わせ入力');

// お問い合わせ内容を送信します
Expand Down Expand Up @@ -112,7 +112,7 @@ test.describe.serial('お問い合わせページのテストをします', () =
test.describe('テストを実行します[POST][確認→完了] @attack', () => {
let requestBody: string;

test('アクティブスキャンを実行します', async () => {
test('アクティブスキャンを実行します', async ({ page }) => {

// transactionid を取得し直します
await page.goto(url);
Expand Down
3 changes: 3 additions & 0 deletions e2e-tests/utils/FakerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ export class FakerUtils {
static dummyImage() {
return path.join(__dirname, '..', 'fixtures', 'images', 'main.jpg');
}
static createPassword() {
return faker.string.uuid();
}
}

0 comments on commit 07927d8

Please sign in to comment.