How can I get puppeteer objects from within a test?

Viewed 102

I am writing tests using SAPUI5, Opa5, and karma. I'm trying to add the ability to take screenshots from a test, so I looked into puppeteer. I added this to my karma.conf.js file:

process.env.CHROME_BIN = require( 'puppeteer' ).executablePath();
config.customLaunchers = {
    'ChromeHeadlessNoSandbox': {
        base: 'ChromeHeadless',
        flags: [ '--no-sandbox' ]
    }
};
config.browsers = [ 'ChromeHeadlessNoSandbox' ];

The tests now run through headless Chrome. I'd like to use the page.screenshot function in one of my tests, but to do that I need a page object. The docs tell you to get the browser object from puppeteer.launch (and then create the page from there) but I'm not calling that directly, karma is doing that for me. The test has already created and rendered the page, so I don't need to create anything, I just want a Page object that refers to the current page. How can I get that?

0 Answers
Related