pg: scrollUntilStable to wait in loop to load all games since one scroll may not be enough
This commit is contained in:
parent
17f1ee41c9
commit
b8f7068a87
1 changed files with 18 additions and 16 deletions
|
|
@ -97,12 +97,25 @@ try {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
await page.click('button[data-type="Game"]');
|
const waitUntilStable = async (f, act) => {
|
||||||
|
let v;
|
||||||
|
while (true) {
|
||||||
|
const v2 = await f();
|
||||||
|
if (v == v2) break;
|
||||||
|
v = v2;
|
||||||
|
await act();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const scrollUntilStable = async f => waitUntilStable(f, async () => {
|
||||||
await page.keyboard.press('End'); // scroll to bottom to show all games
|
await page.keyboard.press('End'); // scroll to bottom to show all games
|
||||||
await page.waitForLoadState('networkidle'); // wait for all games to be loaded
|
await page.waitForLoadState('networkidle'); // wait for all games to be loaded
|
||||||
await page.waitForTimeout(2000); // TODO networkidle wasn't enough to load all already collected games
|
await page.waitForTimeout(2000); // TODO networkidle wasn't enough to load all already collected games
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.click('button[data-type="Game"]');
|
||||||
const games = page.locator('div[data-a-target="offer-list-FGWP_FULL"]');
|
const games = page.locator('div[data-a-target="offer-list-FGWP_FULL"]');
|
||||||
await games.waitFor();
|
await games.waitFor();
|
||||||
|
await scrollUntilStable(() => games.locator('.item-card__action').count());
|
||||||
console.log('Number of already claimed games (total):', await games.locator('p:has-text("Collected")').count());
|
console.log('Number of already claimed games (total):', await games.locator('p:has-text("Collected")').count());
|
||||||
// can't use .all() since the list of elements via locator will change after click while we iterate over it
|
// can't use .all() since the list of elements via locator will change after click while we iterate over it
|
||||||
const internal = await games.locator('.item-card__action:has([data-a-target="FGWPOffer"])').elementHandles();
|
const internal = await games.locator('.item-card__action:has([data-a-target="FGWPOffer"])').elementHandles();
|
||||||
|
|
@ -324,8 +337,7 @@ try {
|
||||||
if (notify_games.length) { // make screenshot of all games if something was claimed
|
if (notify_games.length) { // make screenshot of all games if something was claimed
|
||||||
const p = screenshot(`${filenamify(datetime())}.png`);
|
const p = screenshot(`${filenamify(datetime())}.png`);
|
||||||
// await page.screenshot({ path: p, fullPage: true }); // fullPage does not make a difference since scroll not on body but on some element
|
// await page.screenshot({ path: p, fullPage: true }); // fullPage does not make a difference since scroll not on body but on some element
|
||||||
await page.keyboard.press('End'); // scroll to bottom to show all games
|
await scrollUntilStable(() => games.locator('.item-card__action').count());
|
||||||
await page.waitForTimeout(1000); // wait for fade in animation
|
|
||||||
const viewportSize = page.viewportSize(); // current viewport size
|
const viewportSize = page.viewportSize(); // current viewport size
|
||||||
await page.setViewportSize({ ...viewportSize, height: 3000 }); // increase height, otherwise element screenshot is cut off at the top and bottom
|
await page.setViewportSize({ ...viewportSize, height: 3000 }); // increase height, otherwise element screenshot is cut off at the top and bottom
|
||||||
await games.screenshot({ path: p }); // screenshot of all claimed games
|
await games.screenshot({ path: p }); // screenshot of all claimed games
|
||||||
|
|
@ -339,17 +351,7 @@ try {
|
||||||
await loot.waitFor();
|
await loot.waitFor();
|
||||||
|
|
||||||
process.stdout.write('Loading all DLCs on page...');
|
process.stdout.write('Loading all DLCs on page...');
|
||||||
let n1 = 0;
|
scrollUntilStable(() => loot.locator('[data-a-target="item-card"]').count())
|
||||||
let n2 = 0;
|
|
||||||
do {
|
|
||||||
n1 = n2;
|
|
||||||
n2 = await loot.locator('[data-a-target="item-card"]').count();
|
|
||||||
// console.log(n2);
|
|
||||||
process.stdout.write(` ${n2}`);
|
|
||||||
await page.keyboard.press('End'); // scroll to bottom to show all dlcs
|
|
||||||
await page.waitForLoadState('networkidle'); // did not wait for dlcs to be loaded
|
|
||||||
await page.waitForTimeout(1000);
|
|
||||||
} while (n2 > n1);
|
|
||||||
|
|
||||||
console.log('\nNumber of already claimed DLC:', await loot.locator('p:has-text("Collected")').count());
|
console.log('\nNumber of already claimed DLC:', await loot.locator('p:has-text("Collected")').count());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue