-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverviewCheckout.po.ts
62 lines (54 loc) · 1.85 KB
/
overviewCheckout.po.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Locator, Page } from '@playwright/test'
import { CartItem } from './shared/cartItem.po'
import { ShoppingCart } from './shoppingCart.po'
import { CompleteCheckout } from './completeCheckout.po'
export class OverviewCheckout {
readonly page: Page
readonly checkoutItems: Locator
readonly paymentInformation: Locator
readonly shippingInformation: Locator
readonly itemTotal: Locator
readonly tax: Locator
readonly total: Locator
readonly cancelButton: Locator
readonly finishButton: Locator
constructor(page: Page) {
this.page = page
this.checkoutItems = page.locator('.cart_item')
this.paymentInformation = page.locator(
`":text('Payment Information') + .summary_value_label"`
)
this.shippingInformation = page.locator(
`":text('Shipping Information') + .summary_value_label"`
)
this.itemTotal = page.locator('.summary_subtotal_label')
this.tax = page.locator('.summary_tax_label')
this.total = page.locator('.summary_total_label')
this.cancelButton = page.getByTestId('cancel')
this.finishButton = page.getByTestId('finish')
}
async getCheckoutItems() {
const checkoutItems = await this.checkoutItems.all()
return checkoutItems.map((item) => new CartItem(item))
}
async getItemTotal() {
const itemTotalText = await this.itemTotal.innerText()
return parseFloat(itemTotalText.replace('Item total: $', ''))
}
async getTax() {
const taxText = await this.tax.innerText()
return parseFloat(taxText.replace('Tax: $', ''))
}
async getTotal() {
const totalText = await this.total.innerText()
return parseFloat(totalText.replace('Total: $', ''))
}
async finishCheckout() {
await this.finishButton.click()
return new CompleteCheckout(this.page)
}
async cancelCheckout() {
await this.cancelButton.click()
return new ShoppingCart(this.page)
}
}