ファイル構成
config:eccubeへの接続情報が記載 (URLやログイン情報)
fixtures:テスト実行事前準備ファイル格納
(ECCUBEにログインしたり、受注情報を登録したりする)
(fixturesがないと、ECCUBEにアクセスできない)
pages:specで使う関数・クラスまとめ
spec:テストコード格納
type:
コード理解
場所:e2e-tests/spec/admin/order/order/list.spec.ts
関数:EA0401-UC03-T01 配送CSVダウンロード
ここでは、from 以降のパスでexportされているクラスや、定数を取得(import)している。
import {expect, test} from "../../../../fixtures/admin_login.fixture";
import {Order_count} from "../../../../types/order_count.type";
import {createOrder, hasExistingOrders} from "../../../../fixtures/admin/order/order.fixture";
import {AdminOrderListPage} from "../../../../pages/admin/order/order/list.page";
import {Download} from "@playwright/test";
import {Iconv} from "iconv";
EA0401-UC03-T01 配送CSVダウンロード
test('EA0401-UC03-T01 配送CSVダウンロード', async ({ loginPage, page }) => {
// ログイン実行がされたか確認
await loginPage.seeAfterLoginSuccess();
// 受注数を数えている??
const existingOrdersCnt: Order_count = await hasExistingOrders();
// 対象のid要素を取得
const OrderList = new AdminOrderListPage(page);
// documentをダウンロードし終えるまで待機
await page.waitForLoadState('domcontentloaded');
// 一覧押下
await OrderList.gotoViaMenu();
// 件数確認
await OrderList.confirmTotalResultCount(existingOrdersCnt.product_count);
// ダウンロードが開始されるまで待機
const downloadPromise = page.waitForEvent('download', { timeout: 2000});
// csvボタン -> 出荷・受注CSVが表示されるか確認
await OrderList.downloadOrderDeliveryCsv();
// イベント実行されたか確認
const download: Download = await downloadPromise;
// assert filename
// ダウンロードしたファイルとが、指定のファイル名と一致するか確認
expect(download.suggestedFilename()).toMatch(new RegExp('^shipping_\\d{14}\\.csv$'));
// get and assert stats
const fs = require('fs').promises;
// 疑問:何している?
expect((await fs.stat(await download.path() as string)).size).toBeGreaterThan(200);
const path: string = await download.path();
const content: string = await fs.readFile(path);
const iconv = new Iconv('SHIFT_JIS', 'UTF-8');
const utf8Content = iconv.convert(content).toString();
const rows = utf8Content.trim().split('\n');
const rowCount = rows.length;
expect(rowCount).toBeGreaterThan(existingOrdersCnt.product_count + 1);
});