Complete assessment
This commit is contained in:
parent
1fc4ffca79
commit
1b70ac612e
2 changed files with 33 additions and 1 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
node_modules/
|
||||
/test-results/
|
||||
/playwright-report/
|
||||
/playwright/.cache/
|
30
index.js
30
index.js
|
@ -1,4 +1,4 @@
|
|||
// EDIT THIS FILE TO COMPLETE ASSIGNMENT QUESTION 1
|
||||
// Solution by Ethan Ruszanowski
|
||||
const { chromium } = require("playwright");
|
||||
|
||||
async function sortHackerNewsArticles() {
|
||||
|
@ -9,6 +9,34 @@ async function sortHackerNewsArticles() {
|
|||
|
||||
// go to Hacker News
|
||||
await page.goto("https://news.ycombinator.com/newest");
|
||||
|
||||
// instantiate array for all date objects
|
||||
let datestamps = []
|
||||
|
||||
// loop through process per page
|
||||
for (var pageview = 0; pageview <= 3; pageview++) {
|
||||
// locate each article's age span
|
||||
let datespans = await page.locator('.age').all();
|
||||
|
||||
// iterate through date spans to get timestamps
|
||||
for (row = 0; row < datespans.length; row++) {
|
||||
// turn timestamp strings into date objects and push to array
|
||||
datestamps.push(new Date(await datespans[row].getAttribute('title')));
|
||||
}
|
||||
|
||||
// click the next button as needed
|
||||
await page.getByRole('link', { name: 'More', exact: true }).click();
|
||||
}
|
||||
|
||||
// drop extra articles from last page grab
|
||||
datestamps = datestamps.slice(0, 100);
|
||||
|
||||
// report results
|
||||
if (datestamps === datestamps.sort()) {
|
||||
console.log("Success! The first 100 articles are correctly sorted by posting time.")
|
||||
} else {
|
||||
console.log("Failure… The first 100 articles are not correctly sorted by posting time.")
|
||||
}
|
||||
}
|
||||
|
||||
(async () => {
|
||||
|
|
Loading…
Reference in a new issue