1

I am using browser.saveDocumentScreenshot('folder/filename.png') I am getting error as browser.saveDocumentScreenshot is not a function

Anjani Kumar
  • 374
  • 1
  • 2
  • 17
  • I have used the accepted solution from this question, but it is not working. https://stackoverflow.com/questions/37055507/webdriverio-take-full-page-screenshot – Anjani Kumar Oct 07 '20 at 10:33

1 Answers1

2

If you want support of all browser and devices use https://github.com/wswebcreation/wdio-image-comparison-service

Alternately, with WebdriverIO 6 (maybe with 5 as well) it's possible to use Puppeteer commands. With Puppeteer, it's possible to take full-page screenshots, see https://github.com/puppeteer/puppeteer/blob/v5.3.1/docs/api.md#pagescreenshotoptions

// Mocha example
describe('Screenshot', () => {
    // replace with beforeAll in Jasmine!
    before(() => {
        // add command to reuse easily everywhere in the project
        // https://webdriver.io/docs/customcommands.html
        browser.addCommand('takeFullPageScreenshot', function (options = {}) {
            // Puppeteer commands should be wrapped with browser.call
            // because they return Promises
            // https://webdriver.io/docs/api/browser/call.html
            return browser.call(async () => {
                // https://webdriver.io/docs/api/browser/getPuppeteer.html
                const puppeteer = await browser.getPuppeteer()
                // now we interact with Puppeteer API
                // https://github.com/puppeteer/puppeteer/blob/v5.3.1/docs/api.md#browserpages
                const pages = await puppeteer.pages()

                // https://github.com/puppeteer/puppeteer/blob/v5.3.1/docs/api.md#pagescreenshotoptions
                return pages[0].screenshot({ ...options, fullPage: true })
            })
        })
    })

    it('should take full page screenshot', () => {
        browser.url('https://stackoverflow.com/questions/64242220/how-to-take-full-web-page-screenshot-using-webdriverio-command')

        // somehow wait for page to load
        expect($('.user-details')).toBeVisible()

        // take screenshot and save to file
        browser.takeFullPageScreenshot({ path: './screenshot.png' })

        // take screenshot but don't save to file
        const screenshot = browser.takeFullPageScreenshot()
    })
})
Mike G.
  • 3,512
  • 3
  • 14
  • 16
  • In here, https://www.npmjs.com/package/wdio-screenshot , there are are commands like browser.saveDocumentScreenshot([fileName], [{options}]); , what about them? Are they no longer supported or removed? – Anjani Kumar Oct 11 '20 at 09:20
  • Use https://github.com/wswebcreation/wdio-image-comparison-service instead – Mike G. Oct 11 '20 at 13:28
  • your solution is not working with wdio6.... the session just close imediately. – newBike Oct 28 '20 at 04:24
  • It's something with your setup, the example above can only work if you have @wdio/sync inatalled and browser running on same machine with Puppeteer support. – Mike G. Oct 28 '20 at 09:18
  • Anyway, "something is not working" is not informative at all. – Mike G. Oct 28 '20 at 09:19
  • This link https://www.npmjs.com/package/wdio-screenshot shows how to use three types of screenshots. browser.saveDocumentScreenshot([fileName], [{options}]), what is the correct way of writing filename and option while using the command? – Anjani Kumar Oct 28 '20 at 19:36