protractor icon indicating copy to clipboard operation
protractor copied to clipboard

ng-repeat with two columns arrays.

Open mengxiw opened this issue 10 years ago • 3 comments

I am trying to use Protractor test selection part. The html page is looks like:

< md-input-container class="md-block" flex="20" >
     < label>Country< /label >
         < md-select ng-model="main.productCountry1">
                < md-option  ng-value="country" ng-repeat="country in countries">{{country.name}}
                < /md-option >< /md-select>< /md-input-container >
< md-input-container class="md-block" flex="20" style="height: 150px;">
       < label>Sub Contractor< /label>
            < md-select ng-model="main.subContractor">
                   < md-option ng-value="contractor" ng-repeat="contractor in contractors">{{contractor.name}}< /md-option>
          < /md-select>
< /md-input-container>

For test code part:

        var contractor = element.all(by.repeater('contractor in contractors'));
        var subContractor = element(by.model('main.subContractor'));
        subContractor.click();
        contractor.get(3).click();
        browser.sleep(500);

And

        var productCountry = element(by.model('main.productCountry1'));
        productCountry.click();
        var country = element.all(by.repeater('country in countries'));
        country.get(5).click();
        browser.sleep(500);

When I run the code, the first contractor part works, but the select country part got errors. The error is like this:

  Stack:
    ElementNotVisibleError: element not visible
      (Session info: chrome=44.0.2403.81)

I guess it caused by there is one array(contractor.name) in contractor array,but the country array contains two (country.name and country.code). I also try the code following: 1.

var country = element.all(by.repeater('country in countries').column('country.name'));
var country = element.all(by.repeater('country in countries').column('{{country.name}}'));
var country = element.all(by.repeater('country in countries'));
var c1 = country.get(15);
var c2 =c1.element(by.binding('country.name'));
c2.click();
browser.sleep(500);

However, the same error is still happened. Is anyone meet this problem before?

mengxiw avatar Jan 25 '16 17:01 mengxiw

I change the html code and after run the following code in test.js

        var country =element.all(by.repeater('country in countries'));
        var productCountry = element(by.model('main.productCountry1'));
        productCountry.click();
        browser.sleep(500);
        var c1 = country.get(2);      
        names.getAttribute('value').then(function(txt){
             console.log(txt);
         });
        browser.sleep(5000);
        c1.click();
        browser.sleep(500);

        var contractor = element.all(by.repeater('contractor in contractors'));
        contractor.getAttribute('value').then(function(txt){
            console.log(txt);
         });
        var subContractor = element(by.model('main.subContractor'));
        subContractor.click();
        browser.sleep(500);
        var s1 = contractor.get(4);
        browser.sleep(1000);
        s1.click();
        browser.sleep(1000);

The structure of two console results are same, and I also test c1 and s1 respectively, the value of them are correct. But subContractor code can work, the productCountry code is still can't work. The error is the same as before.

   Stacktrace:
     ElementNotVisibleError: element not visible
  (Session info: chrome=44.0.2403.81)

I used $scope.countries twice in html file as following

                    <md-select ng-model="main.productCountry1" required name="prcountry">
                        <md-option ng-value="country.name" ng-repeat="country in countries"><p>{{country.name}}</p></md-option>
                    </md-select>
                    <md-select ng-model="main.managerCountry1" required name="macountry">
                        <md-option ng-value="country.name" ng-repeat="country in countries"><p>{{country.name}}</p></md-option>
                    </md-select>

And does this lead the error happen?

Yes, the error is caused by I have two {{country.name}} in file, I comment one selection, the test code can work. But how to keep these two selection at the same page and run the test ?

mengxiw avatar Jan 26 '16 15:01 mengxiw

I search and study ng-repeat again, it seems I used it in wrong way. Now the html file is looks like:

<md-select ng-model="main.productCountry" required>
     <md-option ng-value="country1.name" ng-repeat="country1 in countries"><p>{{country1.name}}</p></md-option>
 </md-select>
<md-select ng-model="main.managerCountry" required>
     <md-option ng-value="country2.name" ng-repeat="country2 in countries"><p>{{country2.name}}</p></md-option>
</md-select>

The code in test.js is this:

        var productCountry = element(by.model('main.productCountry'));
        var country1 = element.all(by.repeater('country1 in countries'));
        productCountry.click();
        browser.sleep(500);
        country1.get(2).click();

And it works.

mengxiw avatar Feb 02 '16 10:02 mengxiw

Thanks mengxiw. Your fix worked like a charm.

BalachanderJ avatar Feb 22 '16 20:02 BalachanderJ