K
K
Kyon13372021-05-26 11:43:44
JavaScript
Kyon1337, 2021-05-26 11:43:44

How to report as a screenshot while testing on node.js?

Hello! Interested in testing web applications. I would like to automatically take a screenshot of the action in some folder when starting the autotest. I use node.js and mocha testrunner. I read that mocha can take screenshots, but how? Thanks in advance for your reply!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Shcherbina, 2021-05-26
@Kyon1337

Puppeteer will help you - this is a "console browser" that, through js, performs the actions you need on the page:
https://www.npmjs.com/package/puppeteer
here's how to go to the site and take a screenshot using this technology:

const puppeteer = require('puppeteer');

test();

async function test() {
 const browser = await puppeteer.launch({
    headless: true,
    args :[
      '--no-sandbox'
    ]
  });

 const page = await browser.newPage();
  await page.setViewport({
    width: 1366,
    height: 768,
    deviceScaleFactor: 1,
  });
  await page.goto('https://ваш-сайт.ру', {
    waitUntil: 'networkidle2'
  })
 await page.waitForTimeout(1000);
 await page.screenshot({ path: 'example.png' });
 await browser.close();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question