I'm implementing a web-scraping script for a website which will collect some useful information.
Script is implemented using Puppeteer library and is basically a set of instructions like:
- Start a headless chrome
- Open new tab/page
- Get some pagination links from the HTML
- Open every pagination link found and scrape some information from HTML
I'm looking for some way of testing this functionality. Ideally, what I want to do is to "pre-save" the real HTML responses in test folder and then mock the external website responses (making sure they always are the same). And then assert that collected information is correct.
I'm familiar with several tools which are able to mock endpoints for fetch
function in the browser. I'm looking for something similar but for Puppeteer
.
So far, the only solution I'm thinking about is to use browser
instance as a dependency for my script. And then mock the newPage
method of the browser to return a page with custom interceptor. This looks like a lot of work though.
Any other solution for this?