MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / saveScreenshot

Method saveScreenshot

lib/helper/WebDriver.js:1998–2047  ·  view source on GitHub ↗

* {{> saveScreenshot }}

(fileName, fullPage = false)

Source from the content-addressed store, hash-verified

1996 * {{> saveScreenshot }}
1997 */
1998 async saveScreenshot(fileName, fullPage = false) {
1999 let outputFile = screenshotOutputFolder(fileName)
2000
2001 if (this.activeSessionName) {
2002 const browser = this.sessionWindows[this.activeSessionName]
2003
2004 for (const sessionName in this.sessionWindows) {
2005 const activeSessionPage = this.sessionWindows[sessionName]
2006 outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`)
2007
2008 this.debug(`${sessionName} - Screenshot is saving to ${outputFile}`)
2009
2010 if (browser) {
2011 this.debug(`Screenshot of ${sessionName} session has been saved to ${outputFile}`)
2012 await browser.saveScreenshot(outputFile)
2013 }
2014 }
2015 }
2016
2017 if (!fullPage) {
2018 this.debug(`Screenshot has been saved to ${outputFile}`)
2019 await this.browser.saveScreenshot(outputFile)
2020 }
2021
2022 const originalWindowSize = await this.browser.getWindowSize()
2023
2024 // this case running on device, so we could not set the windowSize
2025 if (this.browser.isMobile) {
2026 this.debug(`Screenshot has been saved to ${outputFile}, size: ${originalWindowSize.width}x${originalWindowSize.height}`)
2027 const buffer = await this.browser.saveScreenshot(outputFile)
2028 return buffer
2029 }
2030
2031 let { width, height } = await this.browser
2032 .execute(function () {
2033 return {
2034 height: document.body.scrollHeight,
2035 width: document.body.scrollWidth,
2036 }
2037 })
2038 .then(res => res)
2039
2040 if (height < 100) height = 500 // errors for very small height
2041
2042 await this.browser.setWindowSize(width, height)
2043 this.debug(`Screenshot has been saved to ${outputFile}, size: ${width}x${height}`)
2044 const buffer = await this.browser.saveScreenshot(outputFile)
2045 await this.browser.setWindowSize(originalWindowSize.width, originalWindowSize.height)
2046 return buffer
2047 }
2048
2049 /**
2050 * Uses Selenium's JSON [cookie format](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).

Callers 1

saveElementScreenshotMethod · 0.45

Calls 2

screenshotOutputFolderFunction · 0.90
debugMethod · 0.80

Tested by

no test coverage detected