Path: blob/trunk/py/test/selenium/webdriver/common/bidi_tests.py
1865 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.161718from selenium.webdriver.common.bidi.log import LogLevel19from selenium.webdriver.common.by import By20from selenium.webdriver.support.ui import WebDriverWait212223async def test_check_console_messages(driver, pages):24pages.load("javascriptPage.html")2526log_entries = []27driver.script.add_console_message_handler(log_entries.append)2829driver.execute_script("console.log('I love cheese')")30WebDriverWait(driver, 5).until(lambda _: log_entries)3132log_entry = log_entries[0]33assert log_entry.level == LogLevel.INFO34assert log_entry.method == "log"35assert log_entry.text == "I love cheese"36assert log_entry.type_ == "console"373839async def test_check_error_console_messages(driver, pages):40pages.load("javascriptPage.html")4142log_entries = []4344def log_error(entry):45if entry.level == "error":46log_entries.append(entry)4748driver.script.add_console_message_handler(log_error)4950driver.execute_script('console.error("I don\'t cheese")')51WebDriverWait(driver, 5).until(lambda _: log_entries)5253log_entry = log_entries[0]54assert log_entry.level == LogLevel.ERROR55assert log_entry.method == "error"56assert log_entry.text == "I don't cheese"57assert log_entry.type_ == "console"585960async def test_collect_js_exceptions(driver, pages):61pages.load("javascriptPage.html")6263log_entries = []64driver.script.add_javascript_error_handler(log_entries.append)6566driver.find_element(By.ID, "throwing-mouseover").click()67WebDriverWait(driver, 5).until(lambda _: log_entries)6869log_entry = log_entries[0]70assert log_entry.text == "Error: I like cheese"71assert log_entry.level == LogLevel.ERROR72assert log_entry.type_ == "javascript"73assert log_entry.stacktrace["callFrames"][0]["functionName"] == "onmouseover"747576# Test is now failing since Chrome 137, this is using BiDi.77# @pytest.mark.xfail_firefox78# @pytest.mark.xfail_remote79# async def test_collect_log_mutations(driver, pages):80# async with driver.bidi_connection() as session:81# log = Log(driver, session)82# async with log.mutation_events() as event:83# pages.load("dynamic.html")84# driver.find_element(By.ID, "reveal").click()85# WebDriverWait(driver, 10).until(86# lambda d: d.find_element(By.ID, "revealed").value_of_css_property("display") != "none"87# )88# assert event["attribute_name"] == "style"89# assert event["current_value"] == ""90# assert event["old_value"] == "display:none;"919293