Skip to content

Commit 933e274

Browse files
authored
Merge pull request #338 from Jimliu29/lab4
[LAB4] 110550078
2 parents de10488 + 987a88d commit 933e274

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

lab1/main_test.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,52 @@ const test = require('node:test');
22
const assert = require('assert');
33
const { MyClass, Student } = require('./main');
44

5+
const myclass = new MyClass;
6+
57
test("Test MyClass's addStudent", () => {
68
// TODO
7-
throw new Error("Test not implemented");
9+
assert.equal(-1, myclass.addStudent('Oops'));
10+
const student = new Student;
11+
const name = 'Kiwi'
12+
student.setName(name);
13+
assert.equal(0, myclass.addStudent(student));
14+
return;
15+
// throw new Error("Test not implemented");
816
});
917

1018
test("Test MyClass's getStudentById", () => {
1119
// TODO
12-
throw new Error("Test not implemented");
20+
assert.equal(null, myclass.getStudentById(-3));
21+
assert.equal(null, myclass.getStudentById(10));
22+
const student = new Student;
23+
const name = 'Kiwi'
24+
student.setName(name);
25+
const id = myclass.addStudent(student);
26+
assert.equal(student, myclass.getStudentById(id));
27+
return;
28+
// throw new Error("Test not implemented");
1329
});
1430

1531
test("Test Student's setName", () => {
1632
// TODO
17-
throw new Error("Test not implemented");
33+
const student = new Student;
34+
student.setName(123);
35+
assert.equal(undefined, student.name);
36+
37+
const name = 'Kiwi'
38+
student.setName(name);
39+
assert.equal(name, student.name);
40+
return;
41+
// throw new Error("Test not implemented");
1842
});
1943

2044
test("Test Student's getName", () => {
2145
// TODO
22-
throw new Error("Test not implemented");
46+
const student = new Student;
47+
assert.equal('', student.getName());
48+
const name = 'Kiwi'
49+
student.setName(name);
50+
assert.equal(name, student.getName());
51+
return;
52+
// throw new Error("Test not implemented");
2353
});

lab4/main_test.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const puppeteer = require('puppeteer');
22

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

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

20+
// (1) click search button
21+
const searchSelector = '#__docusaurus > nav > div.navbar__inner > div.navbar__items.navbar__items--right > div.navbarSearchContainer_IP3a > button > span.DocSearch-Button-Container > span';
22+
await page.click(searchSelector);
23+
24+
// (2) wait search box
25+
const typeSelector = '#docsearch-input';
26+
await page.waitForSelector(typeSelector);
27+
28+
// (3) type into search box
29+
await page.type(typeSelector, 'andy popoo');
30+
31+
// (4) wait for search result
32+
await new Promise(resolve => setTimeout(resolve, 500));
33+
const resultSelector = '#docsearch-hits1-item-4 > a';
34+
await page.waitForSelector(resultSelector);
35+
36+
// (5) click the result
37+
await page.click(resultSelector);
38+
39+
// (6) get the title
40+
const titleSelector = '#__docusaurus_skipToContent_fallback > div > div > main > div > div > div > div > article > div.theme-doc-markdown.markdown > header > h1';
41+
const textSelector = await page.waitForSelector(titleSelector);
42+
const fullTitle = await textSelector?.evaluate(el => el.innerText);
43+
44+
// (7) print the title
45+
console.log(fullTitle);
46+
2047
// Close the browser
2148
await browser.close();
2249
})();

0 commit comments

Comments
 (0)