Untitled
unknown
javascript
2 years ago
1.9 kB
11
Indexable
import { expect } from "@playwright/test";
import { ProductsListPage } from "../pages/products-list-page";
export class ItemListTesting {
constructor(page) {
this.page = page;
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);
this.itemId = itemId;
}
async testingScopeValue(testingMethod) {
if (testingMethod == "single") {
await this.page.locator('xpath=(//div/button[contains(@id,"add-to-cart")])[' + this.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"])[' + this.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")])[' + this.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);
}
}
}
Editor is loading...