In code below, when debugger is hit, the value of thing/item shows nothing (See image)..
在下面的代码中,当调试器被命中时,thing / item的值不显示任何内容(参见图片)..
it('CheckAllLinks:', function () {
browser.ignoreSynchronization = true;
browser
.findElements(by.tagName('a'))
.then(function (items) {
items.forEach(function (item) {
var thing = item;
debugger;
});
});
});
For example any call to these methods only returns three dots using the immediate window in Visual Studio. (...);
例如,对这些方法的任何调用仅使用Visual Studio中的立即窗口返回三个点。 (...);
I realize this is a promise, but don't understand how to use any of the methods to validate content and click the link as well...
我意识到这是一个承诺,但不明白如何使用任何方法来验证内容并点击链接...
1 个解决方案
#1
Found the answer to be related to the fact that these calls themseleves are promises. Promises are fulfilled when the .then statement is hit. In example below there are two things being promised, the text and the href of each link.
找到答案与这些称为单位的承诺相关的事实有关。当.then语句被命中时,将实现Promise。在下面的示例中,承诺了两件事,即每个链接的文本和href。
it('CheckAllLinks:', function () {
browser.ignoreSynchronization = true;
browser
.findElements(by.tagName('a'))
.then(function (items) {
items.forEach(function (item, i) {
var test = item.getText().then(function (text) {
item.getAttribute('href').then(function (href) {
debugger;
});
});
});
});
});
#1
Found the answer to be related to the fact that these calls themseleves are promises. Promises are fulfilled when the .then statement is hit. In example below there are two things being promised, the text and the href of each link.
找到答案与这些称为单位的承诺相关的事实有关。当.then语句被命中时,将实现Promise。在下面的示例中,承诺了两件事,即每个链接的文本和href。
it('CheckAllLinks:', function () {
browser.ignoreSynchronization = true;
browser
.findElements(by.tagName('a'))
.then(function (items) {
items.forEach(function (item, i) {
var test = item.getText().then(function (text) {
item.getAttribute('href').then(function (href) {
debugger;
});
});
});
});
});