Skip to content

Commit

Permalink
Add front_guest/shopping_multiple.test
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Jan 21, 2025
1 parent 747bbc2 commit 46cfa05
Showing 1 changed file with 116 additions and 0 deletions.
116 changes: 116 additions & 0 deletions e2e-tests/test/front_guest/shopping_multiple.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { test, expect, chromium, Page, request, APIRequestContext } from '@playwright/test';
import PlaywrightConfig from '../../../playwright.config';
import { ProductsDetailPage } from '../../pages/products/detail.page';
import { CartPage } from '../../pages/cart.page';
import { PersonalInputPage } from '../../pages/personal_input.page';
import { ShoppingMultiplePage } from '../../pages/shopping/multiple.page';
import { ShoppingPaymentPage } from '../../pages/shopping/payment.page';
import { MypageDeliveryAddrPage } from '../../pages/mypage/delivery_addr.page';
import { faker } from '@faker-js/faker/locale/ja';
import { FakerUtils } from '../../utils/FakerUtils';

const url = '/products/list.php?category_id=3';

test.describe.serial('購入フロー(ゲスト)のテストをします', () => {
let mailcatcher: APIRequestContext;
test.beforeAll(async () => {
mailcatcher = await request.newContext({
baseURL: PlaywrightConfig.use?.proxy ? 'http://mailcatcher:1080' : 'http://localhost:1080',
proxy: PlaywrightConfig.use?.proxy
});
await mailcatcher.delete('/messages');
});

test('商品を購入します', async ({ page }) => {
await page.goto(url);
await test.step('商品一覧を表示します', async () => {
await expect(page.locator('form[name=product_form1] >> h3')).toContainText('アイスクリーム');
});

await test.step('商品をカートに入れます', async () => {
const productsDetailPage = new ProductsDetailPage(page);
await productsDetailPage.cartIn(
2,
faker.helpers.arrayElement(['抹茶', 'チョコ', 'バニラ']),
faker.helpers.arrayElement(['S', 'M', 'L'])
);
});

await test.step('カートの内容を確認します', async () => {
await expect(page.locator('h2.title')).toContainText('現在のカゴの中');
await expect(page.locator('table[summary=商品情報] >> tr >> nth=1')).toContainText('アイスクリーム');
const cartPage = new CartPage(page);
await cartPage.gotoNext();
});

await test.step('購入手続きへ進みます', async () => {
await expect(page).toHaveTitle(//);
await page.click('[alt=購入手続きへ]');
});

const email = FakerUtils.createEmail();
await test.step('お客様情報を入力します', async () => {
const personalInputPage = new PersonalInputPage(page, email, url, 'order_');
await personalInputPage.fillName();
await personalInputPage.fillCompany();
await personalInputPage.fillAddress();
await personalInputPage.fillTel();
await personalInputPage.fillFax();

await personalInputPage.fillEmail();
await personalInputPage.fillPersonalInfo();

await page.click('text=お届け先を指定');

const shoppingInputPage = new PersonalInputPage(page, email, url, 'shipping_');
await shoppingInputPage.fillName();
await shoppingInputPage.fillCompany();
await shoppingInputPage.fillAddress();
await shoppingInputPage.fillTel();
await shoppingInputPage.fillFax();
await page.pause();
await page.click('[alt=複数のお届け先に送る]');
});

await test.step('複数のお届け先を指定します', async () => {
const popupPromise = page.waitForEvent('popup');
await page.getByAltText('新しいお届け先を追加する').click();
const popup = await popupPromise;
const mypageDeliveryAddrPage = new MypageDeliveryAddrPage(popup);
await mypageDeliveryAddrPage.fill();
await mypageDeliveryAddrPage.register();

const shoppingMultiplePage = new ShoppingMultiplePage(page);
await shoppingMultiplePage.assignDeliveryAddress(0, 1);
await shoppingMultiplePage.assignDeliveryAddress(1, 3);
await shoppingMultiplePage.gotoNext();
});

await test.step('お支払い方法・お届け時間の指定をします', async () => {
const shoppingPaymentPage = new ShoppingPaymentPage(page);
await shoppingPaymentPage.selectPaymentMethod(faker.helpers.arrayElement(['郵便振替', '現金書留', '銀行振込', '代金引換']));
await shoppingPaymentPage.selectDeliveryDate(faker.number.int({ min: 0, max: 5 }));
await shoppingPaymentPage.selectDeliveryTime(faker.number.int({ min: 0, max: 2 }));
await shoppingPaymentPage.fillMessage(faker.lorem.sentence());
await shoppingPaymentPage.gotoNext();
});

await test.step('入力内容の確認をします', async () => {
await expect(page.locator('h2.title')).toContainText('入力内容のご確認');
await page.click('[alt=ご注文完了ページへ]');
});

await test.step('注文完了を確認します', async () => {
await expect(page.locator('h2.title')).toContainText('ご注文完了');

const messages = await mailcatcher.get('/messages');
expect((await messages.json()).length).toBe(1);
expect(await messages.json()).toContainEqual(expect.objectContaining(
{
subject: expect.stringContaining('ご注文ありがとうございます'),
recipients: expect.arrayContaining([ `<${ email }>` ])
}
));
});
});
});

0 comments on commit 46cfa05

Please sign in to comment.