epic-games: title_url as filename, GET-button as loading barrier

This commit is contained in:
Ralf Vogler 2022-07-14 17:09:41 +02:00
parent f888981415
commit 4868ba66f9

View file

@ -64,20 +64,21 @@ try {
const n = run.n = await page.locator(game_sel).count(); const n = run.n = await page.locator(game_sel).count();
console.log('Number of free games:', n); console.log('Number of free games:', n);
for (let i = 1; i <= n; i++) { for (let i = 1; i <= n; i++) {
await page.click(`:nth-match(${game_sel}, ${i})`); await page.click(`:nth-match(${game_sel}, ${i})`); // navigates to page for game
const title = await page.locator('h1').first().innerText(); const btnText = await page.locator('//button[@data-testid="purchase-cta-button"][not(contains(.,"Loading"))]').first().innerText(); // barrier to block until page is loaded
console.log('Current free game:', title);
// click Continue if 'This game contains mature content recommended only for ages 18+' // click Continue if 'This game contains mature content recommended only for ages 18+'
if (await page.locator('button:has-text("Continue")').count() > 0) { if (await page.locator('button:has-text("Continue")').count() > 0) {
console.log('This game contains mature content recommended only for ages 18+'); console.log('This game contains mature content recommended only for ages 18+');
await page.click('button:has-text("Continue")'); await page.click('button:has-text("Continue")');
} }
const btnText = await page.locator('//button[@data-testid="purchase-cta-button"][not(contains(.,"Loading"))]').first().innerText(); const title = await page.locator('h1').first().innerText();
const p = path.resolve(dirs.screenshots, 'epic-games', `${title.replace(/[^a-z0-9]/gi, '_')}.png`); console.log('Current free game:', title);
const title_url = page.url().split('/').pop();
const p = path.resolve(dirs.screenshots, 'epic-games', `${title_url}.png`);
await page.screenshot({ path: p, fullPage: false }); // fullPage is quite long... await page.screenshot({ path: p, fullPage: false }); // fullPage is quite long...
if (btnText.toLowerCase() == 'in library') { if (btnText.toLowerCase() == 'in library') {
console.log('Already in library! Nothing to claim.'); console.log('Already in library! Nothing to claim.');
} else { } else { // GET
console.log('Not in library yet! Click GET.'); console.log('Not in library yet! Click GET.');
await page.click('[data-testid="purchase-cta-button"]'); await page.click('[data-testid="purchase-cta-button"]');
// click Continue if 'Device not supported. This product is not compatible with your current device.' // click Continue if 'Device not supported. This product is not compatible with your current device.'