I guess I’m just looking for feedback really. I’m not a professional QA tester and have no professional experience so I’m not really aware of any standards or conventions, or even professional expectations really. My testing using PlayWright is self taught, although I am a web developer. I’m just curious is there things I did wrong? Could have done better? Were there expectations of me that I wasn’t aware of?
I recently applied for a Junior QA role, there was a take home test in which I was to write a script in Playwright to fetch the first 100 articles for a webpage and check that they were in chronological order but they rejected me after submission.
The following is the script I ended up making.
const { chromium } = require('playwright');
const { expect } = require('playwright/test');
const fs = require('fs');
async function collectHackerNewsArticles() {
// Launch browser
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
let articles = [];
// Go to Hacker News news page with pagination
await page.goto(`https://news.ycombinator.com/newest`);
// Get current datetime
let dateNow = new Date();
// Slugify now
dateNowSlug = dateNow.toString()
.toLowerCase()
.replace(/^s+|s+$/g, '')
.replace(/[^a-z0-9 -]/g, '')
.replace(/s+/g, '-')
.replace(/-+/g, '-');
// Take a screenshot of the page
await page.screenshot({ path: `screenshots/hackernews-${dateNowSlug}.png` });
while (articles.length < 100) {
// Extract articles and their timestamps
const newArticles = await page.$$eval('.athing', nodes => {
return nodes.map(node => {
const id = node.querySelector('.rank').innerText;
const title = node.querySelector('.titleline a').innerText;
const age = node.nextElementSibling.querySelector('.age').innerText;
return { id, title, age };
});
});
articles = articles.concat(newArticles);
// Click "More" link
const moreLink = await page.$('.morelink');
if (moreLink) {
await moreLink.click();
} else {
break;
}
}
// Ensure only the first 100 articles are processed
articles = articles.slice(0, 100);
// Parse timestamps
const articlesColl = articles.map((article) => {
const timeParts = article.age.split(' ');
const timeValue = parseInt(timeParts[0]);
const timeUnit = timeParts[1];
let date = new Date();
if (timeUnit.includes('minute')) {
date.setMinutes(date.getMinutes() - timeValue);
} else if (timeUnit.includes('hour')) {
date.setHours(date.getHours() - timeValue);
} else if (timeUnit.includes('day')) {
date.setDate(date.getDate() - timeValue);
}
return { ...article, date };
})
// Write the data to a file
fs.writeFileSync('articles.json', JSON.stringify(articlesColl, null, 2));
// Close browser
await browser.close();
}
(async () => {
await collectHackerNewsArticles();
const articles = require('./articles.json');
// Iterate through the JSON file and make an assertion that the items are sorted chronologically
for (let i = 1; i < articles.length; i++) {
const ArticleIsNewer = new Date(articles[i - 1].date) >= new Date(articles[i].date);
expect(ArticleIsNewer).toBe(true);
}
})();
The script worked well as far as I’m aware, I’m just curious if they are things that are “expected” of a junior QA that I wasn’t aware of as I have no “professional” experience or specific education on the topic.