AVA + Puppeteer 샘플 레시피를 기반으로 ignoreHTTPSErrors 지정

ava/header\.png at master · avajs/ava · GitHub

GitHub - avajs/ava: 🚀 Testing can be a drag. AVA helps you get it done.

왠지 약간의 테스트에 Puppeteer 사용할 수 있는 손쉬운 프레임워크 없을까라고 생각해 조금 구그해 보면 AVA

Recipes
  • Testing web apps using Puppeteer

  • helpers/withPage in recipe



    과연 이야기가 빠르다

    The first step is setting up a helper to configure the environment:

    helpers/withPage.js
    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();
        }
    }
    

    ava/puppeteer.md at master · avajs/ava · GitHub

    즉시 서버 인증서에 걸린다.



    고맙지만 곤란하다.

    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.js
    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();
        }
    }
    

    main.js
    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
    

    more 🐤

    좋은 웹페이지 즐겨찾기