AngularJS & Protractor - getLocationAbsUrl() 不是 return url(字符串)而是 object

AngularJS & Protractor - getLocationAbsUrl() doesn't return the url (string) but an object

标题说明了一切。 我想将 url 记录到控制台,但它给了我一些 object

spec.js

describe('Protractor Demo App', function() {

  it('should add 1 and 2', function() {

    browser.get('http://juliemr.github.io/protractor-demo/#/');
    element(by.model('first')).sendKeys(1);
    element(by.model('second')).sendKeys(2);

    element(by.id('gobutton')).click();

    console.log(browser.getLocationAbsUrl()); // logs some object

    expect(browser.getLocationAbsUrl())
        .toEqual('/'); 
    });

});

这是我在控制台中看到的

Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
Started
{ closure_uid_727700741: 274,
  flow_:
   { events_: {},
     closure_uid_727700741: 1,
     activeFrame_:
      { events_: {},
        closure_uid_727700741: 75,
        flow_: [Circular],
        parent_: [Object],
        children_: [Object],
        lastInsertedChild_: [Object],
        pendingTask_: null,
        isLocked_: false,
        isBlocked_: false,
        pendingCallback: false,
        pendingRejection: false,
        cancellationError_: null },
     schedulingFrame_:
      { events_: {},
        closure_uid_727700741: 75,
        flow_: [Circular],
        parent_: [Object],
        children_: [Object],
        lastInsertedChild_: [Object],
        pendingTask_: null,
        isLocked_: false,
        isBlocked_: false,
        pendingCallback: false,
        pendingRejection: false,
        cancellationError_: null },
     shutdownTask_: null,
     eventLoopTask_: null,
     hold_:
      { _idleTimeout: 2147483647,
        _idlePrev: [Object],
        _idleNext: [Object],
        _idleStart: 95289669,
        _onTimeout: [Function: wrapper],
        _repeat: true },
     yieldCount_: 10 },
  stack_: null,
  parent_:
   { closure_uid_727700741: 272,
     flow_:
      { events_: {},
        closure_uid_727700741: 1,
        activeFrame_: [Object],
        schedulingFrame_: [Object],
        shutdownTask_: null,
        eventLoopTask_: null,
        hold_: [Object],
        yieldCount_: 10 },
     stack_: { [Task: Protractor.getLocationAbsUrl()] name: 'Task' },
     parent_: null,
     callbacks_: [ [Object] ],
     state_: 'pending',
     handled_: true,
     pendingNotifications_: false,
     value_: undefined },
  callbacks_: null,
  state_: 'pending',
  handled_: false,
  pendingNotifications_: false,
  value_: undefined }
.


1 spec, 0 failures
Finished in 3.251 seconds
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed

那是什么object? 如何将当前 url 打印到控制台?

据我所知 browser.getLocationAbsUrl() return 承诺,当承诺得到解决时,它会给你当前的 url。 因此,当您使用

打印它时
console.log(browser.getLocationAbsUrl());

打印完整的promise对象。

试试下面的代码可能对你有帮助:-

 browser.getCurrentUrl().then(function(actualUrl) {
      console.log(actualUrl);
    });

你可以在这里找到语法 link

希望对您有所帮助:)