CodeceptJS
CodeceptJS copied to clipboard
Filesystem helper handleDownloads and amInPath can't be used when file path is outside codecept_dir
What are you trying to achieve?
Use Filesystem helper with:
- CodeceptJS output directory set at the root of my local disk (e.g. "c:\tests\output")
- setting I.amInPath(process.env.TEST_OUTPUT_DIRECTORY) => TEST_OUTPUT_DIRECTORY = CodeceptJS output directory
What do you get instead?
file (printable1.png) still not present in directory C:\Projects\foo\bar\Frontend\tests\output after 15 sec
In other words: my project directory.
const fileName = `printable${i}.png`
await I.handleDownloads(fileName)
I.click(buttonsLocator.at(i))
I.amInPath(process.env.TEST_OUTPUT_DIRECTORY)
await I.waitForFile(fileName, 15)
Details
- CodeceptJS version: 3.3.5
- NodeJS Version: v16.17.0
- Operating System: Windows 11 Pro
- playwright
- Configuration file:
require('ts-node/register')
const { setHeadlessWhen } = require('@codeceptjs/configure')
// turn on headless mode when running with HEADLESS=true environment variable
// HEADLESS=true npx codecept run
setHeadlessWhen(process.env.TEST_HEADLESS === 'true')
exports.config = {
tests: './tests/*/**_test.ts',
output: process.env.TEST_OUTPUT_DIRECTORY,
timeout: 240, // limit all tests in all suites to 240 secs
helpers: {
Playwright: {
browser: 'chromium',
show: false,
url: process.env.TEST_FRONTEND_URL,
video: process.env.TEST_VIDEO === 'true',
trace: true,
// keepTraceForPassedTests: true,
waitForAction: 2000,
waitForTimeout: 30000,
windowSize: '1800x920',
},
GraphQL: {
endpoint: process.env.GRAPHQL_API_SECURE_URL,
timeout: 30000,
},
JSONResponse: {
requestHelper: 'GraphQL',
},
FileSystem: {},
},
mocha: { bail: true },
bootstrapAll: require('./presettings.ts').bootstrapAll,
bootstrap: require('./presettings.ts').bootstrap,
teardownAll: require('./presettings').teardownAll,
teardown: require('./presettings').teardown,
plugins: {
subtitles: {
enabled: true,
},
pauseOnFail: {},
retryFailedStep: {
enabled: true,
},
tryTo: {
enabled: true,
},
screenshotOnFail: {
enabled: true,
},
// coverage: {
// enabled: true,
// },
},
}
pre-analysis
This would be due to this code in the method handleDownloads:
const downloadPath = path.join(global.output_dir, fileName || path.basename(filePath));
While the method amInPath takes the global codecept dir:
this.dir = path.join(global.codecept_dir, openPath);