diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b..a24c60f 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -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"); }); \ No newline at end of file diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a..a5d694f 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -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 @@ -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(); })(); \ No newline at end of file