Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/common/devtools_tests.py
1865 views
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 pytest
18
19
from selenium.webdriver.support.ui import WebDriverWait
20
21
22
@pytest.mark.xfail_safari
23
@pytest.mark.xfail_firefox
24
@pytest.mark.xfail_remote
25
def test_check_console_messages(driver, pages, recwarn):
26
devtools, connection = driver.start_devtools()
27
console_api_calls = []
28
29
assert len(recwarn) == 0
30
31
connection.execute(devtools.runtime.enable())
32
connection.on(devtools.runtime.ConsoleAPICalled, console_api_calls.append)
33
driver.execute_script("console.log('I love cheese')")
34
driver.execute_script("console.error('I love bread')")
35
WebDriverWait(driver, 10).until(lambda _: len(console_api_calls) == 2)
36
37
assert console_api_calls[0].type_ == "log"
38
assert console_api_calls[0].args[0].value == "I love cheese"
39
assert console_api_calls[1].type_ == "error"
40
assert console_api_calls[1].args[0].value == "I love bread"
41
42
43
@pytest.mark.xfail_safari
44
@pytest.mark.xfail_firefox
45
@pytest.mark.xfail_remote
46
def test_check_start_twice(clean_driver, clean_options):
47
driver1 = clean_driver(options=clean_options)
48
devtools1, connection1 = driver1.start_devtools()
49
driver1.quit()
50
51
driver2 = clean_driver(options=clean_options)
52
devtools2, connection2 = driver2.start_devtools()
53
driver2.quit()
54
55