在使用量角器元素函数选择的元素上使用 then() 后,黄瓜量角器超时

Cucumber Protractor times out after using then() on elements selected using Protractors element function

我有一个问题,描述与 I am not able to identify elements using protractor in angular 2 application 完全匹配,但对我来说,通过在 id 值前添加 # 无法解决问题

下面是代码:

When('I select my input box', (callback) => {

  let inputbox = element(by.css('#roomWidthInput'));
  console.log('inputBox promise set');

  var scrpt = "return document.getElementById('roomWidthInput');";
  browser.executeScript(scrpt).then(function (text) {
    console.log('info', 'Script is: ' + scrpt);
  });

  inputbox.isPresent().then(function(isElementVisible) {
    console.log('hello!');
    expect(isElementVisible).to.be.true;
    callback();
  });
});

控制台记录:

然后它抛出错误:函数在 5000 毫秒后超时。

我也尝试过使用 by.id 定位器得到完全相同的结果。

非常感谢任何帮助,谢谢。

您的问题与protractor can't find element无关,这是由于您的步骤定义函数执行持续时间超过了默认超时:5秒。

您应该如下更改默认超时:

黄瓜3及以上

// supports/timeout.js
var { setDefaultTimeout } = require("cucumber");
setDefaultTimeout(60 * 1000);

Cucumber 2 以上,但低于 Cucumber 3

// supports/timeout.js
var {defineSupportCode} = require('cucumber');

defineSupportCode(function({setDefaultTimeout}) {
  setDefaultTimeout(60 * 1000);
});

黄瓜 1 号及以下

// supports/timeout.js
module.exports = function() {
    this.setDefaultTimeout(60 * 1000);
};

在量角器 conf.js 中,将 timeout.js 添加到 cucumberOpts.require:

// set allScriptsTimeout to fix asynchronous Angular tasks to finish after 11 seconds
allScriptsTimeout: 600 * 1000, 

cucumberOpts: {     
   require: [
      "supports/timeout.js",
   ]
},

onPrepare: function() {
   // add this when page opened by browser.get() is not angular page
   browser.ignoreSynchronization = true;
}