-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment2.spec.js
More file actions
80 lines (54 loc) · 2.91 KB
/
Assignment2.spec.js
File metadata and controls
80 lines (54 loc) · 2.91 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const { test, expect } = require('@playwright/test');
test('single dropdown',async({page})=>{
await page.goto("https://demoqa.com/")
await page.getByText("Widgets").click()
await page.getByText("Select Menu").click()
//Select Option
await page.getByText("Select Option").click()
const select_Option = "Group 2, option 2"
await page.getByText(select_Option).click()
await expect(page.locator("div.css-1uccc91-singleValue")).toHaveText(select_Option)
//Select Title
await page.getByText("Select Title").click()
await page.getByText("Mr.").click()
const select_Title_Value = await page.locator("div#selectOne div.css-1uccc91-singleValue").textContent()
expect(select_Title_Value).toBe("Mr.")
//oldSelectMenu
const selectOption = "Green"
const menus= await page.locator("select#oldSelectMenu>option").all()
console.log("Option List : "+menus.length);
for(const menu of menus){
console.log(await menu.textContent())
}
await page.locator("select#oldSelectMenu").selectOption(selectOption)
const selectedValue = await page.locator("select#oldSelectMenu").locator("option:checked").textContent();
console.log("Selected Option :"+selectedValue);
//Multiselect drop down
await page.getByText("Select...").click()
// const elements = await page.locator("(//div[contains(@class,'css-2b097c-container')])[3]//div").elementHandles()
// const elements = await page.locator("div.css-2b097c-container").nth(2).locator("div").elementHandles()
// for(const ele of elements){
// console.log(await ele.innerHTML())
// }
const values = await page.locator("div.css-2b097c-container").nth(2).locator("div.css-11unzgr>div").allTextContents()
console.log("Option size : "+values.length)
console.log("Option list : " + values)
for (const value of values) {
const optionValue = value.trim()
await page.getByText(optionValue).nth(2).click({force:true})
}
const selectedOptions = await page.locator("div.css-1rhbuit-multiValue").allTextContents()
console.log(`Selected Options : ${selectedOptions}`)
expect(await page.locator("div.css-1rhbuit-multiValue")).toContainText(selectedOptions)
//Standard multi select
const carsOptionList = await page.locator("select#cars>option").allTextContents()
console.log("Cars drop-down length :"+carsOptionList.length)
console.log("Cars drop-down Option :"+carsOptionList)
await page.locator("select#cars").selectOption([...carsOptionList])
const selectedCarsList = await page.locator("select#cars").locator("option:checked").allTextContents()
console.log(`Selected cars drop-down size ${selectedCarsList.length}`)
console.log(`Selected cars drop-down Name : ${selectedCarsList}`)
expect(carsOptionList.length).toBe(selectedCarsList.length)
expect(carsOptionList).toEqual(selectedCarsList);
await page.waitForTimeout(6000)
})