AVA + Puppeteer 샘플 레시피를 기반으로 ignoreHTTPSErrors 지정
10526 단어 testHTTPSpuppeteercertificateava
GitHub - avajs/ava: 🚀 Testing can be a drag. AVA helps you get it done.
왠지 약간의 테스트에 Puppeteer 사용할 수 있는 손쉬운 프레임워크 없을까라고 생각해 조금 구그해 보면 AVA
Recipes
helpers/withPage in recipe
과연 이야기가 빠르다
The first step is setting up a helper to configure the environment:
helpers/withPage.jsimport puppeteer from 'puppeteer';
export default async function withPage(t, run) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
try {
await run(t, page);
} finally {
await page.close();
await browser.close();
}
}
ava/puppeteer.md at master · avajs/ava · GitHub
즉시 서버 인증서에 걸린다.
고맙지만 곤란하다.
main.jsimport test from 'ava';
import withPage from './helpers/withPage';
const url = `https://host/test`;
test('page title must be appear in "📓The Narrative"', withPage, async (t, page) => {
await page.goto(url);
t.is('🐥 VigilaNTe', await page.title());
}
);
✖ page title must be appear in "📓 The Narrative" Rejected promise returned by test
1 test failed
page title must be appear in "📓 The Narrative"
/path/to/node_modules/puppeteer/lib/FrameManager.js:107
Rejected promise returned by test. Reason:
Error {
message: 'net::ERR_CERT_AUTHORITY_INVALID at https://host/test',
}
navigate (node_modules/puppeteer/lib/FrameManager.js:107:37)
Frame.<anonymous> (node_modules/puppeteer/lib/helper.js:144:27)
Page.goto (node_modules/puppeteer/lib/Page.js:624:49)
Page.<anonymous> (node_modules/puppeteer/lib/helper.js:145:23)
goto (test/main.js:7:16)
Test.run (test/helpers/withPage.js:7:11)
puppeteer.launch([options]) 로 대응
우선 puppeteer.launch에서 대응하자
helpers/withPage.jsimport puppeteer from 'puppeteer';
export default async function withPage(t, run, puppeteer_launch_opts = {}) {
const browser = await puppeteer.launch(puppeteer_launch_opts);
const page = await browser.newPage();
try {
await run(t, page);
} finally {
await page.close();
await browser.close();
}
}
main.jsimport test from 'ava';
import withPage from './helpers/withPage';
const url = `https://host/test`;
const puppeteer_launch_opts =
{
ignoreHTTPSErrors: true
};
test('page title must be appear in "📓The Narrative"', withPage, async (t, page) => {
await page.goto(url);
t.is('🐥 VigilaNTe', await page.title());
}, puppeteer_launch_opts
);
✔ page title must be appear in "📓 The Narrative" (2.4s)
1 test passed
more 🐤
Reference
이 문제에 관하여(AVA + Puppeteer 샘플 레시피를 기반으로 ignoreHTTPSErrors 지정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/szf/items/3c927be79fcfa87032e7
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import puppeteer from 'puppeteer';
export default async function withPage(t, run) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
try {
await run(t, page);
} finally {
await page.close();
await browser.close();
}
}
고맙지만 곤란하다.
main.js
import test from 'ava';
import withPage from './helpers/withPage';
const url = `https://host/test`;
test('page title must be appear in "📓The Narrative"', withPage, async (t, page) => {
await page.goto(url);
t.is('🐥 VigilaNTe', await page.title());
}
);
✖ page title must be appear in "📓 The Narrative" Rejected promise returned by test
1 test failed
page title must be appear in "📓 The Narrative"
/path/to/node_modules/puppeteer/lib/FrameManager.js:107
Rejected promise returned by test. Reason:
Error {
message: 'net::ERR_CERT_AUTHORITY_INVALID at https://host/test',
}
navigate (node_modules/puppeteer/lib/FrameManager.js:107:37)
Frame.<anonymous> (node_modules/puppeteer/lib/helper.js:144:27)
Page.goto (node_modules/puppeteer/lib/Page.js:624:49)
Page.<anonymous> (node_modules/puppeteer/lib/helper.js:145:23)
goto (test/main.js:7:16)
Test.run (test/helpers/withPage.js:7:11)
puppeteer.launch([options]) 로 대응
우선 puppeteer.launch에서 대응하자
helpers/withPage.jsimport puppeteer from 'puppeteer';
export default async function withPage(t, run, puppeteer_launch_opts = {}) {
const browser = await puppeteer.launch(puppeteer_launch_opts);
const page = await browser.newPage();
try {
await run(t, page);
} finally {
await page.close();
await browser.close();
}
}
main.jsimport test from 'ava';
import withPage from './helpers/withPage';
const url = `https://host/test`;
const puppeteer_launch_opts =
{
ignoreHTTPSErrors: true
};
test('page title must be appear in "📓The Narrative"', withPage, async (t, page) => {
await page.goto(url);
t.is('🐥 VigilaNTe', await page.title());
}, puppeteer_launch_opts
);
✔ page title must be appear in "📓 The Narrative" (2.4s)
1 test passed
more 🐤
Reference
이 문제에 관하여(AVA + Puppeteer 샘플 레시피를 기반으로 ignoreHTTPSErrors 지정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/szf/items/3c927be79fcfa87032e7
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import puppeteer from 'puppeteer';
export default async function withPage(t, run, puppeteer_launch_opts = {}) {
const browser = await puppeteer.launch(puppeteer_launch_opts);
const page = await browser.newPage();
try {
await run(t, page);
} finally {
await page.close();
await browser.close();
}
}
import test from 'ava';
import withPage from './helpers/withPage';
const url = `https://host/test`;
const puppeteer_launch_opts =
{
ignoreHTTPSErrors: true
};
test('page title must be appear in "📓The Narrative"', withPage, async (t, page) => {
await page.goto(url);
t.is('🐥 VigilaNTe', await page.title());
}, puppeteer_launch_opts
);
✔ page title must be appear in "📓 The Narrative" (2.4s)
1 test passed
Reference
이 문제에 관하여(AVA + Puppeteer 샘플 레시피를 기반으로 ignoreHTTPSErrors 지정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/szf/items/3c927be79fcfa87032e7텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)