通过在Angular材料中发送密钥到md-auto-complete来量角器测试用例

时间:2015-12-01 00:30:07

标签: javascript angularjs testing protractor angular-material

我想将密钥发送到md-autocomplete,但我无法将密钥发送到文本字段,查找下面的代码

HTML:

 <md-autocomplete md-selected-item="selectedItem" md-search-text="searchText" md-items="item in getMatches(searchText)" md-item-text="item.display">
      <span id="xyz" md-highlight-text="searchText">{{item.display}}</span>
    </md-autocomplete>

量角器代码:

  it('checking my test case', function() {
    browser.get('http://localhost:8080/#/home');

    var inputSearchTextBox = element(by.id("xyz"));
    inputSearchTextBox.sendKeys('Boston , us , 02120');
  });

我收到以下错误:

Test checking my test case
   Message:
     NoSuchElementError: No element found using locator: By.id("xyz")
   Stacktrace:
     NoSuchElementError: No element found using locator: By.id("xyz")

Angular Material Link:

ms-AutoComplete Link

我有什么方法可以将密钥发送到md-autocomplete标记文本字段

1 个答案:

答案 0 :(得分:4)

您可以在html中使用 md-input-id 属性向md-input-container添加ID。 例如:

 <md-autocomplete md-input-id="xyz" md-selected-item="selectedItem" md-search-text="searchText" md-items="item in getMatches(searchText)" md-item-text="item.display">
      <span md-highlight-text="searchText">{{item.display}}</span>
 </md-autocomplete>

之后,您可以访问并使用它:

var myElt = element(by.css("md-autocomplete input#xyz"));
myElt.clear();
myElt.sendKeys("blabla");