사용자 체감 속도 측정 도구/WebPageTest(웹페이지테스트)
WebPageTest API를 사용하여 로그인 후 여러 사이트 URL 속도 테스트하는 코드
프리스케이터
2024. 3. 14. 00:53
WebPageTest API를 사용하여 로그인 후 여러 사이트 URL 속도 테스트하는 코드
import WebPageTest from "webpagetest";
// 여기서 "www.webpagetest.org"는 WebPageTest API의 엔드포인트이며, "YOUR_API_KEY"는 실제 API 키로 대체되어야 합니다.
const wptServer = "https://www.webpagetest.org";
const wpt = new WebPageTest(wptServer, "YOUR_API_KEY");
const options = {
pollResults: 5,
firstViewOnly: true, //Skips the Repeat View test
location: "ec2-ap-northeast-2:Chrome",
connectivity: "Native",
};
// 로그인 후 특정 URL로 이동하는 스크립트를 생성하는 함수
const generateScript = (url) => {
return wpt.scriptToString([
{ logData: 0 },
{ navigate: "https://nid.naver.com/nidlogin.login" },
{ logData: 1 },
{ setValue: ["name=name", "test@naver.com"] },
{ setValue: ["name=pw", "YOUR_PW"] },
{ click: "type=submit" },
{ navigate: url },
"waitForComplete",
]);
};
// 테스트할 URL 목록
const urls = [
"https://section.blog.naver.com/",
"https://mail.naver.com",
// 나머지 URL들을 추가해주세요
];
// 각 URL에 대한 테스트를 실행하는 함수
const runTestForUrl = (url) => {
const script = generateScript(url);
wpt.runTest(script, options, (err, result) => {
if (result) {
console.log(result);
} else {
console.log(err);
}
});
};
// 모든 URL에 대해 테스트 실행
urls.forEach((url) => runTestForUrl(url));