【问题标题】:Find file and print complete path查找文件并打印完整路径
【发布时间】:2019-05-13 22:25:02
【问题描述】:

我的项目文件夹结构如下:

tests
  - features
  - payloads
     - request
        -JSONRequest (create-req.json file is present inside this folder)
        -XMLRequest (sample-req.xml file is present inside this folder)

我必须根据找到的 create-req.json 文件打印完整的 PATH

我创建了一个名为 requestDataPath 的变量,它存储到“请求”结构的路径。我正在根据作为参数传递的值来选择我的 json 请求。我正在尝试根据文件所在的文件夹打印完整路径。

let path = require('path');
let requestDataPath = path.resolve('tests/payloads/request/../');

let requestBodyPath = requestDataPath + '/' + 'create' + '-req.json';

console.log('Path is-->' + requestBody);

实际结果:/Users/pranaytgupta/Documents/pranay/api-automation-framework/tests/payloads/request/create-req.json

预期结果:/Users/pranaytgupta/Documents/pranay/api-automation-framework/tests/payloads/request/JSONRequest/create-req.json

【问题讨论】:

  • 你的脚本存放在哪个文件夹?
  • 功能文件夹内--> step_definition(脚本在此)

标签: javascript filepath


【解决方案1】:

如果您是从主目录运行它,请尝试:

  const path = `${__dirname}/tests/payloads/request/JSONRequest/create-req.json`
  console.log('path is -->', path);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-30
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多