Reputation: 125
I have a project folder structure as below:
tests
- features
- payloads
- request
-JSONRequest (create-req.json file is present inside this folder)
-XMLRequest (sample-req.xml file is present inside this folder)
I have to print complete PATH based on finding the create-req.json file
I have created a variable named as requestDataPath which stores path upto 'request' structure. And I am picking my json request based on the value passed as argument. And I am trying to print complete path based on the folder the file is present.
let path = require('path');
let requestDataPath = path.resolve('tests/payloads/request/../');
let requestBodyPath = requestDataPath + '/' + 'create' + '-req.json';
console.log('Path is-->' + requestBody);
Actual Result: /Users/pranaytgupta/Documents/pranay/api-automation-framework/tests/payloads/request/create-req.json
Expected Result: /Users/pranaytgupta/Documents/pranay/api-automation-framework/tests/payloads/request/JSONRequest/create-req.json
Upvotes: 0
Views: 50
Reputation: 219
If you are running this from you main directory, try:
const path = `${__dirname}/tests/payloads/request/JSONRequest/create-req.json`
console.log('path is -->', path);
Upvotes: 1