Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/fanatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
STACKOVERFLOW_PASSWORD: ${{ secrets.STACKOVERFLOW_PASSWORD }}
ALTERNATIVE_URL: ${{ secrets.ALTERNATIVE_URL }}
- name: Upload screenshots
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: screenshots
Expand Down
100 changes: 52 additions & 48 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,66 @@ import {

const browser = await playwright['chromium'].launch();
const page = await browser.newPage();
try {
console.log(`Login to ${url}`);
await page.goto(`${url}users/login`);
console.log('url', page.url());
await page.waitForSelector('#email');
await page.fill('#email', email);
await page.fill('#password', password);
await Promise.all([page.waitForURL(url), page.click('#submit-button')]);

console.log(`Login to ${url}`);
await page.goto(`${url}users/login`);
console.log('url', page.url());
await page.waitForSelector('#email');
await page.fill('#email', email);
await page.fill('#password', password);
await Promise.all([page.waitForURL(url), page.click('#submit-button')]);

const badgeNo = await getBadgeNumber(page, url);

console.log('Go to profile');
console.log('url', page.url());
await Promise.all([
page.waitForURL('**/users/**'),
page.click('.s-user-card'),
]);

console.log("Go to user's Fanatic badge page");
console.log('url', page.url());
const userid = page.url().split('/')[4];
console.log('userid', userid);
await page.goto(`${url}help/badges/${badgeNo}/?userid=${userid}`);

console.log('Has the user been awarded the Fanatic badge yet?');
console.log('url', page.url());
const awarded = await maybeGetBadgeAwardedText(page);
console.log('Fanatic awarded?', awarded || 'No');
await screenshotElement(page, '#mainbar', 'awarded.png');
const badgeNo = await getBadgeNumber(page, url);

if (!awarded) {
console.log('User does not have Fanatic badge yet so capture progress');
console.log('Go to profile');
console.log('url', page.url());
await Promise.all([
page.waitForURL('**/users/**'),
page.click('.s-user-card'),
]);

console.log("Go to user's Fanatic badge page");
console.log('url', page.url());
const userid = page.url().split('/')[4];
console.log('userid', userid);
await page.goto(`${url}help/badges/${badgeNo}/?userid=${userid}`);

console.log('Has the user been awarded the Fanatic badge yet?');
console.log('url', page.url());
await page.click('.js-select-badge-container');
const progressSelector = '[data-badge-database-name="Fanatic"]';
await page.waitForSelector(progressSelector);
const text = await page.evaluate(
(selector: string) =>
document.querySelector(selector)?.querySelector('.s-badge--label')
?.textContent,
progressSelector
);
console.log('Progress:', text);
await screenshotElement(page, progressSelector, 'progress.png');
const awarded = await maybeGetBadgeAwardedText(page);
console.log('Fanatic awarded?', awarded || 'No');
await screenshotElement(page, '#mainbar', 'awarded.png');

if (!text) throw new Error('Progress text is falsy');
const dayProgress = parseInt(text.slice(10).split('/')[0]);
if (dayProgress === 42) {
console.log("Create repo activity so workflow doesn't get disabled");
await generateFauxRepoActivity();
if (!awarded) {
console.log('User does not have Fanatic badge yet so capture progress');
await Promise.all([
page.waitForURL('**/users/**'),
page.click('.s-user-card'),
]);
console.log('url', page.url());
await page.click('.js-select-badge-container');
const progressSelector = '[data-badge-database-name="Fanatic"]';
await page.waitForSelector(progressSelector);
const text = await page.evaluate(
(selector: string) =>
document.querySelector(selector)?.querySelector('.s-badge--label')
?.textContent,
progressSelector
);
console.log('Progress:', text);
await screenshotElement(page, progressSelector, 'progress.png');

if (!text) throw new Error('Progress text is falsy');
const dayProgress = parseInt(text.slice(10).split('/')[0]);
if (dayProgress === 42) {
console.log("Create repo activity so workflow doesn't get disabled");
await generateFauxRepoActivity();
}
}
} catch (error) {
console.error('Error:', error);
await page.screenshot({path: 'error.png'});
} finally {
await browser.close();
}

await browser.close();
})();