Does the conveyor find the element in the repeater by binding?

I am trying to write a simple test that matches the binding in the repeater.

It works for me when I look at the CSS class, but I am "forbidden" to do this in our code. I cannot use HTML tags as a locator. I can only find attributes or direct binding.

I tried many different ways, including (but getting errors or no result):

var productPageUrl = element.all(by.repeater('product in products').row(0).column('{{product.productPageUrl}}'));

Not sure if this matters, but in the application the HTML template is included in ng-repeat.

This works (but cannot be used):

products.then(function(prods) {
    prods[0].findElement(by.className('homepage-panel-link')).getAttribute('href').then(function(href){
        expect(href).toMatch('/products/1');
    });
});

HTML template repeated:

<div data-ng-repeat="product in products">
    <div data-property-name="productItem-{{$index}}">
        <a href="{{product.productPageUrl}}" class="homepage-panel-link" data-property-name="productPageUrl"></a>
    </div>
</div>

In any case, just check the binding file. productPageUrl ??? From the above code, there seems to be a very long way to get this value.

+4
2

, by.binding? http://angular.imtqy.com/protractor/#/api?view=ProtractorBy.prototype.binding

.

var productPageUrl = element(by.binding('product.productPageUrl'));
expect(productPageUrl.getAttribute('href')).toMatch('/products/1');

:

var productPageUrls = element.all(by.binding('product.productPageUrl'));
expect(productPageUrls.getAttribute('href').get(0)).toMatch('/products/1');
or
expect(productPageUrls.getAttribute('href')).toMatch(['/products/1', '/products/2', ...]);
+1

, - , .:) , ng-bind value . ( , getText() : D)

element(by.binding('mainImageUrl')).getAttribute('value')
   .then(function(text){
      expect(text.toMatch(/img\/phones\/nexus-s.0.jpg/));
   });

..
  <a href="{{product.productPageUrl}}" 
   class="homepage-panel-link" data-property-name="productPageUrl"></a>
  <input type="hidden" ng-bind="product.productPageUrl"
   value= "{{product.productPageUrl}}" >
..

javascript:

    element.all(by.repeater('product in products').row(0)
    .column('{{product.productPageUrl}}'))
    .getAttribute('value').then(function(value){
           //matching value
         });
0

Source: https://habr.com/ru/post/1542930/


All Articles