我使用了答案
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
如何强制量角器等待步骤#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很有用!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。