我使用Protractor来运行e2e测试,但无法使用getText()验证元素的文本。量角器返回:
Expected '' to equal 'Joe Smith'.
以下是代码:
<span class="input-group" style="padding: 40px;">
<input tabindex="0" class="form-control ng-valid ng-dirty ng-
valid-parse ng-touched" id="requesterSearchInput" aria-expanded="false"
aria-invalid="false" aria-owns="typeahead-6604-1028" aria-
autocomplete="list" type="text" placeholder="Enter a Requester name" ng-
model="searchText" typeahead-loading="loadingLocations" typeahead-wait-
ms="500" typeahead-min-length="1" typeahead-on-
select="OnRequesterSelect($item)" typeahead-template-
url="requesterTypeAheadTemplate.html" typeahead="rdata for rdatas in
GetRequesters($viewValue)"></input>
在我的测试脚本中,我有:
element(by.id('requesterSearchInput')).click();
browser.actions().sendKeys('Joe Smith').perform();
expect(element(by.id('requesterSearchInput')).getText()).toEqual('Joe Smith');
然而,最后一行失败了:
Expected '' to equal 'Joe Smith'.
我已经多次尝试解决这个问题但没有一个有效。以下是我的尝试:
尝试1:
expect(element(by.id('requesterSearchInput')).getText()).toEqual('Joe Smith');
尝试2:
expect(element(by.id('requesterSearchInput')).getAttribute("aria-hidden")).toEqual('Joe Smith');
尝试3:
expect(element(by.id('requesterSearchInput')).getAttribute("innerText")).
toEqual('Joe Smith');
尝试4:
var previousEntry = element(by.xpath("//div[@ng-hide='searchText']"))
.getAttribute("aria-hidden");
expect(previousEntry).toEqual('Masterson');
非常感谢您的帮助。
答案 0 :(得分:2)
根据我的理解,您需要检查value
属性:
expect(element(by.id('requesterSearchInput')).getAttribute('value')).toEqual('Joe Smith');