我有这个:
<span>{{ $ctrl.title }}</span>
我用这个测试它:
element(by.binding('$ctrl.title'))
它正在发挥作用。
在那之后,我需要标题不是纯文本,而是html,因为我想在文本中添加一些h1、h2标签,所以我更新了我的html,如下所示:
<span ng-bind-html="$ctrl.buildHtmlContent()"></span>
buildHtmlContent() {
return this.$sce.trustAsHtml(this.title);
}
但是测试失败了,我需要更换元素定位器,但我不知道用什么。知道吗?
您可以使用css选择器:
by.css('div[ng-bind-html="$ctrl.buildHtmlContent()"]')
或者您可以添加额外的属性,这样测试就不那么依赖于实现:
<span ng-bind-html="$ctrl.buildHtmlContent()" e2e-title></span>
by.css('div[e2e-title]')
虽然它比我简单,但我只需要替换它:
element(by.binding('$ctrl.title'))
这个:
element(by.binding('$ctrl.buildHtmlContent()'))