javascript - Node.JS - How to perform verfication on a dynamic file name in JS? -
i've tried used in "split()" in order ignore dynamic string inside file name , perform verification on fixed value "schedule" , return response pass 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(){ $$("button.font-xs.md-button.ng-scope.md-ink-ripple.gray-btn").get(1).click(); browser.driver.wait(function() { return fs.existssync(filename); }, 30000); }); });
the error
failures: 1) test cases pull - frontage sanity testing frontage - calendar test cases new app - calendar - print calendar message: error: wait timed out after 30000ms stacktrace: error: wait timed out after 30000ms @ c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1630:20 @ [object object].promise.controlflow.runinframe_ (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) @ [object object].promise.callback_.goog.defineclass.notify (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2464:25) @ [object object].promise.promise.notify_ (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:563:12) @ array.foreach (native) @ object.goog.array.foreach (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\array\array.js:203:43) @ [object object].promise.promise.notifyall_ (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:552:16) @ goog.async.run.processworkqueue (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21) from: task: <anonymous wait> @ [object object].promise.controlflow.wait (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1617:15) @ [object object].webdriver.webdriver.wait (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:714:21) @ [object object].<anonymous> (c:\automation\tests\testcases\newapp\calendartc.js:382:23) @ c:\automation\npm\node_modules\protractor\node_modules\jasminewd\index.js:94:14 @ [object object].promise.controlflow.runinframe_ (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) @ [object object].promise.controlflow.runeventloop_ (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1755:8) @ [object object].<anonymous> (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12) @ goog.async.run.processworkqueue (c:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21) @ runmicrotaskscallback (node.js:337:7) @ process._tickcallback (node.js:355:11) from: task: asynchronous test function: it() @ [object object].<anonymous> (c:\automation\npm\node_modules\protractor\node_modules\jasminewd\index.js:93:33) @ [object object].<anonymous> (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\async-callback.js:45:37) @ [object object].jasmine.block.execute (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1174:17) @ [object object].jasmine.queue.next_ (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31) @ [object object].jasmine.queue.start (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2162:8) @ [object object].jasmine.spec.execute (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2503:14) @ [object object].jasmine.queue.next_ (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31) @ oncomplete (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2205:18) @ [object object].jasmine.spec.finish (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2477:5) @ [object object].oncomplete (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2504:10)==== async task ==== error @ [object object].<anonymous> (c:\automation\tests\testcases\newapp\calendartc.js:380:5) @ [object object].jasmine.env.describe_ (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21) @ [object object].jasmine.env.describe (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15) @ describe (c:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:658:27) @ object.<anonymous> (c:\automation\tests\testcases\newapp\calendartc.js:1:63)
you can use fs.readdir
filenames, , check them regular expression against thing trying match.
it('new app - calendar - print calendar', function(){ $$("button.font-xs.md-button.ng-scope.md-ink-ripple.gray-btn").get(1).click(); 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); });
Comments
Post a Comment