1

考虑以下代码片段

var allRows = element.all(by.repeater('row in items'))

这将返回一个array转发器项目。那么,如何在控制台中调试此变量。当我这样做时console.log(allRows),我在控制台而不是数组中得到以下内容html

{ ptor_: { controlFlow: [Function],
 schedule: [Function],
 setFileDetector: [Function],
 getSession: [Function],
 getCapabilities: [Function],
 quit: [Function],
 actions: [Function],
 touchActions: [Function],
 executeScript: [Function],
 executeAsyncScript: [Function],
 call: [Function],
 wait: [Function],
 sleep: [Function],
 getWindowHandle: [Function],
 getAllWindowHandles: [Function],
 getPageSource: [Function],
 close: [Function],
 getCurrentUrl: [Function],
 getTitle: [Function],
 findElementInternal_: [Function],
 findElementsInternal_: [Function],
 takeScreenshot: [Function],
 manage: [Function],
 switchTo: [Function],
 driver: 
  WebDriver {
    session_: [Object],
    executor_: [Object],
    flow_: [Object],
    fileDetector_: null },
 element: { [Function] all: [Function] },
 '$': [Function],
 '$$': [Function],
 baseUrl: '',
 rootEl: 'html',
 ignoreSynchronization: false,
 getPageTimeout: 100000,
 params: {},
 ready: 
  Promise {
    flow_: [Object],
    stack_: null,
    parent_: null,
    callbacks_: null,
    state_: 'fulfilled',
    handled_: true,
    value_: null,
    queue_: null },
 plugins_: 
  { pluginConfs: [],
    pluginObjs: [],
    assertions: {},
    resultsReported: false },
 resetUrl: 'data:text/html,<html></html>',
 trackOutstandingTimeouts_: true,
 mockModules_: [ [Object] ],
 allScriptsTimeout: 100000,
 getProcessedConfig: [Function],
 forkNewDriverInstance: [Function],
 restart: [Function] },

那么如何调试应该包含所有 html 行的实际变量。我在调试文档中找不到它的选项。

任何帮助是极大的赞赏。

谢谢。

更新

allRows有以下标记。

<li>AA</li><li>BB</li><li>CC</li>

我需要在控制台中查看整个内容

4

2 回答 2

2

我认为您正在寻找getOuterHtml()- 它将打印出指定元素的整个元素标记(包括 html 属性)。例如,

it('prints element', function () {
    var el = element(by.model('username'));
    el.getOuterHtml().then(function (val) {
        console.log(val);
    });
});

这会产生:

这个控制台输出

来源:https ://angular.github.io/protractor/#/api?view=webdriver.WebElement.prototype.getOuterHtml

于 2016-04-21T20:55:01.867 回答
2

请记住,几乎每个量角器函数都返回一个必须在继续之前解决的承诺。如果您想查看变量的内容allRows

allRows.each(function(row)getInnerHtml().then(function(html) {
     console.log(html);
});

Promise 可以在 expect 方法中解决,因此假设变量引用了预期结果,myHtmlString您可以将上述内容缩短为:

expect(allRows.getInnerHtml()).toBe(myHtmlString);

对更新的回应:

你想要的是父元素的 innerHtml 。您可以使用 xpath 函数获得它,但它们是最慢的选择方法,因此只能作为最后的手段使用。如果您可以直接获取 /,那么我提供的代码将起作用。如果由于某种原因无法直接获取列表元素,则

var firstItem = allRows.first();
var parent = firstItem.element(by.xpath('..'));
parent.getInnerHtml().then(function(html) {
    console.log(html);
});

应该在控制台中打印所需的结果。

于 2016-04-21T18:26:12.360 回答