我有一個相當簡單的量角器測試,它應該檢查ng重複行中的文本值。量角器 - getText()返回一個數組而不是一個字符串
這裏是我的HTML:
<div ng-repeat="destination in destinations">
<span>{{destination.city}}, {{destination.country}}</span>
</div>
這是我的JS:
lastDestination = element.all(by.repeater('destination in destinations').row(1));
expect(lastDestination.getText()).toEqual("Madrid, Spain");
的documentation for getText()狀態:
Get the visible (i.e. not hidden by CSS) innerText of this element, including sub-elements, without any leading or trailing whitespace.
所以我期望從該行的跨度標籤的文字被返回,但是當運行量角器測試時,我得到以下錯誤的斷言:
預計['馬德里,西班牙']等於'西班牙馬德里'。
GetText()似乎是返回一個數組而不是一個字符串。
我試圖解決的getText()的承諾,但仍然得到了同樣的錯誤:
lastDestination = element.all(by.repeater('destination in destinations').row(1));
lastDestination.getText().then(function (text) {
expect(text).toEqual("Madrid, Spain");
});
我可以在陣列中針對第一個值獲得解決此問題:
expect(text[0]).toEqual("Madrid, Spain");
但我仍然想知道爲什麼這不起作用。
任何想法?
更新:量角器的Github的頁面上的similar bug has been reported,所以它可能是一個Gettext()函數只是不工作,因爲它應該。
你的代碼的工作,但是,對於gettext的文檔()指出,「獲得可見的(即不是由CSS隱藏)這個元素,包括子元素,沒有任何開頭或結尾空白的innerText」。所以我相信該行上的getText()也應該起作用。我在這裏發現了類似的問題https://github.com/angular/protractor/issues/1794,所以我認爲這可能是一個錯誤。 – Matt
我應該注意到,你在一個承諾上調用getText,而這不是所使用的文檔。 –
有道理,謝謝你鑽研這個和詳細的答案:) – Matt