Skip to content

Instantly share code, notes, and snippets.

@hoangsetup
Created June 19, 2021 13:25
Show Gist options
  • Save hoangsetup/61815d8f655aa72d4c42a1616c21d6bd to your computer and use it in GitHub Desktop.
Save hoangsetup/61815d8f655aa72d4c42a1616c21d6bd to your computer and use it in GitHub Desktop.
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