Untitled
javascript
a month ago
1.8 kB
2
Indexable
Never
import { expect } from "@playwright/test"; import { ProductsListPage } from "../pages/products-list-page"; export class ItemListTesting { constructor(page) { this.page = page; } async testingScopeValue(testingMethod) { function randomNumber(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; } let itemId = randomNumber(1, 6); if (testingMethod == "single") { await this.page.locator('xpath=(//div/button[contains(@id,"add-to-cart")])[' + itemId + "]").click(); await expect(this.page.locator('xpath=(//div/button[contains(@id,"remove")])')).toHaveText("Remove"); await this.page.locator('xpath=(//div/button[contains(@id,"remove")])').click(); await this.page.locator('xpath=(//div[@class="inventory_item_name"])[' + itemId + "]").click(); await this.page.locator('xpath=(//div/button[contains(@id,"add-to-cart")])').click(); await expect(this.page.locator('xpath=(//div/button[contains(@id,"remove")])')).toHaveText("Remove"); await this.page.locator('xpath=(//div/button[contains(@id,"remove")])').click(); await this.page.locator('xpath=//div/button[contains(@id,"back")]').click(); await this.page.locator('xpath=(//div/button[contains(@id,"add-to-cart")])[' + itemId + "]").click(); await expect(this.page.locator('xpath=//span[@class="shopping_cart_badge"]')).toHaveText("1"); await this.page.locator('xpath=//span[@class="shopping_cart_badge"]').click(); await expect(this.page.locator('xpath=//div[@class="inventory_item_name"]')).toHaveCount(1); await this.page.locator('xpath=(//div/button[contains(@id,"remove")])').click(); await expect(this.page.locator('xpath=//div[@class="inventory_item_name"]')).toHaveCount(0); } } }