我的站点中有一个页面向服务器发出请求,然后使用结果来填充表。
我该如何为此编写 e2e 测试?我在计算如何等待服务器响应以及如何从响应中获取数据时遇到了麻烦,因此我可以根据表内容对其进行检查。
这是我的 Angular Controller 的一个简化示例:
angular.module("myApp").controller("myCtrl", function(MyService) {
MyService.getData()
.then(function (response) {
$scope.data = response;
});
});
然后 html 页面循环遍历 $scope.data 中的项目以填充表格。
谢谢你的帮助!
最佳答案
通常,您不必担心这个,因为 protractor
知道 angular 何时准备就绪并加载页面。换句话说,it syncs with Angular itself :
You no longer need to add waits and sleeps to your test. Protractor can automatically execute the next step in your test the moment the webpage finishes pending tasks, so you don’t have to worry about waiting for your test and webpage to sync.
但在某些情况下,您需要通过
browser.wait()
明确等待某些预期条件得到满足。 .例如,您可以等到特定元素出现:var EC = protractor.ExpectedConditions;
var elm = element(by.css("#myid"));
browser.wait(EC.presenceOf(elm), 10000);
有一大套built-in Expected Conditions , 一探究竟。
在您的情况下究竟要等待什么取决于浏览器收到该服务器响应时浏览器中发生的事情 - 可能有一些表格出现,或者有额外的表格行添加到现有表格等。
关于angularjs - 在 Protractor 测试中等待服务器响应(和检查值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32773234/