无法在量角器中访问自定义定位器。得到错误"失败:by.shadowRoot不是一个函数"

时间:2018-03-26 05:58:50

标签: javascript protractor

我正在尝试在我的量角器套装中访问自定义定位器作为函数。定位器详细信息

"use strict";
  module.exports = function() {

By.addLocator('shadowRoot',function(selector, using) {
  var selectors = cssSelector.split('::sr');
   if (selectors.length === 0) {
    return [];
 }

 var shadowDomInUse = (document.head.createShadowRoot || 
 document.head.attachShadow);
  var getShadowRoot  = function (el) {
  return ((el && shadowDomInUse) ? el.shadowRoot : el);
 };
  var findAllMatches = function (selector /*string*/, targets /*array*/, 
   firstTry /*boolean*/) {
   var scope, i, matches = [];
    for (i = 0; i < targets.length; ++i) {
       scope = (firstTry) ? targets[i] : getShadowRoot(targets[i]);
       if (scope) {
          if (selector === '') {
              matches.push(scope);
          } else {
              Array.prototype.push.apply(matches, 
              scope.querySelectorAll(selector));
           }
       }
   }
  return matches;
 };   

  var matches = findAllMatches(selectors.shift().trim(), [using || 
   document], true);
   while (selectors.length > 0 && matches.length > 0) {
     matches = findAllMatches(selectors.shift().trim(), matches, false);
   }
   return matches;
  });
  };

当我尝试访问定位器时

  element(by.shadowRoot('apps::sr nd-icon#icon')).click().then(function(){
   browser.sleep(10000);

    });    

获得以下错误

失败:by.shadowRoot不是函数

使用版本为0.4.2的gulp-angular-protractor

1 个答案:

答案 0 :(得分:0)

使用 bool binaryPredicate(const Node& a, const Node& b);

在conf文件中加载定位器功能 module.exports = (function() {...})