angularjs – 如何等待Protractor端的http请求响应
发布时间:2020-12-17 10:20:29 所属栏目:安全 来源:网络整理
导读:我使用了答案 https://stackoverflow.com/a/25149395/3330910中的代码. 我做下一个: it('HTTP request',function () { var BackRequest = require('../helper/backRequest'); var request = new BackRequest(); page.visitPage(); request.setBaseUrl('http
我使用了答案
https://stackoverflow.com/a/25149395/3330910中的代码.
我做下一个: it('HTTP request',function () { var BackRequest = require('../helper/backRequest'); var request = new BackRequest(); page.visitPage(); request.setBaseUrl('http://localhost:8081'); // Step #1 request.get('/api/v1/one') .then(function(result){ expect(result.statusCode).toBe(100); // An error #1 expect(result.bodyString).toContain('Some text'); }); // Step #2 expect(1).toBe(2); // an error #2 }); 我按顺序得到错误: >错误#2 如何强制量角器等待步骤#1然后执行步骤#2. 现在我只能做链接then()函数: request.get('/api/v1/one') .then(function(result){ expect(result.statusCode).toBe(100); // An error #1 expect(result.bodyString).toContain('Some text') .then(function(result){ expect(1).toBe(2); }); 更新 因此,它最终采用下一种方法: describe('Scenarios',function () { beforeEach(function () { page.visitPage(); }); var chain = function () { var defer = protractor.promise.defer(); defer.fulfill(true); return defer.promise; }; it('HTTP request',function () { var BackRequest = require('../helper/backRequest'); var request = new BackRequest(); request.setBaseUrl('http://localhost:8081'); chain() .then(function () { // Save data }) .then(function () { request.get('/api/v1/one') .then(function (result) { expect(result.statusCode).toBe(200); expect(result.bodyString).toContain('text'); }); }) .then(function () { // Change and Save again }) .then(function () { request.get('/api/v1/one') .then(function (result) { expect(result.statusCode).toBe(200); expect(result.bodyString).toContain('new text'); expect(result.bodyString).not.toContain('text'); }); }); }); }); 谢谢Leo Gallucci的帮助.
步骤#2立即得到解决,因为没有什么可以等待的,没有webdriver承诺,你只是将绝对数字与expect(1).toBe(2)进行比较;
您可以坚持使用chaining then(),或者我喜欢的方式是单独的it()块: it('HTTP request',function () { // Step #1 code ... }); it('keeps testing other things in this step #2',function () { expect(1).toBe(2); }); 顺便说一句,我很高兴你发现我的其他answer很有用! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- shell脚本编写一些基础但容易忘记的小技巧(持续更新)
- Scala中的方法与函数和含义
- angularjs – 如何在Angular 2中观看复杂对象,就像我们在An
- twitter-bootstrap – Bootstrap页脚,页面全宽
- shell 生成随机数的实现方法总结
- .NET WebService的创建、部署、运用
- angularjs – $rootScope:过滤器引起的infdig错误?
- angularjs – SystemJS插件可以修改已经转换的文件吗?
- ionic 2错误’ReferenceError:未定义sqlitePlugin’
- Axis2 webservice 各种jar包使用(缺包的异常)