javascript - 如何在 e2e Protractor 中读取 ui 中的动态值

标签 javascript angularjs testing dynamic protractor

我正在 Protractor 中开发端到端测试。我正在运行测试 chrome 浏览器。 在 UI 中有一个动态字段:

<div ng-show="searchResult.count" >
            <h4>Search Results: </h4>
            <p id="font-weight-500">{{searchResult.count}} Items</p>
            <hr>
      </div>

我需要取searchResult.count的值

我试过了

element(by.binding('searchResult.count'));

$('[ng-show="searchResult.count"]')

;

我在 html 中做了一些更改,并在 div 中添加了 ng-model='shearchResult.count'

<div ng-show="searchResult.count"  ng-model="searchResult.count">

然后我打电话

element(by.model("searchResult.count"));

他们的结果都是一样的:

 <h4>Search Results: </h4>
 <p id="font-weight-500" class="ng-binding"> Items</p>
 <hr>

我也尝试过使用 $scope

SearchPage.prototype.getSearchResultNumber=function($scope){
....        
    var value=$scope.searchResult.count;
....

但是我得到了“$scope”是未定义的结果 虽然我可以在网络浏览器中看到数字,但我无法在 Protractor 中阅读或接受 e2e 规范。

我怎样才能得到这个动态生成的数据? 谁能帮我解决这个问题? 谢谢

最佳答案

您可以使用 getAttribute() 解决此问题获取 ng-model 属性的值:

var div = element(by.model("searchResult.count"));
expect(div.getAttribute('ng-model')).toBe('10');  // 10 is an example

关于javascript - 如何在 e2e Protractor 中读取 ui 中的动态值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26286124/

相关文章:

javascript - 将值绑定(bind)到 Angular JS 中的输入

javascript - 如何创建 Angularjs 部分更新(补丁)?

javascript - AngularJS - ng-repeat 出现问题

testing - 如何防止测试在第一个失败的测试用例上停止?

testing - 单击 Watir 中嵌套元素的复选框

javascript - jquery验证模态错误,多次触发模态

javascript - 防止 javascript 自动转义和字符

javascript - 如何在 JavaScript 中为 ENTER 事件充值

c# - 我如何使用 Moq 来模拟一个接口(interface),该接口(interface)具有将具体类作为参数的方法?

javascript 到 zepto - 未捕获的 ReferenceError : setColor is not defined