# Copyright (c) Microsoft Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from playwright.async_api import Page, Selectors
from tests.server import Server
from .utils import Utils
async def test_should_dispatch_click_event(page: Page, server: Server) -> None:
await page.goto(server.PREFIX + "/input/button.html")
await page.dispatch_event("button", "click")
assert await page.evaluate("() => result") == "Clicked"
async def test_should_dispatch_click_event_properties(
page: Page, server: Server
) -> None:
await page.goto(server.PREFIX + "/input/button.html")
await page.dispatch_event("button", "click")
assert await page.evaluate("() => bubbles")
assert await page.evaluate("() => cancelable")
assert await page.evaluate("() => composed")
async def test_should_dispatch_click_svg(page: Page) -> None:
await page.set_content(
"""
"""
)
await page.dispatch_event("circle", "click")
assert await page.evaluate("() => window.__CLICKED") == 42
async def test_should_dispatch_click_on_a_span_with_an_inline_element_inside(
page: Page,
) -> None:
await page.set_content(
"""
"""
)
await page.dispatch_event("span", "click")
assert await page.evaluate("() => window.CLICKED") == 42
async def test_should_dispatch_click_after_navigation(
page: Page, server: Server
) -> None:
await page.goto(server.PREFIX + "/input/button.html")
await page.dispatch_event("button", "click")
await page.goto(server.PREFIX + "/input/button.html")
await page.dispatch_event("button", "click")
assert await page.evaluate("() => result") == "Clicked"
async def test_should_dispatch_click_after_a_cross_origin_navigation(
page: Page, server: Server
) -> None:
await page.goto(server.PREFIX + "/input/button.html")
await page.dispatch_event("button", "click")
await page.goto(server.CROSS_PROCESS_PREFIX + "/input/button.html")
await page.dispatch_event("button", "click")
assert await page.evaluate("() => result") == "Clicked"
async def test_should_not_fail_when_element_is_blocked_on_hover(page: Page) -> None:
await page.set_content(
"""