Skip to content

[LAB4] 313551801 #339

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: 313551801
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lab2/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Application {
this.people = [];
this.selected = [];
this.mailSystem = new MailSystem();

this.getNames().then(([people, selected]) => {
this.people = people;
this.selected = selected;
Expand Down
2 changes: 1 addition & 1 deletion lab2/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ const assert = require('assert');
const { Application, MailSystem } = require('./main');

// TODO: write your tests here
// Remember to use Stub, Mock, and Spy when necessary
// Remember to use Stub, Mock, and Spy when necessary
162 changes: 162 additions & 0 deletions lab2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lab2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"sinon": "^19.0.4"
}
}
61 changes: 48 additions & 13 deletions lab4/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,56 @@ const puppeteer = require('puppeteer');

(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch();
const browser = await puppeteer.launch({
headless: false,
slowMo: 1
});
const page = await browser.newPage();

// Navigate the page to a URL
await page.goto('https://pptr.dev/');

// Hints:
// Click search button
// Type into search box
// Wait for search result
// Get the `Docs` result section
// Click on first result in `Docs` section
// Locate the title
// Print the title
try {
await page.goto('https://pptr.dev/');
await page.setViewport({ width: 1080, height: 1024 });

// Click search button
await page.click('.DocSearch-Button');
await page.waitForSelector('.DocSearch-Input');
// Type into search box
// Wait for search result
await page.type('.DocSearch-Input', 'Andy popoo');

// Get the `Docs` result section
// Click on first result in `Docs` section
await page.waitForFunction(() => {
const bits = document.querySelectorAll('.DocSearch-Hit-source');
return Array.from(bits).some(el =>
el.textContent.trim() === 'ElementHandle'
);
}, { timeout: 8000 });

await page.evaluate(() => {
const bits = document.querySelectorAll('.DocSearch-Hit-source');
for (const bite of bits) {
if (bite.textContent.trim() === 'ElementHandle') {
const parent = bite.parentElement;
const first = parent.querySelector('.DocSearch-Hit a');
if (first) {
first.click();
return true;
}
}
}
throw new Error('No results found for elementhandle');
});

// locate and print the title
await page.waitForSelector('h1');
const header = await page.$eval('h1', el => el.textContent.trim());
console.log(header);

// Close the browser
await browser.close();
} catch (error) {
console.error('Error:', error.message);
} finally {
await browser.close();
}
})();
Loading