-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarket.spec.ts
More file actions
66 lines (54 loc) · 2.11 KB
/
Copy pathmarket.spec.ts
File metadata and controls
66 lines (54 loc) · 2.11 KB
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
63
64
65
66
import { expect, Page, test } from "@playwright/test";
test.describe.serial("Market Tests", () => {
test.beforeEach(async ({ page }) => {
// Navigate to the game page before each test
await page.goto("/");
// Open the market
const marketButton = await page.locator("#market-toolbar-btn");
await marketButton.click();
});
test("should buy a carrot seed from the market", async ({ page }) => {
await buyCarrotSeed(page);
});
});
export async function buyCarrotSeed(page: Page) {
// Verify the market is visible
const marketBuyButton = await page.locator("#market-buy");
await expect(marketBuyButton).toBeVisible();
// click on the market buy button
await marketBuyButton.click();
// get all the items that have text "Owned:"
const ownedItems = await page.locator("text=Owned:");
// Get the first owned item (carrot seeds)
const ownedCarrotSeed = await ownedItems.first();
// Extract the number from the inner span
const ownedCount = await ownedCarrotSeed
.locator("span.text-white\\/90")
.textContent();
// Verify the carrot seed is visible
const carrotSeed = await page.locator(
'[data-testid="market-buy-sell-item-carrot-seeds-1"]'
);
await expect(carrotSeed).toBeVisible();
// click on the carrot seed
await carrotSeed.click();
// Verify the carrot seed is planted
const plantedCarrotSeed = await page.locator("#carrot-seeds");
await expect(plantedCarrotSeed).toBeVisible();
// wait 2 seconds
await page.waitForTimeout(2000);
// get all the items that have text "Owned:"
const newOwnedItems = await page.locator("text=Owned:");
// Get the first owned item (carrot seeds)
const newOwnedCarrotSeed = await newOwnedItems.first();
// Extract the number from the inner span
const newOwnedCount = await newOwnedCarrotSeed
.locator("span.text-white\\/90")
.textContent();
// Verify the number of owned carrot seeds has increased by 1
if (ownedCount && !isNaN(Number(ownedCount)) && Number(ownedCount) > 0) {
expect(newOwnedCount).toBe((Number(ownedCount) + 1).toString());
} else {
throw new Error("No owned carrot seeds found");
}
}