Path: blob/trunk/javascript/selenium-webdriver/example/logging.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* @fileoverview Demonstrates how to use WebDriver's logging system.19*/2021'use strict'2223const chrome = require('../chrome')24const firefox = require('../firefox')25const edge = require('../edge')26const { Builder, By, Key, logging, until } = require('..')2728logging.installConsoleHandler()29logging.getLogger(`${logging.Type.DRIVER}.http`).setLevel(logging.Level.ALL)30;(async function () {31let driver32try {33driver = await new Builder()34// Default to using Firefox. This can be overridden at runtime by35// setting the SELENIUM_BROWSER environment variable:36//37// SELENIUM_BROWSER=chrome node selenium-webdriver/example/logging.js38.forBrowser('firefox')39// Configure the service for each browser to enable verbose logging and40// to inherit the stdio settings from the current process. The builder41// will only start the service if needed for the selected browser.42.setChromeService(new chrome.ServiceBuilder().enableVerboseLogging().setStdio('inherit'))43.setEdgeService(44process.platform === 'win32' ? new edge.ServiceBuilder().enableVerboseLogging().setStdio('inherit') : null,45)46.setFirefoxService(new firefox.ServiceBuilder().enableVerboseLogging().setStdio('inherit'))47.build()4849await driver.get('http://www.google.com/ncr')50await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN)51await driver.wait(until.titleIs('webdriver - Google Search'), 1000)52} finally {53if (driver) {54await driver.quit()55}56}57})()585960