gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:55:12 24 4
gpt4 key购买 nike

我正在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com