我正在尝试编写一个与转发器中的绑定匹配的简单测试.
当我通过CSS类搜索时,我有它工作,但是我“不允许”在我们的代码中执行此操作.我也不能使用HTML标签作为定位器.我只能通过属性或直接绑定找到.
var productPageUrl = element.all(by.repeater('product in products').row(0).column('{{product.productPageUrl}}'));
不确定它是否有所作为,但在应用程序中,ng-repeat包含HTML模板.
这有效(但不能使用):
products.then(function(prods) { prods[0].findElement(by.className('homepage-panel-link')).getAttribute('href').then(function(href){ expect(href).toMatch('/products/1'); }); });
重复的HTML模板:
<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>
无论如何只是测试绑定product.productPageUrl ???从上面的代码开始,为了获得这个价值,似乎还有很长的路要走.
解决方法
看起来你只是在寻找定位器by.binding?
http://angular.github.io/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',...]);