Skip to content

Commit baa87d0

Browse files
committed
resolve the path in filename
1 parent 6cdf288 commit baa87d0

File tree

10 files changed

+17
-108
lines changed

10 files changed

+17
-108
lines changed

docs/helpers/Playwright.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,30 +1817,11 @@ Optionally resize the window to the full available page `scrollHeight` and `scro
18171817
```js
18181818
I.saveScreenshot('debug.png')
18191819
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
1820+
I.saveScreenshot('customFolder/debug.png') //saves to customFolder/debug.png
18201821
```
18211822

18221823
#### Parameters
18231824

1824-
- `fileName` **[string][9]** file name to save.
1825-
- `fullPage` **[boolean][26]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
1826-
- `customPath` **[string][9]** (optional, `''` by default) custom path to save file.
1827-
1828-
Returns **void** automatically synchronized promise through #recorder
1829-
1830-
### saveScreenshotToPath
1831-
1832-
Saves a screenshot to custom folder (set in codecept.conf.ts or codecept.conf.js).
1833-
Filename is relative to custom folder.
1834-
Optionally resize the window to the full available page `scrollHeight` and `scrollWidth` to capture the entire page by passing `true` in as the second argument.
1835-
1836-
```js
1837-
I.saveScreenshotToPath('output/custom', 'debug.png')
1838-
I.saveScreenshotToPath('output/custom', 'debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
1839-
```
1840-
1841-
#### Parameters
1842-
1843-
- `path` **[string][9]** custom path to save file.
18441825
- `fileName` **[string][9]** file name to save.
18451826
- `fullPage` **[boolean][26]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
18461827

docs/helpers/Puppeteer.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,30 +1539,11 @@ Optionally resize the window to the full available page `scrollHeight` and `scro
15391539
```js
15401540
I.saveScreenshot('debug.png')
15411541
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
1542+
I.saveScreenshot('customFolder/debug.png') //saves to customFolder/debug.png
15421543
```
15431544
15441545
#### Parameters
15451546
1546-
- `fileName` **[string][6]** file name to save.
1547-
- `fullPage` **[boolean][23]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
1548-
- `customPath` **[string][6]** (optional, `''` by default) custom path to save file.
1549-
1550-
Returns **void** automatically synchronized promise through #recorder
1551-
1552-
### saveScreenshotToPath
1553-
1554-
Saves a screenshot to custom folder (set in codecept.conf.ts or codecept.conf.js).
1555-
Filename is relative to custom folder.
1556-
Optionally resize the window to the full available page `scrollHeight` and `scrollWidth` to capture the entire page by passing `true` in as the second argument.
1557-
1558-
```js
1559-
I.saveScreenshotToPath('output/custom', 'debug.png')
1560-
I.saveScreenshotToPath('output/custom', 'debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
1561-
```
1562-
1563-
#### Parameters
1564-
1565-
- `path` **[string][6]** custom path to save file.
15661547
- `fileName` **[string][6]** file name to save.
15671548
- `fullPage` **[boolean][23]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
15681549

docs/helpers/WebDriver.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,30 +1659,11 @@ Optionally resize the window to the full available page `scrollHeight` and `scro
16591659
```js
16601660
I.saveScreenshot('debug.png')
16611661
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
1662+
I.saveScreenshot('customFolder/debug.png') //saves to customFolder/debug.png
16621663
```
16631664
16641665
#### Parameters
16651666
1666-
- `fileName` **[string][18]** file name to save.
1667-
- `fullPage` **[boolean][33]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
1668-
- `customPath` **[string][18]** (optional, `''` by default) custom path to save file.
1669-
1670-
Returns **void** automatically synchronized promise through #recorder
1671-
1672-
### saveScreenshotToPath
1673-
1674-
Saves a screenshot to custom folder (set in codecept.conf.ts or codecept.conf.js).
1675-
Filename is relative to custom folder.
1676-
Optionally resize the window to the full available page `scrollHeight` and `scrollWidth` to capture the entire page by passing `true` in as the second argument.
1677-
1678-
```js
1679-
I.saveScreenshotToPath('output/custom', 'debug.png')
1680-
I.saveScreenshotToPath('output/custom', 'debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
1681-
```
1682-
1683-
#### Parameters
1684-
1685-
- `path` **[string][18]** custom path to save file.
16861667
- `fileName` **[string][18]** file name to save.
16871668
- `fullPage` **[boolean][33]** (optional, `false` by default) flag to enable fullscreen screenshot mode.
16881669

docs/webapi/saveScreenshot.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Optionally resize the window to the full available page `scrollHeight` and `scro
55
```js
66
I.saveScreenshot('debug.png');
77
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
8+
I.saveScreenshot('customFolder/debug.png') //saves to customFolder/debug.png
89
```
910

1011
@param {string} fileName file name to save.
1112
@param {boolean} [fullPage=false] (optional, `false` by default) flag to enable fullscreen screenshot mode.
12-
@param {string} [customPath=''] (optional, `''` by default) custom path to save file.
1313
@returns {void} automatically synchronized promise through #recorder

docs/webapi/saveScreenshotToPath.mustache

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/helper/Playwright.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,9 +2500,9 @@ class Playwright extends Helper {
25002500
/**
25012501
* {{> saveScreenshot }}
25022502
*/
2503-
async saveScreenshot(fileName, fullPage, customPath = '') {
2503+
async saveScreenshot(fileName, fullPage) {
25042504
const fullPageOption = fullPage || this.options.fullPageScreenshots
2505-
let outputFile = screenshotOutputFolder(fileName, customPath)
2505+
let outputFile = screenshotOutputFolder(fileName)
25062506

25072507
this.debugSection('Screenshot', relativeDir(outputFile))
25082508

@@ -2515,7 +2515,7 @@ class Playwright extends Helper {
25152515
if (this.activeSessionName) {
25162516
for (const sessionName in this.sessionPages) {
25172517
const activeSessionPage = this.sessionPages[sessionName]
2518-
outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`, customPath)
2518+
outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`)
25192519

25202520
this.debugSection('Screenshot', `${sessionName} - ${relativeDir(outputFile)}`)
25212521

@@ -2530,13 +2530,6 @@ class Playwright extends Helper {
25302530
}
25312531
}
25322532

2533-
/**
2534-
* {{> saveScreenshotToPath }}
2535-
*/
2536-
async saveScreenshotToPath(path, fileName = '', fullPage) {
2537-
return this.saveScreenshot(fileName, fullPage, path)
2538-
}
2539-
25402533
/**
25412534
* Performs [api request](https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get) using
25422535
* the cookies from the current browser session.

lib/helper/Puppeteer.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,9 +1992,9 @@ class Puppeteer extends Helper {
19921992
/**
19931993
* {{> saveScreenshot }}
19941994
*/
1995-
async saveScreenshot(fileName, fullPage, customPath = '') {
1995+
async saveScreenshot(fileName, fullPage) {
19961996
const fullPageOption = fullPage || this.options.fullPageScreenshots
1997-
let outputFile = screenshotOutputFolder(fileName, customPath)
1997+
let outputFile = screenshotOutputFolder(fileName)
19981998

19991999
this.debug(`Screenshot is saving to ${outputFile}`)
20002000

@@ -2007,7 +2007,7 @@ class Puppeteer extends Helper {
20072007
if (this.activeSessionName) {
20082008
for (const sessionName in this.sessionPages) {
20092009
const activeSessionPage = this.sessionPages[sessionName]
2010-
outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`, customPath)
2010+
outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`)
20112011

20122012
this.debug(`${sessionName} - Screenshot is saving to ${outputFile}`)
20132013

@@ -2022,13 +2022,6 @@ class Puppeteer extends Helper {
20222022
}
20232023
}
20242024

2025-
/**
2026-
* {{> saveScreenshotToPath }}
2027-
*/
2028-
async saveScreenshotToPath(path, fileName = '', fullPage) {
2029-
return this.saveScreenshot(fileName, fullPage, path)
2030-
}
2031-
20322025
async _failed(test) {
20332026
await this._withinEnd()
20342027

lib/helper/WebDriver.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,15 +1798,15 @@ class WebDriver extends Helper {
17981798
/**
17991799
* {{> saveScreenshot }}
18001800
*/
1801-
async saveScreenshot(fileName, fullPage = false, customPath = '') {
1802-
let outputFile = screenshotOutputFolder(fileName, customPath)
1801+
async saveScreenshot(fileName, fullPage = false) {
1802+
let outputFile = screenshotOutputFolder(fileName)
18031803

18041804
if (this.activeSessionName) {
18051805
const browser = this.sessionWindows[this.activeSessionName]
18061806

18071807
for (const sessionName in this.sessionWindows) {
18081808
const activeSessionPage = this.sessionWindows[sessionName]
1809-
outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`, customPath)
1809+
outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`)
18101810

18111811
this.debug(`${sessionName} - Screenshot is saving to ${outputFile}`)
18121812

@@ -1849,13 +1849,6 @@ class WebDriver extends Helper {
18491849
return buffer
18501850
}
18511851

1852-
/**
1853-
* {{> saveScreenshotToPath }}
1854-
*/
1855-
async saveScreenshotToPath(path, fileName = '', fullPage) {
1856-
return this.saveScreenshot(fileName, fullPage, path)
1857-
}
1858-
18591852
/**
18601853
* Uses Selenium's JSON [cookie format](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object).
18611854
* {{> setCookie }}

lib/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ module.exports.deleteDir = function (dir_path) {
311311
* Returns absolute filename to save screenshot.
312312
* @param fileName {string} - filename.
313313
*/
314-
module.exports.screenshotOutputFolder = function (fileName, customPath = '') {
314+
module.exports.screenshotOutputFolder = function (fileName) {
315315
const fileSep = path.sep
316316

317-
if (customPath.includes(fileSep)) {
318-
return path.resolve(customPath, fileName)
317+
if (fileName.includes(fileSep) && !(fileName.includes(global.output_dir) || fileName.includes(global.codecept_dir))) {
318+
return path.resolve(fileName)
319319
}
320320

321321
if (!fileName.includes(fileSep) || fileName.includes('record_')) {

test/unit/utils_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ describe('utils', () => {
330330
})
331331

332332
it('saves screenshot to custom path', () => {
333-
const _path = utils.screenshotOutputFolder('screenshot1.failed.png', '/Users/someuser/workbase/project1/custom_path/'.replace(/\//g, path.sep))
333+
const _path = utils.screenshotOutputFolder('/Users/someuser/workbase/project1/custom_path/'.replace(/\//g, path.sep) + 'screenshot1.failed.png')
334334
if (os.platform() === 'win32') {
335335
expect(_path).eql(path.resolve(global.codecept_dir, '/Users/someuser/workbase/project1/custom_path/screenshot1.failed.png'))
336336
} else {

0 commit comments

Comments
 (0)