2017-05-04 64 views
1

因爲我有一個加載視圖(黑盒測試&我不是Android應用程序開發人員),所以我在使用appium + nodejs(wd)+ mocha時遇到問題並且我想等待它的失敗。所以,我想是這樣的:如果找不到元素,appium nodejs(wd)會掛起

wd.addPromiseChainMethod('waitForElementByIdDisappears', function (id, retries) { 
    var self = this; 
    return new Promise(function (resolve, reject) { 
     (function waitForElementDisappears(retry, context){ 
      if(retry < 0) { 
       return reject(); 
      } 
      else { 
       try { 
       context.elementByIdIfExists(id, function(err, element) { 
        console.log('Element found: ' + element + ' retry: ' + retry); 
        if(typeof element === 'undefined') { 
        return resolve(); 
        } 
        else { 
        setTimeout(() => waitForElementDisappears(retry-1, context), 1000); 
        }     
       }); 
       } 
       catch (error) { 
       console.log(error); 
       return reject(); 
       } 
      } 
     })(retries, self); 
    }); 
}); 

一切工作正常,直到加載視圖在前看不見,因爲那時的NodeJS開始與appium獨立控制檯輸出掛起:

信息:[調試] [引導] [ debug]使用:UiSelector [RESOURCE_ID = de.myapp.foo:id/loadingView] info:[debug] [BOOTSTRAP] [debug] getElements selector:UiSelector [RESOURCE_ID = de.myapp.foo:id/[調試] [BOOTSTRAP] [調試]元素[]爲空:(0)

一遍又一遍地重複,直到它超時運行。

我也試過:

hasElementById(value, cb) -> cb(err, boolean)

elementByIdOrNull(value, cb) -> cb(err, element)

elementsById(value, cb) -> cb(err, element) (和檢查元素列表爲空)

等語法方面,如:

context.elementByIdIfExists(id).then(element => { ... })

但每次我的輸出是這樣的:

Element found: 15 retry: 30 
Element found: 15 retry: 29 
Element found: 15 retry: 28 
Element found: 15 retry: 27 

# hangs because the loading view was disappeared and appium standalone starts to repeat the [debug][info] section above ... 

感謝您閱讀&幫助!

回答

0

我以前用過appium standalone,現在改成了最新的npm appium版本1.6.x.但是最後在我的方法之前設置了.setImplicitWaitTimeout(250),並在該方法完成之後重置了它。