• <legend id='pzmUr'><style id='pzmUr'><dir id='pzmUr'><q id='pzmUr'></q></dir></style></legend>

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

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

        <tfoot id='pzmUr'></tfoot>

        来自 Protractor 测试的裸 HTTP 调用

        时间:2023-06-15
          <tbody id='Z46Y1'></tbody>

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

                <legend id='Z46Y1'><style id='Z46Y1'><dir id='Z46Y1'><q id='Z46Y1'></q></dir></style></legend>
                <tfoot id='Z46Y1'></tfoot>

                1. 本文介绍了来自 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 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文章

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

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

                    <legend id='CGnws'><style id='CGnws'><dir id='CGnws'><q id='CGnws'></q></dir></style></legend>