AngularJS e2e测试:如何获得repeater().count()的值?
发布时间:2020-12-17 10:17:27 所属栏目:安全 来源:网络整理
导读:问题 调用转发器(‘#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
问题
调用转发器(‘#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)
深入研究Angularjs的e2e支持的源代码表明,您必须在Future上调用execute()以使其填充其值.此外,当你调用execute时,你必须为execute()提供一个“done”函数,否则Testacular会(奇怪的是!)跳过你的测试.
码 var rowCountFuture = repeater('#memberTable tr','Member Rows').count(); rowCountFuture.execute(function(){ }); var memberCount = rowCountFuture.value; 虽然我很高兴看到这个有用,但我担心可能会出现一些异步错误,而且,我觉得这是一个黑客而不是正确的方法.有任何想法吗? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |