对通过Protractors元素函数选择的元素使用then()后,黄瓜Protractor超时 [英] Cucumber Protractor times out after using then() on elements selected using Protractors element function
问题描述
我遇到一个问题,该描述与我无法在角度2应用程序中使用量角器来识别元素,但对我来说,通过在ID值之前添加#并不能解决问题
I have an issue which description matches perfectly with I am not able to identify elements using protractor in angular 2 application but for me the problem is not fixed by adding # before the id value
这是下面的代码:
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();
});
});
控制台日志:
- inputBox承诺集
- info脚本是:return document.getElementById('roomWidthInput');
然后抛出错误:函数在5000毫秒后超时。
and then it throws Error: function timed out after 5000 milliseconds.
我也尝试使用 by.id
定位器具有完全相同的结果。
I have also tried using by.id
locator with exactly the same results.
任何帮助将不胜感激,谢谢。
Any help would be much appreciated, thanks.
推荐答案
您的问题与量角器找不到元素
无关,这是由于您的步骤定义函数执行时间超过了默认超时:5秒。
Your issue has no matter with protractor can't find element
, It's due to your step definition function execution time duration exceeded the default timeout: 5 secs.
您应按以下方式更改默认超时:
You should change the default timeout as below:
黄瓜3及以上
// supports/timeout.js
var { setDefaultTimeout } = require("cucumber");
setDefaultTimeout(60 * 1000);
黄瓜2以上,但低于黄瓜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:
In protractor conf.js
, add the timeout.js into 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;
}
这篇关于对通过Protractors元素函数选择的元素使用then()后,黄瓜Protractor超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!