簡體   English   中英

setTimeout函數未使用JavaScript在量角器中執行

[英]setTimeout function is not getting executed in protractor using javascript

我創建了一個函數,需要在2分鍾的延遲后讀取文件。

function checkInLogs(logFilPath, logMessage){

    setTimeout(() => {

        fs.readFile(logFilPath, 'utf8', function (err,data){
            console.log('I am inside the checkInLogs function')
         })

    }, 120000);

    console.log('outside the function');
}

我用以下代碼調用該函數:

fileUtil.checkInLogs('D:/Installation/V114_new/be/5.6/rms/bin/logs/CCARms25', '[Port:8090] successfully started');

但是問題是setTimeOut內部的代碼永遠不會執行。 在控制台上,我可以看到消息::功能外。 但是里面的代碼沒有被執行。 我什至嘗試功能為:


function checkInLogs(logFilPath, logMessage){

    fs.exists(logFilPath, function(exists) {
        fs.readFile(logFilPath, 'utf8', function (err,data){
            console.log(data.toString());
            console.log(err.toString());
         })

    })



}

並像這樣調用它:

setTimeout(function() {
            fileUtil.checkInLogs('D:/Installation/V114_new/be/5.6/rms/bin/logs/CCARms21', '[Port:8090] successfully started')
        }, 120000);

但是沒有運氣。 setTimeOut內部的代碼未執行。 任何建議/解決方案,請。

通過測試,我認為您需要告訴它首先等待,而不要使用setTimeout。 假裝您的protractor.conf中的超時足夠長,這應該可以工作。

it('can wait two min', async ()=>{
  await browser.sleep(120000);

  fileUtil.checkInLogs('D:/Installation/V114_new/be/5.6/rms/bin/logs/CCARms21', '[Port:8090] successfully started');
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM