Skip to content

Commit 838ca67

Browse files
authored
Merge branch 'trunk' into install_drivers
2 parents ba2a008 + d0ebb24 commit 838ca67

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dev.selenium.troubleshooting;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Paths;
6+
import java.util.Arrays;
7+
import java.util.logging.FileHandler;
8+
import java.util.logging.Handler;
9+
import java.util.logging.Level;
10+
import java.util.logging.Logger;
11+
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.Test;
13+
import org.openqa.selenium.manager.SeleniumManager;
14+
import org.openqa.selenium.remote.RemoteWebDriver;
15+
16+
public class LoggingTest {
17+
18+
@Test
19+
public void logging() throws IOException {
20+
Logger logger = Logger.getLogger("");
21+
22+
logger.setLevel(Level.FINE);
23+
Arrays.stream(logger.getHandlers()).forEach(handler -> {
24+
handler.setLevel(Level.FINE);
25+
});
26+
27+
Handler handler = new FileHandler("selenium.xml");
28+
logger.addHandler(handler);
29+
30+
Logger.getLogger(RemoteWebDriver.class.getName()).setLevel(Level.FINEST);
31+
Logger.getLogger(SeleniumManager.class.getName()).setLevel(Level.SEVERE);
32+
33+
Logger localLogger = Logger.getLogger(this.getClass().getName());
34+
localLogger.warning("this is a warning");
35+
localLogger.info("this is useful information");
36+
localLogger.fine("this is detailed debug information");
37+
38+
byte[] bytes = Files.readAllBytes(Paths.get("selenium.xml"));
39+
String fileContent = new String(bytes);
40+
41+
Assertions.assertTrue(fileContent.contains("this is a warning"));
42+
Assertions.assertTrue(fileContent.contains("this is useful information"));
43+
Assertions.assertTrue(fileContent.contains("this is detailed debug information"));
44+
}
45+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import logging
2+
import os
3+
4+
import pytest
5+
6+
7+
def test_logging():
8+
logger = logging.getLogger('selenium')
9+
10+
logger.setLevel(logging.DEBUG)
11+
12+
log_path = "selenium.log"
13+
handler = logging.FileHandler(log_path)
14+
logger.addHandler(handler)
15+
16+
logging.getLogger('selenium.webdriver.remote').setLevel(logging.WARN)
17+
logging.getLogger('selenium.webdriver.common').setLevel(logging.DEBUG)
18+
19+
logger.info("this is useful information")
20+
logger.warning("this is a warning")
21+
logger.debug("this is detailed debug information")
22+
23+
try:
24+
with open(log_path, 'r') as fp:
25+
assert len(fp.readlines()) == 3
26+
finally:
27+
os.remove(log_path)

Diff for: examples/ruby/spec/troubleshooting/logging_spec.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe 'Logging' do
6+
describe 'Options' do
7+
let(:file_name) { File.expand_path('selenium.log') }
8+
after { FileUtils.rm_f(file_name) }
9+
10+
it 'logs things' do
11+
logger = Selenium::WebDriver.logger
12+
13+
logger.level = :debug
14+
15+
logger.output = file_name
16+
17+
logger.ignore(:jwp_caps, :logger_info)
18+
logger.allow(%i[selenium_manager example_id])
19+
20+
logger.warn('this is a warning', id: :example_id)
21+
logger.info('this is useful information', id: :example_id)
22+
logger.debug('this is detailed debug information', id: :example_id)
23+
24+
expect(File.readlines(file_name).grep(/\[:example_id\]/).size).to eq 3
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)