Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
updated test for utils.puppeteer.saveSnapshot
metalwarrior66539068a446402
diff --git a/test/puppeteer_utils.js b/test/puppeteer_utils.jsindex 8247524f8..f9af2260e 100644--- a/test/puppeteer_utils.js+++ b/test/puppeteer_utils.js@@ -1,6 +1,8 @@import { expect } from 'chai';+import sinon from 'sinon';import path from 'path';import Apify from '../build/index';+import * as keyValueStore from '../build/key_value_store';const { utils: { log } } = Apify;@@ -374,4 +376,44 @@ describe('Apify.utils.puppeteer', () => {await browser.close();}});+++ it('saveSnapshot() works', async () => {+ const mock = sinon.mock(keyValueStore);+ const browser = await Apify.launchPuppeteer({ headless: true });+ try {+ const page = await browser.newPage();+ let count = 0;+ const content = Array(10).fill(null).map(() => {+ return `<div style="border: 1px solid black">Div number: ${count++}</div>`;+ });+ const contentHTML = `<html><head></head><body>${content}</body></html>`;+ await page.setContent(contentHTML);++ const screenshot = await page.screenshot({ fullPage: true });++ mock.expects('setValue')+ .once()+ .withArgs('TEST.png', screenshot, { contentType: 'image/png' })+ .returns(Promise.resolve());++ mock.expects('setValue')+ .once()+ .withArgs('TEST.html', contentHTML, { contentType: 'text/html' })+ .returns(Promise.resolve());++ await Apify.utils.puppeteer.saveSnapshot(page, 'TEST');++ mock.expects('setValue')+ .once()+ .withArgs('TEST.png', screenshot, { contentType: 'image/png' })+ .returns(Promise.resolve());++ await Apify.utils.puppeteer.saveSnapshot(page, 'TEST', { saveHtml: false });++ mock.verify();+ } finally {+ await browser.close();+ }+ });});