How can i read data from a text file in opentest

166 Views Asked by At

I tried the below code but it throws an error that

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

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

There are 1 best solutions below

0
On BEST ANSWER

You are trying to use the Node.js API, which is not available in OpenTest. The proper way to read a text file is by using the ReadTextFile keyword:

- 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)