<small id='NDvBV'></small><noframes id='NDvBV'>

<tfoot id='NDvBV'></tfoot>

    <bdo id='NDvBV'></bdo><ul id='NDvBV'></ul>
  1. <legend id='NDvBV'><style id='NDvBV'><dir id='NDvBV'><q id='NDvBV'></q></dir></style></legend>

      <i id='NDvBV'><tr id='NDvBV'><dt id='NDvBV'><q id='NDvBV'><span id='NDvBV'><b id='NDvBV'><form id='NDvBV'><ins id='NDvBV'></ins><ul id='NDvBV'></ul><sub id='NDvBV'></sub></form><legend id='NDvBV'></legend><bdo id='NDvBV'><pre id='NDvBV'><center id='NDvBV'></center></pre></bdo></b><th id='NDvBV'></th></span></q></dt></tr></i><div id='NDvBV'><tfoot id='NDvBV'></tfoot><dl id='NDvBV'><fieldset id='NDvBV'></fieldset></dl></div>

      来自 Protractor 测试的裸 HTTP 调用

      时间:2023-10-12

      <i id='qo4X0'><tr id='qo4X0'><dt id='qo4X0'><q id='qo4X0'><span id='qo4X0'><b id='qo4X0'><form id='qo4X0'><ins id='qo4X0'></ins><ul id='qo4X0'></ul><sub id='qo4X0'></sub></form><legend id='qo4X0'></legend><bdo id='qo4X0'><pre id='qo4X0'><center id='qo4X0'></center></pre></bdo></b><th id='qo4X0'></th></span></q></dt></tr></i><div id='qo4X0'><tfoot id='qo4X0'></tfoot><dl id='qo4X0'><fieldset id='qo4X0'></fieldset></dl></div>
    1. <tfoot id='qo4X0'></tfoot>
        <tbody id='qo4X0'></tbody>
      <legend id='qo4X0'><style id='qo4X0'><dir id='qo4X0'><q id='qo4X0'></q></dir></style></legend>
        1. <small id='qo4X0'></small><noframes id='qo4X0'>

                <bdo id='qo4X0'></bdo><ul id='qo4X0'></ul>
              • 本文介绍了来自 Protractor 测试的裸 HTTP 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我的量角器测试需要一些数据设置,我想通过对正在运行的服务器进行一系列 POST 和 PUT 来实现这些设置.

                My Protractor tests need some data setup which I would like to implement by making a series of POSTs and PUTs to the running server.

                所以,问题是:如何从 Protractor 测试中执行裸"HTTP 调用?

                So, the question is: How do you execute "bare" HTTP calls from Protractor tests?

                我发现的一种方法是使用 Node Http 模块,但它有点笨拙.我想知道这些问题通常是如何解决的——量角器会暴露什么吗?使用 Http(和其他需要时的 Node 模块)是可行的方法吗?还有其他方法吗?

                One way that I found is using Node Http module, but it's a bit unwieldy. I wonder how such problems are typically solved - does Protractor expose anything? Is using Http (and other Node modules when you need them) the way to go? Is there some other way?

                推荐答案

                另一种不依赖 Angular 的方法是在 browser.executeAsyncScriptXMLHttpRequest>.如果您需要在 Angular 加载或导航到页面之前作为测试设置的一部分进行调用,这将特别有用.

                An alternate way that doesn't depend on Angular is manually creating an XMLHttpRequest inside of browser.executeAsyncScript. This is especially helpful if you need to make a call as part of the test setup, prior to Angular loading or prior to navigating to a page at all.

                查看 Protractor 文档中的这个示例:

                示例 #3:注入 XMLHttpRequest 并等待结果.在此示例中,注入脚本是使用函数文字指定的.使用这种格式时,函数被转换为字符串进行注入,所以它不应该引用任何未定义在被测页面范围内的符号.

                Example #3: Injecting a XMLHttpRequest and waiting for the result. In this example, the inject script is specified with a function literal. When using this format, the function is converted to a string for injection, so it should not reference any symbols not defined in the scope of the page under test.

                driver.executeAsyncScript(function() {
                  var callback = arguments[arguments.length - 1];
                  var xhr = new XMLHttpRequest();
                  xhr.open("GET", "/resource/data.json", true);
                  xhr.onreadystatechange = function() {
                    if (xhr.readyState == 4) {
                      callback(xhr.responseText);
                    }
                  }
                  xhr.send('');
                }).then(function(str) {
                  console.log(JSON.parse(str)['food']);
                });
                

                这篇关于来自 Protractor 测试的裸 HTTP 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用预期条件时未定义的属性“绑定" 下一篇:使用 Protractor 设置 Angular 模型

                相关文章

                最新文章

                  • <bdo id='7SEvY'></bdo><ul id='7SEvY'></ul>

                  1. <i id='7SEvY'><tr id='7SEvY'><dt id='7SEvY'><q id='7SEvY'><span id='7SEvY'><b id='7SEvY'><form id='7SEvY'><ins id='7SEvY'></ins><ul id='7SEvY'></ul><sub id='7SEvY'></sub></form><legend id='7SEvY'></legend><bdo id='7SEvY'><pre id='7SEvY'><center id='7SEvY'></center></pre></bdo></b><th id='7SEvY'></th></span></q></dt></tr></i><div id='7SEvY'><tfoot id='7SEvY'></tfoot><dl id='7SEvY'><fieldset id='7SEvY'></fieldset></dl></div>

                    <small id='7SEvY'></small><noframes id='7SEvY'>

                    <tfoot id='7SEvY'></tfoot>
                    <legend id='7SEvY'><style id='7SEvY'><dir id='7SEvY'><q id='7SEvY'></q></dir></style></legend>