gpt4 book ai didi

angular - 在运行 Protractor 测试时进行 API 调用

转载 作者:搜寻专家 更新时间:2023-10-30 21:17:40 25 4
gpt4 key购买 nike

我已经使用 angular2.0typescript 构建了一个网络应用程序。现在我正在使用 protractor 为我的站点编写 E2E

现在,在我的一个测试中,我需要进行 API 调用(HTTP GET 请求)并将响应值用作我的测试用例中的输入。

所以基本上我想知道如何在 Protractor-Jasmine 中发出 GET 请求 并使用结果/响应。

最佳答案

Protractor 在 nodejs 之上运行,并在底层调用 Selenium API。您可以使用所有节点库,包括 request

在导入/要求之间选择:

import * as request from 'request'; 
var request = require('request');

并执行您的GET 请求:

it('Should reach google.com', done => {
request('http://www.google.com', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
done(); //informs runner that the asynchronous code has finished
});
});

查看此链接:

关于angular - 在运行 Protractor 测试时进行 API 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45182309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com