Search code examples
javascriptangularjstestingprotractorangular-ui-select

Testing with protractor using ui-select


I am trying to test an ui-select with protractor. In this ui-select I have a list of countries. My html looks like:

<ui-select ng-model="datiAnagrafici.countryOfBirth" name="countryOfBirth" theme="bootstrap" reset-search-input="true" append-to-body="true" required blur>
                <ui-select-match placeholder="paese di nascita">{{$select.selected.name}}</ui-select-match>
                <ui-select-choices repeat="country.code as country in countries | filter: {name:$select.search}">
                    <span ng-bind-html="country.name"></span>
                </ui-select-choices>
</ui-select>

My page object looks like:

this.country = element(by.model('datiAnagrafici.countryOfBirth'));
this.fillForm = function(){
   this.country.sendKeys('IT');
}

In my spec file I have:

it('should fill the form', function() {
  form.fillForm();
})

But when i run my test the ng-model is not filled with the sent data. Do you have any tips? Thanks


Solution

  • I have found the solution here

    this.country = element(by.model('datiAnagrafici.countryOfBirth'));
    this.selectCountry = this.country.element(by.css('.ui-select-search'));
    

    then in the fill form method is almost as alecxe said:

    this.country.click();
    this.selectCountry.sendKeys('Italy');