Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ website
.idea
docs/build
test/data/output
test/data/custom
test/acceptance/output
test/bdd/output
examples/output
Expand All @@ -26,4 +27,4 @@ package-lock.json
yarn.lock
/.vs
typings/types.d.ts
typings/promiseBasedTypes.d.ts
typings/promiseBasedTypes.d.ts
2 changes: 1 addition & 1 deletion docs/helpers/Appium.md
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ Returns **[Promise][6]<[string][5]>** attribute value

### saveScreenshot

Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves a screenshot to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.

```js
Expand Down
4 changes: 2 additions & 2 deletions docs/helpers/Nightmare.md
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ Returns **void** automatically synchronized promise through #recorder

### saveElementScreenshot

Saves screenshot of the specified locator to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves screenshot of the specified locator to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.

```js
Expand All @@ -810,7 +810,7 @@ Returns **void** automatically synchronized promise through #recorder

### saveScreenshot

Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves a screenshot to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.
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.

Expand Down
5 changes: 3 additions & 2 deletions docs/helpers/Playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,7 @@ Returns **void** automatically synchronized promise through #recorder

### saveElementScreenshot

Saves screenshot of the specified locator to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves screenshot of the specified locator to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.

```js
Expand All @@ -1815,13 +1815,14 @@ Returns **void** automatically synchronized promise through #recorder

### saveScreenshot

Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves a screenshot to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.
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.

```js
I.saveScreenshot('debug.png');
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
I.saveScreenshot('customFolder/debug.png') //saves to customFolder/debug.png
```

#### Parameters
Expand Down
4 changes: 2 additions & 2 deletions docs/helpers/Protractor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ Returns **void** automatically synchronized promise through #recorder

### saveElementScreenshot

Saves screenshot of the specified locator to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves screenshot of the specified locator to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.

```js
Expand All @@ -1052,7 +1052,7 @@ Returns **void** automatically synchronized promise through #recorder

### saveScreenshot

Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves a screenshot to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.
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.

Expand Down
5 changes: 3 additions & 2 deletions docs/helpers/Puppeteer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ This action supports [React locators](https://codecept.io/react#locators)

### saveElementScreenshot

Saves screenshot of the specified locator to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves screenshot of the specified locator to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.

```js
Expand All @@ -1583,13 +1583,14 @@ Returns **void** automatically synchronized promise through #recorder

### saveScreenshot

Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves a screenshot to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.
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.

```js
I.saveScreenshot('debug.png');
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
I.saveScreenshot('customFolder/debug.png') //saves to customFolder/debug.png
```

#### Parameters
Expand Down
5 changes: 3 additions & 2 deletions docs/helpers/TestCafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ Returns **void** automatically synchronized promise through #recorder

### saveElementScreenshot

Saves screenshot of the specified locator to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves screenshot of the specified locator to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.

```js
Expand All @@ -782,13 +782,14 @@ Returns **void** automatically synchronized promise through #recorder

### saveScreenshot

Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves a screenshot to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.
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.

```js
I.saveScreenshot('debug.png');
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
I.saveScreenshot('customFolder/debug.png') //saves to customFolder/debug.png
```

#### Parameters
Expand Down
5 changes: 3 additions & 2 deletions docs/helpers/WebDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ Placeholder for ~ locator only test case write once run on both Appium and WebDr

### saveElementScreenshot

Saves screenshot of the specified locator to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves screenshot of the specified locator to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.

```js
Expand All @@ -1673,13 +1673,14 @@ Returns **void** automatically synchronized promise through #recorder

### saveScreenshot

Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves a screenshot to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.
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.

```js
I.saveScreenshot('debug.png');
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
I.saveScreenshot('customFolder/debug.png') //saves to customFolder/debug.png
```

#### Parameters
Expand Down
2 changes: 1 addition & 1 deletion docs/webapi/saveElementScreenshot.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Saves screenshot of the specified locator to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves screenshot of the specified locator to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.

```js
Expand Down
3 changes: 2 additions & 1 deletion docs/webapi/saveScreenshot.mustache
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
Saves a screenshot to output folder (set in codecept.conf.ts or codecept.conf.js).
Filename is relative to output folder.
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.

```js
I.saveScreenshot('debug.png');
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
I.saveScreenshot('customFolder/debug.png') //saves to customFolder/debug.png
```

@param {string} fileName file name to save.
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/Appium.js
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ class Appium extends Webdriver {
}

/**
* Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js).
* Saves a screenshot to output folder (set in codecept.conf.ts or codecept.conf.js).
* Filename is relative to output folder.
*
* ```js
Expand Down
8 changes: 6 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,13 @@ module.exports.deleteDir = function (dir_path) {
* @param fileName {string} - filename.
*/
module.exports.screenshotOutputFolder = function (fileName) {
const fileSep = path.sep
const isPathLike = fileName.includes('/') || fileName.includes('\\')

if (!fileName.includes(fileSep) || fileName.includes('record_')) {
if (isPathLike && !(fileName.includes(global.output_dir) || fileName.includes(global.codecept_dir))) {
return path.resolve(fileName)
}

if (!isPathLike || fileName.includes('record_')) {
return path.resolve(global.output_dir, fileName)
}
return path.resolve(global.codecept_dir, fileName)
Expand Down
4 changes: 2 additions & 2 deletions runok.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Our community prepared some valuable recipes for setting up CI systems with Code
// generate documentation for helpers
const files = fs.readdirSync('lib/helper').filter(f => path.extname(f) === '.js')

const ignoreList = ['Polly', 'MockRequest'] // WebDriverIO won't be documented and should be removed
const ignoreList = ['Polly', 'MockRequest', 'Nightmare', 'Protractor'] // WebDriverIO won't be documented and should be removed

const partials = fs.readdirSync('docs/webapi').filter(f => path.extname(f) === '.mustache')
const placeholders = partials.map(file => `{{> ${path.basename(file, '.mustache')} }}`)
Expand Down Expand Up @@ -587,7 +587,7 @@ const exec = require('child_process').exec
const { codecept_dir, codecept_run } = require('./consts')
const debug = require('debug')('codeceptjs:tests')

const config_run_config = (config, grep, verbose = false) =>
const config_run_config = (config, grep, verbose = false) =>
\`\${codecept_run} \${verbose ? '--verbose' : ''} --config \${codecept_dir}/configs/${featureName}/\${config} \${grep ? \`--grep "\${grep}"\` : ''}\`

describe('CodeceptJS ${featureName}', function () {
Expand Down
Empty file added test/data/custom/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions test/helper/webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ module.exports.tests = function () {
describe('#saveScreenshot', () => {
beforeEach(() => {
global.output_dir = path.join(global.codecept_dir, 'output')
global.custom_dir = path.join(global.codecept_dir, 'custom')
})

it('should create a screenshot file in output dir', async () => {
Expand All @@ -887,6 +888,15 @@ module.exports.tests = function () {
await I.saveScreenshot(`screenshot_full_${+sec}.png`, true)
assert.ok(fileExists(path.join(global.output_dir, `screenshot_full_${+sec}.png`)), null, 'file does not exists')
})

it('should create a screenshot file in custom dir', async () => {
if (isHelper('TestCafe')) return

const sec = new Date().getUTCMilliseconds()
await I.amOnPage('/')
await I.saveScreenshot(path.resolve(global.custom_dir, `screenshot_${sec}.png`))
assert.ok(fileExists(path.join(global.custom_dir, `screenshot_${sec}.png`)), null, 'file does not exists')
})
})

describe('cookies : #setCookie, #clearCookies, #seeCookie, #waitForCookie', () => {
Expand Down
15 changes: 11 additions & 4 deletions test/unit/utils_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
let expect
import('chai').then(chai => {
expect = chai.expect
})
const { expect } = require('chai')

const os = require('os')
const path = require('path')
const sinon = require('sinon')
Expand Down Expand Up @@ -330,6 +328,15 @@ describe('utils', () => {
expect(_path).eql('/Users/someuser/workbase/project1/test_output/screenshot1.failed.png')
}
})

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

describe('#requireWithFallback', () => {
Expand Down