Skip to content

Commit

Permalink
shopping/deliv.php のテストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Mar 17, 2022
1 parent b97bc50 commit 81661b8
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
19 changes: 19 additions & 0 deletions e2e-tests/fixtures/cartin.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { test as base } from '@playwright/test';
import PlaywrightConfig from '../../playwright.config';
import { ProductsDetailPage } from '../pages/products/detail.page';
import { CartPage } from '../pages/cart.page';

/** 商品をカートに入れて購入手続きへ進むフィクスチャ. */
export const test = base.extend({
page: async ({ page }, use) => {
await page.goto(PlaywrightConfig.use.baseURL); // トップへ遷移しないと、スキャン後にカートが空になってしまう
const productsDetailPage = new ProductsDetailPage(page);
await productsDetailPage.goto(1);
await productsDetailPage.cartIn(2, '抹茶', 'S');
const cartPage = new CartPage(page);
await cartPage.gotoNext();
use(page);
}
});

export { expect } from '@playwright/test';
20 changes: 20 additions & 0 deletions e2e-tests/pages/cart.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Locator, Page } from '@playwright/test';
import PlaywrightConfig from '../../playwright.config';

export class CartPage {
readonly page: Page;
readonly nextButton: Locator;

constructor(page: Page) {
this.page = page;
this.nextButton = page.locator('input[name=confirm][alt=購入手続きへ]');
}

async goto() {
await this.page.goto(`${PlaywrightConfig.use.baseURL}/cart/index.php`);
}

async gotoNext() {
await this.nextButton.click();
}
}
33 changes: 33 additions & 0 deletions e2e-tests/pages/products/detail.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Locator, Page } from '@playwright/test';
import PlaywrightConfig from '../../../playwright.config';

export class ProductsDetailPage {
readonly page: Page;
readonly classCategoryId1: Locator;
readonly classCategoryId2: Locator;
readonly quantity: Locator;
readonly cartInButton: Locator;

constructor(page: Page) {
this.page = page;
this.classCategoryId1 = page.locator('select[name=classcategory_id1]');
this.classCategoryId2 = page.locator('select[name=classcategory_id2]');
this.quantity = page.locator('input[name=quantity]');
this.cartInButton = page.locator('[alt=カゴに入れる]');
}

async goto(productId: number) {
await this.page.goto(`${PlaywrightConfig.use.baseURL}/products/detail.php?product_id=${productId}`);
}

async cartIn(quantity?: number, classCategory1?: string, classCategory2?: string) {
await this.quantity.fill(String(quantity ?? 1));
if (classCategory1 !== undefined) {
await this.classCategoryId1.selectOption({ label: classCategory1 });
if (classCategory2 !== undefined) {
await this.classCategoryId2.selectOption({ label: classCategory2 });
}
}
await this.cartInButton.click();
}
}
60 changes: 60 additions & 0 deletions e2e-tests/test/front_login/shopping/shopping_deliv.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import PlaywrightConfig from '../../../../playwright.config';
import { ZapClient, ContextType, Risk, HttpMessage } from '../../../utils/ZapClient';
import { intervalRepeater } from '../../../utils/Progress';
const zapClient = new ZapClient();

const url = `${PlaywrightConfig.use.baseURL}/shopping/deliv.php`;

// 商品をカートに入れて購入手続きへ進むフィクスチャ
import { test, expect } from '../../../fixtures/cartin.fixture';

test.describe.serial('お届け先指定画面のテストをします', () => {
test.beforeAll(async () => {
await zapClient.startSession(ContextType.FrontLogin, 'front_login_shopping_deliv')
.then(async () => expect(await zapClient.isForcedUserModeEnabled()).toBeTruthy());
});

test('お届け先指定画面へ遷移します', async ( { page }) => {
await page.goto(url); // url を履歴に登録しておく
await expect(page.locator('h2.title')).toContainText('お届け先の指定');
});

test.describe('テストを実行します[GET] @attack', () => {
let scanId: number;
test('アクティブスキャンを実行します', async ( { page } ) => {
scanId = await zapClient.activeScanAsUser(url, 2, 110, false, null, 'GET');
await intervalRepeater(async () => await zapClient.getActiveScanStatus(scanId), 5000, page);
});

test('結果を確認します', async () => {
await zapClient.getAlerts(url, 0, 1, Risk.High)
.then(alerts => expect(alerts).toEqual([]));
});
});

test('お支払方法・お届け時間等の指定画面へ遷移します', async ( { page } ) => {
await page.click('input[alt=選択したお届け先に送る]');
await expect(page.locator('h2.title')).toContainText('お支払方法・お届け時間等の指定');
});

test.describe('お支払方法・お届け時間等の指定へ進むテストを実行します[POST] @attack', () => {
let message: HttpMessage;

test('履歴を取得します', async () => {
message = await zapClient.getLastMessage(url);
expect(message.requestHeader).toContain(`POST ${url}`);
expect(message.responseHeader).toContain('HTTP/1.1 302 Found');
});

let scanId: number;
test('アクティブスキャンを実行します', async ( { page } ) => {
scanId = await zapClient.activeScanAsUser(url, 2, 110, false, null, 'POST', message.requestBody);
await intervalRepeater(async () => await zapClient.getActiveScanStatus(scanId), 5000, page);
});

test('結果を確認します', async () => {
await zapClient.getAlerts(url, 0, 1, Risk.High)
.then(alerts => expect(alerts).toEqual([]));
});
});
});

0 comments on commit 81661b8

Please sign in to comment.