Created
June 19, 2021 13:25
-
-
Save hoangsetup/61815d8f655aa72d4c42a1616c21d6bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IProduct } from '../interfaces'; | |
import BasePO from './base.po'; | |
class CartPO extends BasePO { | |
private readonly $cartItem = '.cart_item'; | |
private readonly $cart = { | |
$name: '.inventory_item_name', | |
$price: '.inventory_item_price', | |
}; | |
async go() { | |
await this.navigate('/cart.html'); | |
} | |
async getCartItems(): Promise<IProduct[]> { | |
const result: IProduct[] = []; | |
const $items = await page.$$(this.$cartItem); | |
for (const $item of $items) { | |
const $name = (await $item.$(this.$cart.$name))!; | |
const $price = (await $item.$(this.$cart.$price))!; | |
const priceText = await $price.evaluate((ele: HTMLElement) => ele.textContent || '0'); | |
result.push({ | |
name: await $name.evaluate((ele: HTMLElement) => ele.textContent || ''), | |
price: parseFloat(priceText.replace(/\n/g, '').replace('$', '')), | |
}); | |
} | |
return result; | |
} | |
} | |
export default new CartPO(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment