我如何从opentest中的文本文件中读取数据

How can i read data from a text file in opentest

我尝试了下面的代码,但它抛出了一个错误

Caused by: :1 ReferenceError: "require" is not defined

              fs.readFile('test.txt', 'utf-8',function(err,data){
                  if (err) {
                      return  $log(err);
                    }
                    $log(data);
              })

您正在尝试使用 Node.js API,它在 OpenTest 中不可用。读取文本文件的正确方法是使用 ReadTextFile 关键字:

- description: Read text file from disk
  action: org.getopentest.actions.files.ReadTextFile
  args:
    file: $tempDir + "/test.txt"
    encoding: UTF-8

- script: |
    var fileContents = $output.text;
    $log(fileContents)