标题就是这么说。 我想将网址记录到控制台,但它给了我一些对象
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
那个对象是什么? 如何将当前网址打印到控制台?
答案 0 :(得分:2)
据我所知browser.getLocationAbsUrl()
返回承诺,当承诺解决时,它会给你当前的网址。
因此,当您使用
console.log(browser.getLocationAbsUrl());
它打印完整的承诺对象。
尝试下面的代码可能会对您有所帮助: -
browser.getCurrentUrl().then(function(actualUrl) {
console.log(actualUrl);
});
您可以在link
找到语法希望有所帮助:)