I am using browser.saveDocumentScreenshot('folder/filename.png') I am getting error as browser.saveDocumentScreenshot is not a function
1 Answer
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() }) }) 6 Comments
Anjani Kumar
In here, npmjs.com/package/wdio-screenshot , there are are commands like browser.saveDocumentScreenshot([fileName], [{options}]); , what about them? Are they no longer supported or removed?
Mike G.
newBike
your solution is not working with wdio6.... the session just close imediately.
Mike G.
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.
Anyway, "something is not working" is not informative at all.
|