Skip to content

Commit

Permalink
Add page objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Mar 18, 2022
1 parent 94b20a9 commit 284b7fa
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
32 changes: 32 additions & 0 deletions e2e-tests/pages/shopping/deliv.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Locator, Page } from '@playwright/test';
import PlaywrightConfig from '../../../playwright.config';

export class ShoppingDelivPage {
readonly page: Page;
readonly nextButton: Locator;
readonly addNewDeliveryAddressButton: Locator;
readonly sendToMultipleButton: Locator;

constructor(page: Page) {
this.page = page;
this.nextButton = page.locator('input[alt=選択したお届け先に送る]');
this.addNewDeliveryAddressButton = page.locator('[alt=新しいお届け先を追加する]');
this.sendToMultipleButton = page.locator('[alt=お届け先を複数指定する]');
}

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

async gotoNext() {
await this.nextButton.click();
}

async gotoAddNewDeliveryAddress() {
await this.addNewDeliveryAddressButton.click();
}

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

export class ShoppingPaymentPage {
readonly page: Page;
readonly nextButton: Locator;
readonly paymentMethod: Locator;
readonly deliveryDate: Locator;
readonly deliveryTime: Locator;
readonly enablePoint: Locator;
readonly disablePoint: Locator;
readonly usePoint: Locator;
readonly message: Locator;

constructor(page: Page) {
this.page = page;
this.nextButton = page.locator('[alt=次へ]');
this.paymentMethod = page.locator('#payment');
this.deliveryDate = page.locator('#deliv_date0');
this.deliveryTime = page.locator('#deliv_time_id0');
this.enablePoint = page.locator('#point_on');
this.disablePoint = page.locator('#point_off');
this.usePoint = page.locator('input[name=use_point]');
this.message = page.locator('textarea[name=message]');
}

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

async gotoNext() {
await this.nextButton.click();
}

async selectPaymentMethod(label: string) {
await this.paymentMethod.locator(`text=${label}`).click();
}

async selectDeliveryDate(index: number) {
await this.deliveryDate.selectOption({ index: index });
}

async selectDeliveryTime(index: number) {
await this.deliveryTime.selectOption({ index: index });
}

async chooseToUsePoint() {
await this.enablePoint.check();
}

async doNotChooseToUsePoint() {
await this.disablePoint.check();
}

async fillUsePoint(point: number) {
await this.usePoint.fill(String(point));
}

async fillMessage(message: string) {
await this.message.fill(message);
}

async fillOut(paymentMethod?: string, deliveryDateIndex?: number, deliveryTimeIndex?:number, message?: string, usePoint?: number) {
await this.selectPaymentMethod(paymentMethod ?? '銀行振込');
await this.selectDeliveryDate(deliveryDateIndex ?? 1);
await this.selectDeliveryTime(deliveryTimeIndex ?? 1);
await this.fillMessage(message ?? 'お問い合わせ');

if (await this.enablePoint.isVisible()) {
await this.chooseToUsePoint();
await this.fillUsePoint(usePoint ?? 1);
}
}
}

0 comments on commit 284b7fa

Please sign in to comment.