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

        <tfoot id='cRQTm'></tfoot>

      1. <small id='cRQTm'></small><noframes id='cRQTm'>

      2. 如何使用量角器在 e2e 测试中预期元素的动态计数

        时间:2023-10-12

          <bdo id='ZyF8Z'></bdo><ul id='ZyF8Z'></ul>

              <tfoot id='ZyF8Z'></tfoot>
            1. <small id='ZyF8Z'></small><noframes id='ZyF8Z'>

            2. <legend id='ZyF8Z'><style id='ZyF8Z'><dir id='ZyF8Z'><q id='ZyF8Z'></q></dir></style></legend>
                  <tbody id='ZyF8Z'></tbody>

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

                  本文介绍了如何使用量角器在 e2e 测试中预期元素的动态计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我目前正在使用 Protractor 为我不起眼的 Angular 应用程序编写一些 e2e 测试.

                  I'm currently writing some e2e tests for my humble Angular app with Protractor.

                  我的应用程序运行良好,单元测试通过了所有测试,也使用了 e2e...直到这个:

                  My app works fine, unit tests passes all, e2e used too... until this one:

                  appE2ESpec.js

                  describe('adding an item', function() {
                    var items,
                        addItemButton,
                        startCount;
                  
                    beforeEach(function() {
                      items = element.all(by.css('li.item'));
                      addItemButton = element(by.id('addItemButton'));
                      startCount = items.count();
                    });
                  
                    it('should display a new item in list', function() {
                      addItemButton.click();
                  
                      expect(items.count()).toEqual(startCount+1);
                    });
                  });
                  

                  这就是我编写测试的方式,但是,

                  This is how I would have written my test but,

                  问题是: items.count() 返回一个承诺,我知道,但我无法强制 Protractor 解决它.所以我明白了:

                  The problem is: that items.count() returns a promise, I know that, but I can't manage to force Protractor to resolve it. So I get this:

                  Failures:
                  
                  1) myApp adding an item should display a new item in list
                    Message:
                      Expected 6 to equal '[object Object]1'.
                  

                  我的尝试:

                  items.count().then(function(count) {
                    startCount = count;
                    //console.log(startCount) --> "6" Perfect!
                  });
                  

                  但是最后得到了同样的结果……我不能把expect放到then里面,我也想过.

                  But got the same result at the end... I can't put the expect into the then, I thought about that too.

                  • 我搜索了 Protractor GitHub 存储库问题、StackOverflow 和 Google AngularJs 组.

                  附录:

                  console.log(startCount) 输出:

                  { then: [Function: then],
                    cancel: [Function: cancel],
                    isPending: [Function: isPending] }
                  

                  我本可以编写 .toEqual(6),但我不想在每次需要更改应用启动状态时都重写测试.

                  I could have written .toEqual(6) but I don't want to rewrite my test each time I need to change my app startup state.

                  有什么想法吗?提前致谢!!

                  Any idea? Thanks in advance!!

                  推荐答案

                  你需要先解析promise,然后进行断言.

                  You need to resolve the promise and then do the assertion.

                  Protractor 将解析你传递给 expect() 的 Promise,但它不能在 Promise 中添加数字.你需要先解决promise的值:

                  Protractor will resolve the promise that you pass to expect(), but it cannot add a number to a promise. You need to resolve the value of the promise first:

                  beforeEach(function() {
                    ...
                    items.count().then(function(originalCount) {
                      startCount = originalCount;
                    });
                  });
                  
                  it('should display a new item in list', function() {
                    ...
                    expect(items.count()).toEqual(startCount+1);
                  });
                  

                  这篇关于如何使用量角器在 e2e 测试中预期元素的动态计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何处理量角器中未找到元素的异常 下一篇:什么是与量角器一起运行的好的无头浏览器?

                  相关文章

                  最新文章

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

                  • <bdo id='svXjp'></bdo><ul id='svXjp'></ul>

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

                      <tfoot id='svXjp'></tfoot>
                    1. <legend id='svXjp'><style id='svXjp'><dir id='svXjp'><q id='svXjp'></q></dir></style></legend>