簡體   English   中英

觸發ng-change

[英]Trigger the ng-change

我正在angularjs網站上練習。 在那里,有一個搜索欄,可以對字段中的任何變化進行研究,只要字符串長度超過2個字符即可。

無論如何。 在量角器中,我使用sendKeys輸入名稱,希望搜索開始,但無法獲得任何結果。 而當我手動進行操作時,它可以正常工作。 這或多或少是我用來輸入研究的代碼片段:

describe('Search Field', function(){

  browser.get('https://docs.angularjs.org/api');
  it('displays a frame with the results of the search', function(){
     var searchField = element(by.css('.search-query'));
     var searchResult= element(by.css('.search-results-container'));
     searchField.click();
     searchField.sendKeys('angular');

     //I use a wait function here to wait for the results
     browser.wait(function () {
             return searchResult.isDisplayed();
         },10000);         
     //Before doing anything else, I expect to see the results
     expect(searchResult.isPresent()).toBe(true);
     expect(searchResult.isDisplayed()).toBe(true);
  });
});

搜索字段代碼為:

<input type="text" name="as_q" class="search-query ng-valid ng-touched ng-dirty ng-valid-parse" placeholder="Click or press / to search" ng-focus="focus=true" ng-blur="focus=false" ng-change="search(q)" ng-model="q" docs-search-input="" autocomplete="off" style="">

似乎seach(q)函數永遠不會與量角器一起執行。

您是否知道導致此問題的原因?

編輯

我設法通過使用validate()出現了搜索結果框架。 代碼變為:

describe('Search Field', function(){

  browser.get('https://docs.angularjs.org/api');
  it('displays a frame with the results of the search', function(){
     var searchField = element(by.css('.search-query'));
     var searchResult= element(by.css('.search-results-container'));
     searchField.click();
     topBanner.searchField.evaluate('search("angular")');

     //I use a wait function here to wait for the results
     browser.wait(function () {
             return searchResult.isDisplayed();
         },10000);         
     //Before doing anything else, I expect to see the results
     expect(searchResult.isPresent()).toBe(true);
     expect(searchResult.isDisplayed()).toBe(true);
  });
});

但是很奇怪的是,如果我在評估前留下sendkeys()命令,那么搜索結果將不會出現。

因此,我認為這是一種解決方法,它使我能夠處理想要達到的實際框架。 但是我想知道如何在沒有這個技巧的情況下達到目標。

searchField.value('angular');
searchField.trigger('input');

之后,您需要

$scope.$apply();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM