2023-03-16 13:03:38 +00:00
|
|
|
import { Page, Locator, ElementHandle } from '@playwright/test'
|
|
|
|
import { randomString } from './basic'
|
|
|
|
|
2023-06-04 10:46:33 +00:00
|
|
|
export async function closeSearchBox(page: Page): Promise<void> {
|
2023-11-14 06:05:18 +00:00
|
|
|
await page.keyboard.press("Escape", { delay: 50 }) // escape (potential) search box typing
|
2023-06-04 10:46:33 +00:00
|
|
|
await page.waitForTimeout(500)
|
2023-11-14 06:05:18 +00:00
|
|
|
await page.keyboard.press("Escape", { delay: 50 }) // escape modal
|
2023-06-04 10:46:33 +00:00
|
|
|
}
|
|
|
|
|
2023-03-16 13:03:38 +00:00
|
|
|
export async function createRandomPage(page: Page) {
|
|
|
|
const randomTitle = randomString(20)
|
2023-06-04 10:46:33 +00:00
|
|
|
await closeSearchBox(page)
|
2023-03-16 13:03:38 +00:00
|
|
|
// Click #search-button
|
|
|
|
await page.click('#search-button')
|
2023-11-06 09:21:14 +00:00
|
|
|
// Fill [placeholder="What are you looking for?"]
|
|
|
|
await page.fill('[placeholder="What are you looking for?"]', randomTitle)
|
|
|
|
await page.keyboard.press('Enter', { delay: 50 })
|
2023-03-16 13:03:38 +00:00
|
|
|
// Wait for h1 to be from our new page
|
|
|
|
await page.waitForSelector(`h1 >> text="${randomTitle}"`, { state: 'visible' })
|
|
|
|
// wait for textarea of first block
|
|
|
|
await page.waitForSelector('textarea >> nth=0', { state: 'visible' })
|
2023-06-12 10:56:52 +00:00
|
|
|
|
2023-03-16 13:03:38 +00:00
|
|
|
return randomTitle;
|
2023-06-04 10:46:33 +00:00
|
|
|
}
|
2023-06-12 10:56:52 +00:00
|
|
|
|
2023-06-04 10:46:33 +00:00
|
|
|
export async function createPage(page: Page, page_name: string) {// Click #search-button
|
|
|
|
await closeSearchBox(page)
|
2023-03-16 13:03:38 +00:00
|
|
|
await page.click('#search-button')
|
2023-11-06 09:21:14 +00:00
|
|
|
// Fill [placeholder="What are you looking for?"]
|
|
|
|
await page.fill('[placeholder="What are you looking for?"]', page_name)
|
2023-12-19 09:04:37 +00:00
|
|
|
await page.locator('text="Create page"').waitFor({ state: 'visible' })
|
2023-11-14 06:05:18 +00:00
|
|
|
await page.keyboard.press('Enter', { delay: 100 })
|
2023-03-16 13:03:38 +00:00
|
|
|
// wait for textarea of first block
|
|
|
|
await page.waitForSelector('textarea >> nth=0', { state: 'visible' })
|
2023-06-12 10:56:52 +00:00
|
|
|
|
2023-03-16 13:03:38 +00:00
|
|
|
return page_name;
|
2023-12-19 09:04:37 +00:00
|
|
|
}
|
2023-06-12 10:56:52 +00:00
|
|
|
|
2023-06-04 10:46:33 +00:00
|
|
|
export async function searchAndJumpToPage(page: Page, pageTitle: string) {
|
|
|
|
await closeSearchBox(page)
|
2023-03-16 13:03:38 +00:00
|
|
|
await page.click('#search-button')
|
2023-11-06 09:21:14 +00:00
|
|
|
await page.type('[placeholder="What are you looking for?"]', pageTitle)
|
2023-11-07 10:42:07 +00:00
|
|
|
await page.waitForTimeout(200)
|
|
|
|
await page.keyboard.press('Enter', { delay: 50 })
|
2023-03-16 13:03:38 +00:00
|
|
|
return pageTitle;
|
2023-06-04 10:46:33 +00:00
|
|
|
}
|
2023-06-04 09:55:14 +00:00
|
|
|
|
2023-06-04 10:46:33 +00:00
|
|
|
/**
|
|
|
|
* type a search query into the search box
|
|
|
|
* stop at the point where search box shows up
|
2023-06-12 10:56:52 +00:00
|
|
|
*
|
2023-06-04 10:46:33 +00:00
|
|
|
* @param page the pw page object
|
|
|
|
* @param query the search query to type into the search box
|
|
|
|
* @returns the HTML element for the search results ui
|
|
|
|
*/
|
2023-12-19 09:04:37 +00:00
|
|
|
export async function searchPage(page: Page, query: string): Promise<ElementHandle<SVGElement | HTMLElement>[]> {
|
2023-06-04 09:55:14 +00:00
|
|
|
await closeSearchBox(page)
|
2023-03-16 13:03:38 +00:00
|
|
|
await page.click('#search-button')
|
2023-11-06 09:21:14 +00:00
|
|
|
await page.waitForSelector('[placeholder="What are you looking for?"]')
|
|
|
|
await page.fill('[placeholder="What are you looking for?"]', query)
|
2023-03-16 13:03:38 +00:00
|
|
|
await page.waitForTimeout(2000) // wait longer for search contents to render
|
2023-06-12 10:56:52 +00:00
|
|
|
|
2023-11-06 13:51:22 +00:00
|
|
|
return page.$$('.search-results>div');
|
2023-06-04 10:46:33 +00:00
|
|
|
}
|