Debian Codegraph @

test/selenium/webdriver/chrome/chrome_service_tests.py

raw symbols SCIP
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 import os
18 import subprocess
19 import time
20
21 import pytest
22
23 from selenium.common.exceptions import WebDriverException
24 from selenium.webdriver.chrome.service import Service
25
26
27 @pytest.mark.xfail_chrome(raises=WebDriverException)
28 @pytest.mark.no_driver_after_test
29 def test_uses_chromedriver_logging(clean_driver, driver_executable) -> None:
30 log_file = "chromedriver.log"
31 service_args = ["--append-log"]
32
33 service = Service(
34 log_output=log_file,
35 service_args=service_args,
36 executable_path=driver_executable,
37 )
38 driver2 = None
39 try:
40 driver1 = clean_driver(service=service)
41 with open(log_file) as fp:
42 lines = len(fp.readlines())
43 driver2 = clean_driver(service=service)
44 with open(log_file) as fp:
45 assert len(fp.readlines()) >= 2 * lines
46 finally:
47 driver1.quit()
48 if driver2:
49 driver2.quit()
50 os.remove(log_file)
51
52
53 @pytest.mark.no_driver_after_test
54 def test_log_output_as_filename(clean_driver, driver_executable) -> None:
55 log_file = "chromedriver.log"
56 service = Service(log_output=log_file, executable_path=driver_executable)
57 try:
58 assert "--log-path=chromedriver.log" in service.service_args
59 driver = clean_driver(service=service)
60 with open(log_file) as fp:
61 assert "Starting ChromeDriver" in fp.readline()
62 finally:
63 driver.quit()
64 os.remove(log_file)
65
66
67 @pytest.mark.no_driver_after_test
68 def test_log_output_as_file(clean_driver, driver_executable) -> None:
69 log_name = "chromedriver.log"
70 log_file = open(log_name, "w", encoding="utf-8")
71 service = Service(log_output=log_file, executable_path=driver_executable)
72 try:
73 driver = clean_driver(service=service)
74 time.sleep(1)
75 with open(log_name) as fp:
76 assert "Starting ChromeDriver" in fp.readline()
77 finally:
78 driver.quit()
79 log_file.close()
80 os.remove(log_name)
81
82
83 @pytest.mark.no_driver_after_test
84 def test_log_output_as_stdout(clean_driver, capfd, driver_executable) -> None:
85 service = Service(log_output=subprocess.STDOUT, executable_path=driver_executable)
86 driver = clean_driver(service=service)
87
88 out, err = capfd.readouterr()
89 assert "Starting ChromeDriver" in out
90 driver.quit()
91
92
93 @pytest.mark.no_driver_after_test
94 def test_log_output_null_default(driver, capfd) -> None:
95 out, err = capfd.readouterr()
96 assert "Starting ChromeDriver" not in out
97 driver.quit()