【问题标题】:How to make typescript not crying about compile error when adding custom locator添加自定义定位器时如何使打字稿不因编译错误而哭泣
【发布时间】:2016-08-12 17:02:55
【问题描述】:

我写了一个自定义定位器:

onPrepare: function() {
  browser.ignoreSynchronization = true;
  by.addLocator('automationId', function(value, parentElement) {
    parentElement = parentElement || document;
     var nodes = parentElement.querySelectorAll('[automationId]');
     return Array.prototype.filter.call(nodes, function(node) {
       return (node.getAttribute('automationId') === value);
     });
  });
},

但是当我尝试使用它并运行时:

element(by.automationId('auto-id'));

错误是:

Property automationId does not exist on type IProtractorLocationStrategy

如何解决这个问题?

【问题讨论】:

    标签: javascript testing angular typescript protractor


    【解决方案1】:

    使用自定义匹配器遇到同样的问题。没有尝试过扩展命名空间(但你肯定应该)所以我没有干净的解决方案。

    但是作为修补程序(真的很脏),您可以尝试通过 [''] 访问您的自定义定位器:

    element(by['automationId']('auto-id'));
    

    请注意,打字稿会将其视为类型“任何”,因此您将失去类型化对象的好处。

    【讨论】:

      猜你喜欢
      • 2020-09-18
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 2016-05-28
      • 2018-06-05
      • 2020-03-18
      • 2016-08-21
      相关资源
      最近更新 更多