Home Ask Login Register

Developers Planet

Your answer is one click away!

Idan E February 2016

Node.JS - How to perform verfication on a dynamic file name in JS?

I've tried to used in "split()" in order to ignore the dynamic string inside the file name and to perform verification only on the fixed value "Schedule" and then to return the response for to pass the test.

describe('Frontage - Calendar test cases', function() {

    var fs = require('fs');
    var splitFileName = "Schedule"
    var filename = 'c:\\automation\\tests\\downloaded\\' + splitFileName.split();

    it('New App - Calendar - Print calendar', function(){
       browser.driver.wait(function() {
          return fs.existsSync(filename);
       }, 30000);



  1) Test cases pull - Frontage Sanity Testing  Frontage - Calendar test cases New App - Calendar - Print calendar
     Error: Wait timed out after 30000ms
     Error: Wait timed out after 30000ms
    at C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1630:20
    at [object Object].promise.ControlFlow.runInFrame_ (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20)
    at [object Object].promise.Callback_.goog.defineClass.notify (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2464:25)
    at [object Object].promise.Promise.notify_ (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:563:12)
    at Array.forEach (native)
    at Object.goog.array.forEach (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\array\array.js:203:43)
    at [object Object].promise.Promise.notifyAll_ (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:552:16)
    at goog.async.run.processWorkQueue (C:\automation\npm\node_modules\protractor\n        


martin770 February 2016

You can use fs.readdir to get all the filenames, and then check them with a regular expression against the thing you are trying to match.

it('New App - Calendar - Print calendar', function(){
   browser.driver.wait(function() {
      var filepath = 'c:\\automation\\tests\\downloaded\\';
      var matcher = /Schedule/;
      var foundFile = false;
      fs.readdirSync(filepath).forEach(function(filename) {
          if (matcher.test(filename)) {
             foundFile = true;
       return foundFile;
   }, 30000);

Post Status

Asked in February 2016
Viewed 1,490 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life