-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lab7' of https://github.com/s123tg/112-spring-software-…
…testing into lab7
- Loading branch information
Showing
4 changed files
with
107 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,74 @@ | ||
const test = require('node:test'); | ||
const assert = require('assert'); | ||
const fs=require('fs'); | ||
const { Application, MailSystem } = require('./main'); | ||
|
||
// TODO: write your tests here | ||
// Remember to use Stub, Mock, and Spy when necessary | ||
|
||
test('mailsystem write',(t)=>{ | ||
const ms=new MailSystem(); | ||
assert.strictEqual(ms.write('sam'), 'Congrats, sam!'); | ||
}); | ||
test('mailsystem send',(t)=>{ | ||
const ms=new MailSystem(); | ||
assert.strictEqual(typeof(ms.send('sam','mail')), 'boolean'); | ||
assert.strictEqual(typeof(ms.send('sam','mail')), 'boolean'); | ||
assert.strictEqual(typeof(ms.send('sam','mail')), 'boolean'); | ||
assert.strictEqual(typeof(ms.send('sam','mail')), 'boolean'); | ||
assert.strictEqual(typeof(ms.send('sam','mail')), 'boolean'); | ||
assert.strictEqual(typeof(ms.send('sam','mail')), 'boolean'); | ||
assert.strictEqual(typeof(ms.send('sam','mail')), 'boolean'); | ||
assert.strictEqual(typeof(ms.send('sam','mail')), 'boolean'); | ||
assert.strictEqual(typeof(ms.send('sam','mail')), 'boolean'); | ||
assert.strictEqual(typeof(ms.send('sam','mail')), 'boolean'); | ||
}); | ||
test('mailsystem getName',async (t)=>{ | ||
fs.writeFileSync('name_list.txt','sam\ntom\njeck','utf8'); | ||
const app=new Application(); | ||
const [people, selected] = await app.getNames(); | ||
assert.strictEqual(people[0], 'sam'); | ||
assert.strictEqual(people[1], 'tom'); | ||
assert.strictEqual(people[2], 'jeck'); | ||
fs.unlinkSync('name_list.txt'); | ||
}); | ||
test('mailsystem getran',async (t)=>{ | ||
fs.writeFileSync('name_list.txt','sam\ntom\njeck','UTF-8'); | ||
const app=new Application(); | ||
await app.getNames(); | ||
await app.getNames(); | ||
await app.getNames(); | ||
await app.getNames(); | ||
assert.match(app.getRandomPerson(), /^(sam|tom|jeck)$/); | ||
fs.unlinkSync('name_list.txt'); | ||
}); | ||
test('Application selectNextPerson',async (t)=>{ | ||
fs.writeFileSync('name_list.txt','sam\ntom\njeck','UTF-8'); | ||
const app=new Application(); | ||
await app.getNames(); | ||
await app.getNames(); | ||
await app.getNames(); | ||
await app.getNames(); | ||
assert.match(app.selectNextPerson(), /^(sam|tom|jeck)$/); | ||
assert.match(app.selectNextPerson(), /^(sam|tom|jeck)$/); | ||
assert.match(app.selectNextPerson(), /^(sam|tom|jeck)$/); | ||
assert.strictEqual(app.selectNextPerson(), null); | ||
fs.unlinkSync('name_list.txt'); | ||
}); | ||
test('Application notifySelected',async (t)=>{ | ||
fs.writeFileSync('name_list.txt','sam\ntom\njeck','UTF-8'); | ||
const app=new Application(); | ||
await app.getNames(); | ||
await app.getNames(); | ||
await app.getNames(); | ||
await app.getNames(); | ||
app.selectNextPerson(); | ||
assert.strictEqual(app.notifySelected(), undefined); | ||
assert.strictEqual(app.notifySelected(), undefined); | ||
assert.strictEqual(app.notifySelected(), undefined); | ||
assert.strictEqual(app.notifySelected(), undefined); | ||
app.selectNextPerson(); | ||
assert.strictEqual(app.notifySelected(), undefined); | ||
assert.strictEqual(app.notifySelected(), undefined); | ||
assert.strictEqual(app.notifySelected(), undefined); | ||
assert.strictEqual(app.notifySelected(), undefined); | ||
fs.unlinkSync('name_list.txt'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,23 @@ | ||
const puppeteer = require('puppeteer'); | ||
|
||
(async () => { | ||
|
||
// Launch the browser and open a new blank page | ||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
|
||
// Navigate the page to a URL | ||
await page.goto('https://pptr.dev/'); | ||
|
||
const serachButton='.DocSearch-Button-Placeholder'; | ||
await page.waitForSelector(serachButton); | ||
await page.click(serachButton); | ||
await page.waitForSelector('#docsearch-input'); | ||
await page.type('#docsearch-input','chipi chipi chapa chapa'); | ||
// const searchBar = await page.waitForSelector('.DocSearch-Dropdown-Container'); | ||
// const Docs = await searchBar?.$$('.DocSearch-Hits'); | ||
const pageButton = '#docsearch-item-5'; | ||
const button = await page.waitForSelector(pageButton); | ||
const b = await button?.waitForSelector('.DocSearch-Hit-Select-Icon'); | ||
const a = await b?.evaluate(element => { | ||
if (element) { | ||
// Extract information about the element | ||
return { | ||
tagName: element.tagName, | ||
textContent: element.textContent, | ||
attributes: Array.from(element.attributes).map(attr => ({ name: attr.name, value: attr.value })) | ||
}; | ||
} else { | ||
return null; // If element is not found, return null | ||
} | ||
}); | ||
console.log(a); | ||
try{await b.click();}catch(error){console.error(error)} | ||
// await page.waitForNavigation(); | ||
console.log('Navigation complete. Current URL:', page.url()); | ||
const pageSelector = await page.waitForSelector('.theme-doc-markdown.markdown ul'); | ||
// const titleSelector = await pageSelector.waitForSelector('.h1'); | ||
const title = await pageSelector?.evaluate(element=>element.textContent); | ||
console.log(title); | ||
// 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 | ||
|
||
// Close the browser | ||
await browser.close(); | ||
})(); |