2017-09-23 36 views
0

我試圖通過鏈接列表循環,並對每個鏈接執行一些操作。 WebdriverIO對於所有API的測試代碼(如mocha)是同步的。但是如何將現有的node.js代碼集成到同步流程中。對於下面的代碼WebdriverIO中的循環列表

const assert = require('assert'); 

常量webdriverio =需要( 'webdriverio')

描述( 'webdriver.io頁',函數(){

it('should be a pending test'); 

    before(() => { 

     var options = { 
      desiredCapabilities: { 
       browserName: 'chrome' 
      } 
     }; 

     client = webdriverio.remote(options) 
     return client.init(); 

    }) 
    after(function() { 
     browser.end(); 
    }); 

    it('should have the right title - the fancy generator way', function() { 
     var list = ["https://www.google.com", "https://www.yahoo.com", "https://www.github.com"] 

     for(var i = 0 ; i < list.length;i++){ 
      browser.url(list.length); 
      var title = browser.getTitle(); 
      browser.saveScreenshot('./snapshot' + i + '.png').call(function(){ 
       fs.exists(screenshotPath, function(fileExists) { 
        fileExists.should.be.true; 
        done(); 
       }) 
      }); 
     } 
    }); 

}); 
+0

問題不明確。請提供一些更多信息 –

+0

我想知道如何從不太瞭解Promise的新手按特定順序控制Webdriver.io。雖然上面正在測試跑步者像wdio testrunner,但我還沒有嘗試過。其他選項將是異步/等待或套接字承諾電話 – Effectura

+0

根據此鏈接:https://github.com/webdriverio/webdriverio/issues/2312 – Effectura

回答

0

我有2點對你其他的選擇對於同步環

https://www.npmjs.com/package/serial-loop 

,或者你可以創建自己的循環這樣

function testonly() { 
//.. do some stuff 
// when done make again 
testonly() 

// when you finish with your stuff you can start a new function as example after() 
if(test == 'test') { 
after() 
} 

} 

function after() { 
//..  
} 

或者您可以使用回調方法。希望這是你正在尋找的。當然,你可以在這個循環中使用webdriver.io的東西!