Puppeteer 란
Puppetheer는 DevTools Protocol을 통해 Chrome/Chromium을 제어하는 API를 제공하는 Node.js Library
설치
npm i puppeteer or yarn add puppeteer
Puppeteer-core도 있지만, puppeteer-core는 내부 Chrome을 사용해야 함으로, 따라서 설치된 외부 Chromium 브라우저와 연결하여 사용해야 한다.
Example
import puppeteer from 'puppeteer';
(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Navigate the page to a URL
await page.goto('https://developer.chrome.com/');
// Set screen size
await page.setViewport({width: 1080, height: 1024});
// Type into search box
await page.type('.search-box__input', 'automate beyond recorder');
// Wait and click on first result
const searchResultSelector = '.search-box__link';
await page.waitForSelector(searchResultSelector);
await page.click(searchResultSelector);
// Locate the full title with a unique string
const textSelector = await page.waitForSelector(
'text/Customize and automate'
);
const fullTitle = await textSelector?.evaluate(el => el.textContent);
// Print the full title
console.log('The title of this blog post is "%s".', fullTitle);
await browser.close();
})();
E2E 테스팅을 Puppeer로 사용을 하는 곳이 많은 것 같은데, 아마 chrome 브라우져의 점유율도 그렇고 puppeteer에서 제어할 수 있는게 많다 보니 그렇게 쓰는거 같다.
https://ui.toast.com/posts/ko_20200630
Puppeteer로 E2E 테스트하기 팁 - Puppeteer와 함께 속도 높이기!
자바스크립트 세계에서 E2E 테스트는 신나는 한 때를 보내고 있다. 지난 몇 년 동안, 자바스크립트 커뮤니티에서 cypress와 Puppeteer와 같은 도구들이 쏟아져나왔고 빠르게 채택되어 왔다. 오늘은 Pup
ui.toast.com
나중에 시간 되면 puppeteer를 간단하게 제어한번 해봐야겠다.
728x90
'Programming > puppeteer' 카테고리의 다른 글
exposeFunction (0) | 2024.07.09 |
---|---|
Crawling (0) | 2024.05.04 |