Skip to content

[LAB4] 312553027 #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: 312553027
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lab4/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,32 @@ const puppeteer = require('puppeteer');

// Hints:
// Click search button
await page.waitForSelector('#__docusaurus > nav > div.navbar__inner > div.navbar__items.navbar__items--right > div.navbarSearchContainer_IP3a > button > span.DocSearch-Button-Container > svg');
await page.click('#__docusaurus > nav > div.navbar__inner > div.navbar__items.navbar__items--right > div.navbarSearchContainer_IP3a > button > span.DocSearch-Button-Container > svg');
// Type into search box
await page.waitForSelector('.DocSearch-Input');
await page.type('.DocSearch-Input', 'andy popoo' , { delay: 100 });

// Wait for search result
await page.waitForSelector('.DocSearch-Hit');
// Get the `Docs` result section
// Click on first result in `Docs` section
await page.waitForSelector('.DocSearch-Hit', { timeout: 5000 });

const docsSection = await page.$$('.DocSearch-Hit');
const limit = 5; // limit the number of results to show
const visibleDocsSection = docsSection.slice(0, limit); // get the first 5 results

if (visibleDocsSection.length > 0) {
await visibleDocsSection[4].click();
} else {
console.log('No results found');
}
// Locate the title
// Print the title
await page.waitForSelector('h1');
const title = await page.$eval('h1', element => element.innerText);
console.log(title);

// Close the browser
await browser.close();
Expand Down