Skip to content

[LAB4] 110550078 #338

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 6 commits into
base: 110550078
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
38 changes: 34 additions & 4 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,52 @@ const test = require('node:test');
const assert = require('assert');
const { MyClass, Student } = require('./main');

const myclass = new MyClass;

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
assert.equal(-1, myclass.addStudent('Oops'));
const student = new Student;
const name = 'Kiwi'
student.setName(name);
assert.equal(0, myclass.addStudent(student));
return;
// throw new Error("Test not implemented");
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
assert.equal(null, myclass.getStudentById(-3));
assert.equal(null, myclass.getStudentById(10));
const student = new Student;
const name = 'Kiwi'
student.setName(name);
const id = myclass.addStudent(student);
assert.equal(student, myclass.getStudentById(id));
return;
// throw new Error("Test not implemented");
});

test("Test Student's setName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student;
student.setName(123);
assert.equal(undefined, student.name);

const name = 'Kiwi'
student.setName(name);
assert.equal(name, student.name);
return;
// throw new Error("Test not implemented");
});

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student;
assert.equal('', student.getName());
const name = 'Kiwi'
student.setName(name);
assert.equal(name, student.getName());
return;
// throw new Error("Test not implemented");
});
29 changes: 28 additions & 1 deletion lab4/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const puppeteer = require('puppeteer');

(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch();
const browser = await puppeteer.launch({executablePath: '/usr/bin/chromium-browser'});
const page = await browser.newPage();

// Navigate the page to a URL
Expand All @@ -17,6 +17,33 @@ const puppeteer = require('puppeteer');
// Locate the title
// Print the title

// (1) click search button
const searchSelector = '#__docusaurus > nav > div.navbar__inner > div.navbar__items.navbar__items--right > div.navbarSearchContainer_IP3a > button > span.DocSearch-Button-Container > span';
await page.click(searchSelector);

// (2) wait search box
const typeSelector = '#docsearch-input';
await page.waitForSelector(typeSelector);

// (3) type into search box
await page.type(typeSelector, 'andy popoo');

// (4) wait for search result
await new Promise(resolve => setTimeout(resolve, 500));
const resultSelector = '#docsearch-hits1-item-4 > a';
await page.waitForSelector(resultSelector);

// (5) click the result
await page.click(resultSelector);

// (6) get the title
const titleSelector = '#__docusaurus_skipToContent_fallback > div > div > main > div > div > div > div > article > div.theme-doc-markdown.markdown > header > h1';
const textSelector = await page.waitForSelector(titleSelector);
const fullTitle = await textSelector?.evaluate(el => el.innerText);

// (7) print the title
console.log(fullTitle);

// Close the browser
await browser.close();
})();