Skip to content

Commit d987aed

Browse files
committed
js: Expose Closure's logging system through the webdriver.logging module.
This creates a disconnect between local and remote logging (e.g. driver.manage().logs().get('browser')), but that same disconnect exists in the other language bindings too. I'm punting on defining a consistent API until the W3C spec defines logging behavior.
1 parent 22be876 commit d987aed

File tree

6 files changed

+273
-37
lines changed

6 files changed

+273
-37
lines changed

Diff for: javascript/node/selenium-webdriver/CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## v2.46.0-dev
22

3+
* Exposed a new logging API via the `webdriver.logging` module. For usage, see
4+
`example/logging.js`.
35
* Added support for using a proxy server for WebDriver commands.
46
See `Builder#usingWebDriverProxy()` for more info.
57
* Removed deprecated functions:
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
/**
19+
* @fileoverview Demonstrates how to use WebDriver's logging sysem.
20+
*/
21+
22+
'use strict';
23+
24+
var webdriver = require('..'),
25+
By = webdriver.By,
26+
until = webdriver.until;
27+
28+
webdriver.logging.installConsoleHandler();
29+
webdriver.logging.getLogger().setLevel(webdriver.logging.Level.ALL);
30+
31+
var driver = new webdriver.Builder()
32+
.forBrowser('firefox')
33+
.build();
34+
35+
driver.get('http://www.google.com/ncr');
36+
driver.findElement(By.name('q')).sendKeys('webdriver');
37+
driver.findElement(By.name('btnG')).click();
38+
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
39+
driver.quit();

Diff for: javascript/node/selenium-webdriver/test/_base_test.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ function runClosureTest(file) {
6161
describe(name, function() {
6262
var context = new base.Context(true);
6363
context.closure.document.title = name;
64-
if (process.env.VERBOSE != '1') {
64+
if (process.env.VERBOSE == '1') {
65+
context.closure.goog.require('webdriver.logging');
66+
context.closure.goog.module.get('webdriver.logging')
67+
.installConsoleHandler();
68+
} else {
6569
// Null out console so everything loads silently.
6670
context.closure.console = null;
6771
}
@@ -89,7 +93,8 @@ function runClosureTest(file) {
8993
}
9094
var results = tc.getTestResults();
9195
done(Error('\n' + Object.keys(results).map(function(name) {
92-
var msg = [name + ': ' + (results[name].length ? 'FAILED' : 'PASSED')];
96+
var msg =
97+
[name + ': ' + (results[name].length ? 'FAILED' : 'PASSED')];
9398
if (results[name].length) {
9499
msg = msg.concat(results[name]);
95100
}

Diff for: javascript/webdriver/http/http.js

+15
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ goog.require('goog.array');
3030
goog.require('goog.json');
3131
goog.require('webdriver.CommandExecutor');
3232
goog.require('webdriver.CommandName');
33+
goog.require('webdriver.logging');
3334
goog.require('webdriver.promise');
3435

3536

@@ -78,6 +79,11 @@ webdriver.http.Executor = function(client) {
7879
* @private {!Object<{method:string, path:string}>}
7980
*/
8081
this.customCommands_ = {};
82+
83+
/**
84+
* @private {!webdriver.logging.Logger}
85+
*/
86+
this.log_ = webdriver.logging.getLogger('webdriver.http.Executor');
8187
};
8288

8389

@@ -113,13 +119,22 @@ webdriver.http.Executor.prototype.execute = function(command, callback) {
113119
var path = webdriver.http.Executor.buildPath_(resource.path, parameters);
114120
var request = new webdriver.http.Request(resource.method, path, parameters);
115121

122+
var log = this.log_;
123+
log.finer(function() {
124+
return '>>>\n' + request;
125+
});
126+
116127
this.client_.send(request, function(e, response) {
117128
var responseObj;
118129
if (!e) {
130+
log.finer(function() {
131+
return '<<<\n' + response;
132+
});
119133
try {
120134
responseObj = webdriver.http.Executor.parseHttpResponse_(
121135
/** @type {!webdriver.http.Response} */ (response));
122136
} catch (ex) {
137+
log.warning('Error parsing response', ex);
123138
e = ex;
124139
}
125140
}

0 commit comments

Comments
 (0)