调用repeater('#myTable tr','Rows').count();
会返回Future
,而不是整数。我需要获取整数值,以便我可以确认在表中添加了一行。
it('should add a new user when save button is clicked',function()
{
showModal();
//here I'm trynig to store the row count of my table into a local variable.
//a future is returned who's 'value' field is undefined.
var memberCount = repeater('#memberTable tr','Member Rows').count();
//this outputs 'undefined'
console.log(memberCount.value);
input('editedMember.name').enter('John');
input('editedMember.grade').enter(5);
input('editedMember.ladderPosition').enter(3);
element('#saveMemberButton').click();
sleep(1);
expect(element(modalId).css('display')).toBe('none');
//here is where I want to do the comparison against the above stored memberCount
expect(repeater('#memberTable tr', 'Member Rows').count()).toBe(memberCount.value + 1);
});
Chrome 25.0 e2e should add a new user when save button is clicked FAILED
expect repeater 'Member Rows ( #memberTable tr )' count toBe null
/Users/jgordon/learning/chessClub/web-app/test/e2e/scenarios.js:45:3: expected null but was 6
Chrome 25.0: Executed 2 of 2 (1 FAILED) (1 min 4.117 secs / 1 min 3.773 secs)
答案 0 :(得分:4)
深入研究Angularjs的e2e支持的源代码,您必须在execute()
上调用Future
来填充其值。另外,当你致电execute
时,你必须向execute()
提供一个“完成”功能,否则测试会(奇怪的是!)跳过你的测试。
var rowCountFuture = repeater('#memberTable tr','Member Rows').count();
rowCountFuture.execute(function(){
});
var memberCount = rowCountFuture.value;
虽然我很高兴看到它有效,但我担心可能会出现一些异步错误,而且,我觉得这是一个黑客而不是正确的方法。有什么想法吗?
答案 1 :(得分:2)
基于最新的Protractor版本:
it('should add a new user when save button is clicked', function() {
var memberCount;
element.all(by.repeater('#memberTable tr','Member Rows')).count().then(function(value) {
memberCount = value;
});
...
// then do all your entering user info, saving etc.
...
browser.refresh(); // or however you want to load new data
expect(element.all(by.repeater('#memberTable tr','Member Rows')).count()).toEqual(memberCount + 1);
});
答案 2 :(得分:1)
我遇到了同样的问题,并且在调用value
之后测试execute()
返回时看到了令人困惑的结果。我发现这种方法更可靠:
var getCount = repeater('ul li').count();
getCount.execute(function(value) {
expect(value).toEqual(3);
});
答案 3 :(得分:1)
您可以在定位器返回的异步保证中轻松完成此操作
element.all(By.repeater 'thing in things').then(function(elements){
count = elements.length;
expect(count).toEqual(3);
});