qa-wolf/tests/sort.spec.js

31 lines
969 B
JavaScript

const { expect, test } = require("playwright/test");
test("First 100 articles sorted", async ({ page }) => {
// go to Hacker News
await page.goto("https://news.ycombinator.com/newest");
// instantiate empty 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 (var 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 array elements
datestamps.splice(100, 20);
// Expect match
await expect(datestamps === datestamps.sort()).toBeTruthy;
});