0
我正在爲我的web應用程序編寫測試,selenium
webdriver
對於javascript
。我面臨的問題是,由於許多操作是異步的,縮進變得瘋狂。例如,用於讀取元素的值,我使用的是結構Javascript + selenium,編寫可讀的測試
driver.findElement(By.id('my-element')).then(function(elem) {
elem.getAttribute('innerHTML').then(function(text) {
// Some operation
// Read next element with same structure
});
});
正如你可以看到,如果我需要讀取多個元素的值,壓痕很快變得非常深。是否有某種避免這類問題的最佳做法?是否使用「然後」從元素中讀取值的唯一方法?
這個問題更適合[code review](http://codereview.stackexchange.com/) – Guy