【问题标题】:How do we do e2e testing with polymer and selenium?我们如何使用聚合物和硒进行 e2e 测试?
【发布时间】:2014-08-13 11:34:01
【问题描述】:

Angular 有量角器来监听 Angular 中的生命周期事件。

例如:ptor.waitForAngular();

他们是一种让硒测试等待聚合物中各种生命周期事件的方法吗?

目前我们可以运行 mocha 进行简单的 e2e 测试,要做到这一点,只需将测试直接嵌入到 html 中,就像它们在源代码中的做法一样。

您可以像 here 那样运行您的测试。

 <script>
      document.addEventListener('polymer-ready', function() {
        mocha.run();
      });
    </script>

例如,要检查更改观察器中的正确更新,您可以这样做:

Polymer('x-test', {
            bar: '',
            ready: function() {
              this.bar = 'bar';
              setTimeout(function() {
                this.zonk = 'zonk';
              }.bind(this));
            },
            barChanged: function() {
              chai.assert.equal(this.bar, 'bar', 'change in ready calls *Changed');
              checkDone();
            },
            zonkChanged: function() {
              chai.assert.equal(this.zonk, 'zonk', 'change calls *Changed without prototype value')
              checkDone();
            }
          });

例如,如果您想在 ready 事件之后检查计算机属性是否正确,您可以这样做:

<x-foo foo="mee" bar="too" count=3></x-foo>

    <polymer-element name="x-foo" attributes="foo bar count">
      <template>{{ fooBar }}:{{ fooBarCounted }}</template>
      <script>
        Polymer('x-foo', {
          computed: {
            fooBarCounted: 'repeat(fooBar, count)',
            fooBar: "foo + '-' + bar"
          },
          repeat: function(str, count) {
            var retval = '';
            for (var i = 0; i < count; i++) {
              retval += (i ? ' ' : '') + str + '(' + i + ')';
            }
            return retval;
          },
          ready: function() {
            chai.assert.equal(this.shadowRoot.innerHTML, 'mee-too:mee-too(0) mee-too(1) mee-too(2)');
            done();
          }
        })
      </script>
    </polymer-element>

【问题讨论】:

    标签: testing polymer


    【解决方案1】:

    实际上 selenium(以及其他基于它的库)可以等待元素出现在页面上。

    例如browser.waitForExist('#selector')

    在此处查看 API 文档http://webdriver.io/api/utility/waitForExist.html

    希望对你有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 2016-11-07
      • 2010-10-19
      • 2016-09-27
      • 1970-01-01
      • 2016-05-19
      • 2022-12-16
      相关资源
      最近更新 更多