-
Notifications
You must be signed in to change notification settings - Fork 2
/
context-menu.spec.js
28 lines (23 loc) · 1.21 KB
/
context-menu.spec.js
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
const { test, expect } = require("@playwright/test");
test.describe("Context Menu", () => {
test("Should click on each menu and sub-menu item", async ({ page }) => {
await page.goto("apps/context-menu/");
await expect(page.locator('text="Open Right-Click Context Menu"')).toBeVisible();
const menuItems = ["Preview", "Get Link", "Rename", "Delete", "Settings"];
const subMenuItems = ["Twitter", "Instagram", "Dribble", "Telegram"];
const message = page.locator("#msg"); // html paragraph
// Validate menu items
for (let index = 0; index < menuItems.length; index++) {
await page.click("body", { button: "right", delay: 300 }); // right click on the page
await page.locator("text=" + menuItems[index]).click();
await expect(message).toContainText(menuItems[index]);
}
// Validate sub-menu items
for (let index = 0; index < subMenuItems.length; index++) {
await page.click("body", { button: "right", delay: 300 }); // right click on the page
await page.locator('text="Share"').hover(); // Opens Share sub-menu
await page.locator(".share >> text=" + subMenuItems[index]).click();
await expect(message).toContainText(subMenuItems[index]);
}
});
});