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

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

      <small id='1jJHv'></small><noframes id='1jJHv'>

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

      时间:2023-06-15

            <tbody id='1GGkR'></tbody>

            • <small id='1GGkR'></small><noframes id='1GGkR'>

              <tfoot id='1GGkR'></tfoot>
                <bdo id='1GGkR'></bdo><ul id='1GGkR'></ul>
                <legend id='1GGkR'><style id='1GGkR'><dir id='1GGkR'><q id='1GGkR'></q></dir></style></legend>

                <i id='1GGkR'><tr id='1GGkR'><dt id='1GGkR'><q id='1GGkR'><span id='1GGkR'><b id='1GGkR'><form id='1GGkR'><ins id='1GGkR'></ins><ul id='1GGkR'></ul><sub id='1GGkR'></sub></form><legend id='1GGkR'></legend><bdo id='1GGkR'><pre id='1GGkR'><center id='1GGkR'></center></pre></bdo></b><th id='1GGkR'></th></span></q></dt></tr></i><div id='1GGkR'><tfoot id='1GGkR'></tfoot><dl id='1GGkR'><fieldset id='1GGkR'></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 测试中预期元素的动态计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文章

                <legend id='yVr0J'><style id='yVr0J'><dir id='yVr0J'><q id='yVr0J'></q></dir></style></legend>
              • <tfoot id='yVr0J'></tfoot>

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

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